mirror of
https://github.com/frappe/books.git
synced 2025-01-04 23:55:24 +00:00
fix: update and fix failing tests
This commit is contained in:
parent
77f2dfb754
commit
116633ddbd
@ -3,7 +3,6 @@ import { getDefaultMetaFieldValueMap } from 'backend/helpers';
|
|||||||
import { closeTestFyo, getTestFyo, setupTestFyo } from 'tests/helpers';
|
import { closeTestFyo, getTestFyo, setupTestFyo } from 'tests/helpers';
|
||||||
import { ModelNameEnum } from 'models/types';
|
import { ModelNameEnum } from 'models/types';
|
||||||
import { getItem } from 'models/inventory/tests/helpers';
|
import { getItem } from 'models/inventory/tests/helpers';
|
||||||
import { getItemPrice } from 'models/helpers';
|
|
||||||
import { SalesInvoiceItem } from '../SalesInvoiceItem/SalesInvoiceItem';
|
import { SalesInvoiceItem } from '../SalesInvoiceItem/SalesInvoiceItem';
|
||||||
import { SalesInvoice } from '../SalesInvoice/SalesInvoice';
|
import { SalesInvoice } from '../SalesInvoice/SalesInvoice';
|
||||||
import { PurchaseInvoiceItem } from '../PurchaseInvoiceItem/PurchaseInvoiceItem';
|
import { PurchaseInvoiceItem } from '../PurchaseInvoiceItem/PurchaseInvoiceItem';
|
||||||
@ -15,11 +14,7 @@ const itemMap = {
|
|||||||
Pen: {
|
Pen: {
|
||||||
name: 'Pen',
|
name: 'Pen',
|
||||||
rate: 100,
|
rate: 100,
|
||||||
hasBatch: true,
|
unit: 'Unit',
|
||||||
},
|
|
||||||
Ink: {
|
|
||||||
name: 'Ink',
|
|
||||||
rate: 50,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,79 +25,20 @@ const partyMap = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const batchMap = {
|
|
||||||
batchOne: {
|
|
||||||
name: 'PL-AB001',
|
|
||||||
manufactureDate: '2022-11-03T09:57:04.528',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const priceListMap = {
|
const priceListMap = {
|
||||||
PL_SELL: {
|
PL_SELL: {
|
||||||
name: 'PL_SELL',
|
name: 'PL_SELL',
|
||||||
enabled: true,
|
isSales: true,
|
||||||
party: 'Shaju',
|
priceListItem: [
|
||||||
buying: false,
|
|
||||||
selling: true,
|
|
||||||
isUomDependent: false,
|
|
||||||
itemPrice: [
|
|
||||||
{
|
{
|
||||||
enabled: true,
|
|
||||||
item: itemMap.Pen.name,
|
item: itemMap.Pen.name,
|
||||||
rate: 101,
|
rate: 101,
|
||||||
buying: false,
|
|
||||||
selling: true,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
validFrom: '2023-02-28T18:30:00.678Z',
|
|
||||||
validUpto: '2023-03-30T18:30:00.678Z',
|
|
||||||
...getDefaultMetaFieldValueMap(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
PL_BUY: {
|
|
||||||
name: 'PL_BUY',
|
|
||||||
enabled: true,
|
|
||||||
buying: true,
|
|
||||||
selling: false,
|
|
||||||
isUomDependent: false,
|
|
||||||
itemPrice: [
|
|
||||||
{
|
|
||||||
enabled: true,
|
|
||||||
item: itemMap.Pen.name,
|
|
||||||
rate: 102,
|
|
||||||
buying: true,
|
|
||||||
selling: false,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
validFrom: '2023-02-28T18:30:00.678Z',
|
|
||||||
validUpto: '2023-03-30T18:30:00.678Z',
|
|
||||||
...getDefaultMetaFieldValueMap(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
PL_SB: {
|
|
||||||
name: 'PL_SB',
|
|
||||||
enabled: true,
|
|
||||||
selling: true,
|
|
||||||
buying: true,
|
|
||||||
isUomDependent: false,
|
|
||||||
itemPrice: [
|
|
||||||
{
|
|
||||||
enabled: true,
|
|
||||||
item: itemMap.Pen.name,
|
|
||||||
rate: 104,
|
|
||||||
batch: batchMap.batchOne.name,
|
|
||||||
buying: true,
|
|
||||||
selling: true,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
validFrom: '2023-05-05T18:30:00.000Z',
|
|
||||||
validUpto: '2023-06-05T18:30:00.000Z',
|
|
||||||
...getDefaultMetaFieldValueMap(),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
test('Price List: create dummy items, parties and batches', async (t) => {
|
test('Price List: create dummy item, party, price lists', async (t) => {
|
||||||
// Create Items
|
// Create Items
|
||||||
for (const { name, rate } of Object.values(itemMap)) {
|
for (const { name, rate } of Object.values(itemMap)) {
|
||||||
const item = getItem(name, rate, false);
|
const item = getItem(name, rate, false);
|
||||||
@ -119,101 +55,31 @@ test('Price List: create dummy items, parties and batches', async (t) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Batches
|
|
||||||
for (const batch of Object.values(batchMap)) {
|
|
||||||
await fyo.doc.getNewDoc(ModelNameEnum.Batch, batch).sync();
|
|
||||||
t.ok(
|
|
||||||
await fyo.db.exists(ModelNameEnum.Batch, batch.name),
|
|
||||||
`Batch: ${batch.name} exists`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('create Price Lists', async (t) => {
|
|
||||||
for (const priceListItem of Object.values(priceListMap)) {
|
for (const priceListItem of Object.values(priceListMap)) {
|
||||||
await fyo.doc.getNewDoc(ModelNameEnum.PriceList, priceListItem).sync();
|
await fyo.doc.getNewDoc(ModelNameEnum.PriceList, priceListItem).sync();
|
||||||
t.ok(
|
t.ok(
|
||||||
await fyo.db.exists(ModelNameEnum.PriceList, priceListItem.name),
|
await fyo.db.exists(ModelNameEnum.PriceList, priceListItem.name),
|
||||||
`Price List ${priceListItem.name} exists`
|
`Price List: ${priceListItem.name} exists`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await fyo.singles.AccountingSettings?.set('enablePriceList', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('check item price', async (t) => {
|
test('Check if InvoiceItem rate fetched from PriceList', async (t) => {
|
||||||
// check selling enabled item price
|
|
||||||
const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
||||||
items: [{ item: itemMap.Pen.name, quantity: 1 }],
|
date: new Date('2023-01-01'),
|
||||||
date: priceListMap.PL_SELL.itemPrice[0].validFrom,
|
|
||||||
priceList: priceListMap.PL_SELL.name,
|
|
||||||
party: partyMap.partyOne.name,
|
party: partyMap.partyOne.name,
|
||||||
}) as SalesInvoice;
|
}) as SalesInvoice;
|
||||||
|
|
||||||
const sinvItem = Object.values(sinv.items ?? {})[0];
|
await sinv.set('priceList', priceListMap.PL_SELL.name);
|
||||||
const sellEnabled = await getItemPrice(sinvItem as SalesInvoiceItem);
|
await sinv.append('items', {});
|
||||||
|
await sinv.items?.[0].set('item', itemMap.Pen.name);
|
||||||
const sellEnabledPLName = await fyo.getValue(
|
|
||||||
ModelNameEnum.ItemPrice,
|
|
||||||
sellEnabled as string,
|
|
||||||
'parent'
|
|
||||||
);
|
|
||||||
|
|
||||||
t.equal(sellEnabledPLName, priceListMap.PL_SELL.name);
|
|
||||||
|
|
||||||
// check buying enabled item price
|
|
||||||
const pinv = fyo.doc.getNewDoc(ModelNameEnum.PurchaseInvoice, {
|
|
||||||
items: [{ item: itemMap.Pen.name, quantity: 1 }],
|
|
||||||
date: priceListMap.PL_BUY.itemPrice[0].validFrom,
|
|
||||||
priceList: priceListMap.PL_BUY.name,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
}) as SalesInvoice;
|
|
||||||
|
|
||||||
const pinvItem = Object.values(pinv.items ?? {})[0];
|
|
||||||
const buyEnabled = await getItemPrice(pinvItem as PurchaseInvoiceItem);
|
|
||||||
|
|
||||||
const buyEnabledPLName = await fyo.getValue(
|
|
||||||
ModelNameEnum.ItemPrice,
|
|
||||||
buyEnabled as string,
|
|
||||||
'parent'
|
|
||||||
);
|
|
||||||
|
|
||||||
t.equal(buyEnabledPLName, priceListMap.PL_BUY.name);
|
|
||||||
|
|
||||||
// check sell batch enabled
|
|
||||||
const sinv1 = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
|
||||||
items: [
|
|
||||||
{ item: itemMap.Pen.name, quantity: 1, batch: batchMap.batchOne.name },
|
|
||||||
],
|
|
||||||
date: priceListMap.PL_SB.itemPrice[0].validFrom,
|
|
||||||
priceList: priceListMap.PL_SB.name,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
}) as SalesInvoice;
|
|
||||||
|
|
||||||
const sinv1Item = Object.values(sinv1.items ?? {})[0];
|
|
||||||
const sellBatchEnabled = await getItemPrice(sinv1Item as SalesInvoiceItem);
|
|
||||||
|
|
||||||
const sellBatchEnabledPLName = await fyo.getValue(
|
|
||||||
ModelNameEnum.ItemPrice,
|
|
||||||
sellBatchEnabled as string,
|
|
||||||
'parent'
|
|
||||||
);
|
|
||||||
|
|
||||||
t.equal(sellBatchEnabledPLName, priceListMap.PL_SB.name);
|
|
||||||
|
|
||||||
// undefined returns
|
|
||||||
const sinv2 = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
|
|
||||||
items: [{ item: itemMap.Ink.name, quantity: 1 }],
|
|
||||||
date: priceListMap.PL_SELL.itemPrice[0].validFrom,
|
|
||||||
priceList: priceListMap.PL_SELL.name,
|
|
||||||
party: partyMap.partyOne.name,
|
|
||||||
}) as SalesInvoice;
|
|
||||||
|
|
||||||
const sinv2Item = Object.values(sinv2.items ?? {})[0];
|
|
||||||
const nonExistItem = await getItemPrice(sinv2Item as SalesInvoiceItem);
|
|
||||||
|
|
||||||
t.equal(
|
t.equal(
|
||||||
nonExistItem,
|
sinv.items?.[0].rate?.float,
|
||||||
undefined,
|
priceListMap.PL_SELL.priceListItem[0].rate,
|
||||||
'itemPrice of non-existing item in price list returns false'
|
`sales invoice rate fetched from price list`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,15 +19,13 @@
|
|||||||
"fieldname": "isSales",
|
"fieldname": "isSales",
|
||||||
"label": "For Sales",
|
"label": "For Sales",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": true,
|
"default": true
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "isPurchase",
|
"fieldname": "isPurchase",
|
||||||
"label": "For Purchase",
|
"label": "For Purchase",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": false,
|
"default": false
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "priceListItem",
|
"fieldname": "priceListItem",
|
||||||
|
Loading…
Reference in New Issue
Block a user