2
0
mirror of https://github.com/frappe/books.git synced 2024-11-15 01:44:04 +00:00
books/models/baseModels/tests/testPriceList.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-06-06 08:59:19 +00:00
import test from 'tape';
import { closeTestFyo, getTestFyo, setupTestFyo } from 'tests/helpers';
import { ModelNameEnum } from 'models/types';
import { getItem } from 'models/inventory/tests/helpers';
import { SalesInvoice } from '../SalesInvoice/SalesInvoice';
const fyo = getTestFyo();
setupTestFyo(fyo, __filename);
const itemMap = {
Pen: {
name: 'Pen',
rate: 100,
2023-06-07 05:07:13 +00:00
unit: 'Unit',
2023-06-06 08:59:19 +00:00
},
};
const partyMap = {
partyOne: {
name: 'John Whoe',
email: 'john@whoe.com',
},
};
const priceListMap = {
PL_SELL: {
name: 'PL_SELL',
2023-06-07 05:07:13 +00:00
isSales: true,
priceListItem: [
2023-06-06 08:59:19 +00:00
{
item: itemMap.Pen.name,
rate: 101,
},
],
},
};
2023-06-07 05:07:13 +00:00
test('Price List: create dummy item, party, price lists', async (t) => {
2023-06-06 08:59:19 +00:00
// Create Items
for (const { name, rate } of Object.values(itemMap)) {
const item = getItem(name, rate, false);
await fyo.doc.getNewDoc(ModelNameEnum.Item, item).sync();
t.ok(await fyo.db.exists(ModelNameEnum.Item, name), `Item: ${name} exists`);
}
// Create Parties
for (const { name, email } of Object.values(partyMap)) {
await fyo.doc.getNewDoc(ModelNameEnum.Party, { name, email }).sync();
t.ok(
await fyo.db.exists(ModelNameEnum.Party, name),
`Party: ${name} exists`
);
}
for (const priceListItem of Object.values(priceListMap)) {
await fyo.doc.getNewDoc(ModelNameEnum.PriceList, priceListItem).sync();
t.ok(
await fyo.db.exists(ModelNameEnum.PriceList, priceListItem.name),
2023-06-07 05:07:13 +00:00
`Price List: ${priceListItem.name} exists`
2023-06-06 08:59:19 +00:00
);
}
2023-06-07 05:07:13 +00:00
await fyo.singles.AccountingSettings?.set('enablePriceList', true);
2023-06-06 08:59:19 +00:00
});
2023-06-07 05:07:13 +00:00
test('Check if InvoiceItem rate fetched from PriceList', async (t) => {
2023-06-06 08:59:19 +00:00
const sinv = fyo.doc.getNewDoc(ModelNameEnum.SalesInvoice, {
2023-06-07 05:07:13 +00:00
date: new Date('2023-01-01'),
2023-06-06 08:59:19 +00:00
party: partyMap.partyOne.name,
}) as SalesInvoice;
2023-06-07 05:07:13 +00:00
await sinv.set('priceList', priceListMap.PL_SELL.name);
await sinv.append('items', {});
await sinv.items?.[0].set('item', itemMap.Pen.name);
2023-06-06 08:59:19 +00:00
t.equal(
2023-06-07 05:07:13 +00:00
sinv.items?.[0].rate?.float,
priceListMap.PL_SELL.priceListItem[0].rate,
`sales invoice rate fetched from price list`
2023-06-06 08:59:19 +00:00
);
});
closeTestFyo(fyo, __filename);