#333158 - hotfix packingType customerTicketList #1770

Merged
jsegarra merged 2 commits from hotfix_packingType_customerTicketList into master 2025-05-02 09:29:17 +00:00
3 changed files with 48 additions and 18 deletions

View File

@ -15,7 +15,7 @@ import InvoiceOutDescriptorProxy from 'pages/InvoiceOut/Card/InvoiceOutDescripto
import RouteDescriptorProxy from 'src/pages/Route/Card/RouteDescriptorProxy.vue';
import VnTable from 'src/components/VnTable/VnTable.vue';
import CustomerDescriptorProxy from '../Card/CustomerDescriptorProxy.vue';
import { getItemPackagingType } from '../composables/getItemPackagingType.js';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
@ -161,23 +161,6 @@ const setShippedColor = (date) => {
};
const rowClick = ({ id }) =>
window.open(router.resolve({ params: { id }, name: 'TicketSummary' }).href, '_blank');
const getItemPackagingType = (ticketSales) => {
if (!ticketSales?.length) return '-';
const packagingTypes = ticketSales.reduce((types, sale) => {
const { itemPackingTypeFk } = sale.item;
if (
!types.includes(itemPackingTypeFk) &&
(itemPackingTypeFk === 'H' || itemPackingTypeFk === 'V')
) {
types.push(itemPackingTypeFk);
}
return types;
}, []);
return dashIfEmpty(packagingTypes.join(', ') || '-');
};
</script>
<template>

View File

@ -0,0 +1,36 @@
import { describe, it, expect } from 'vitest';
import { getItemPackagingType } from '../getItemPackagingType';
describe('getItemPackagingType', () => {
it('should return "-" if ticketSales is null or undefined', () => {
expect(getItemPackagingType(null)).toBe('-');
expect(getItemPackagingType(undefined)).toBe('-');
});
it('should return "-" if ticketSales does not have a length property', () => {
const ticketSales = { someKey: 'someValue' }; // No tiene propiedad length
expect(getItemPackagingType(ticketSales)).toBe('-');
});
it('should return unique packaging types as a comma-separated string', () => {
const ticketSales = [
{ item: { itemPackingTypeFk: 'H' } },
{ item: { itemPackingTypeFk: 'V' } },
{ item: { itemPackingTypeFk: 'H' } },
];
expect(getItemPackagingType(ticketSales)).toBe('H, V');
});
it('should return unique packaging types as a comma-separated string', () => {
const ticketSales = [
{ item: { itemPackingTypeFk: 'H' } },
{ item: { itemPackingTypeFk: 'V' } },
{ item: { itemPackingTypeFk: 'H' } },
{ item: { itemPackingTypeFk: 'A' } },
];
expect(getItemPackagingType(ticketSales)).toBe('H, V, A');
Review

@jgallego Esto es correcto que debe mostrarse así?

@jgallego Esto es correcto que debe mostrarse así?
Review

si el ticket contiene al menos un articulo de cada uno de esos tipos, sí.

si el ticket contiene al menos un articulo de cada uno de esos tipos, sí.
});
it('should return "-" if ticketSales is an empty array', () => {
expect(getItemPackagingType([])).toBe('-');
});
});

View File

@ -0,0 +1,11 @@
import { dashIfEmpty } from 'src/filters';
export function getItemPackagingType(ticketSales) {
if (!ticketSales?.length) return '-';
const packagingTypes = Array.from(
new Set(ticketSales.map(({ item: { itemPackingTypeFk } }) => itemPackingTypeFk)),
);
return dashIfEmpty(packagingTypes.join(', '));
}