2021-11-04 10:31:26 +00:00
|
|
|
import assert from 'assert';
|
2022-01-20 20:57:29 +00:00
|
|
|
import frappe from 'frappe';
|
|
|
|
import helpers from 'frappe/tests/helpers';
|
2021-11-04 10:31:26 +00:00
|
|
|
import models from '../models';
|
2018-02-16 13:14:38 +00:00
|
|
|
|
|
|
|
async function makeFixtures() {
|
2018-03-05 16:45:40 +00:00
|
|
|
if (!(await frappe.db.exists('Party', 'Test Customer'))) {
|
|
|
|
await frappe.insert({doctype:'Party', name:'Test Customer'})
|
2018-02-16 13:14:38 +00:00
|
|
|
await frappe.insert({doctype:'Item', name:'Test Item 1', description:'Test Item Description 1', unit:'No', rate: 100})
|
|
|
|
await frappe.insert({doctype:'Item', name:'Test Item 2', description:'Test Item Description 2', unit:'No', rate: 200})
|
2018-04-02 17:54:35 +00:00
|
|
|
await frappe.insert({doctype:'Account', name:'GST', parentAccount: 'Liabilities'});
|
2018-02-16 13:14:38 +00:00
|
|
|
await frappe.insert({doctype:'Tax', name:'GST',
|
|
|
|
details: [{account: 'GST', rate:10}]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Invoice', () => {
|
|
|
|
before(async function() {
|
|
|
|
await helpers.initSqlite({models: models});
|
|
|
|
await makeFixtures();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('show create an invoice', async () => {
|
|
|
|
let invoice = await frappe.insert({
|
|
|
|
doctype:'Invoice',
|
|
|
|
customer: 'Test Customer',
|
|
|
|
items: [
|
|
|
|
{item: 'Test Item 1', quantity: 5},
|
|
|
|
{item: 'Test Item 2', quantity: 7},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(invoice.items[0].amount, 500);
|
|
|
|
assert.equal(invoice.items[1].amount, 1400);
|
|
|
|
assert.equal(invoice.netTotal, 1900);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('show create an invoice with tax', async () => {
|
|
|
|
let invoice = await frappe.insert({
|
|
|
|
doctype:'Invoice',
|
|
|
|
customer: 'Test Customer',
|
|
|
|
items: [
|
|
|
|
{item: 'Test Item 1', quantity: 5, tax: 'GST'},
|
|
|
|
{item: 'Test Item 2', quantity: 7, tax: 'GST'},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(invoice.items[0].amount, 500);
|
|
|
|
assert.equal(invoice.items[1].amount, 1400);
|
|
|
|
assert.equal(invoice.netTotal, 1900);
|
|
|
|
assert.equal(invoice.taxes[0].amount, 190);
|
|
|
|
assert.equal(invoice.grandTotal, 2090);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|