2022-02-16 06:19:16 +00:00
|
|
|
import { t } from 'frappe';
|
2021-11-04 10:31:26 +00:00
|
|
|
export default {
|
2019-08-01 11:52:58 +00:00
|
|
|
name: 'SalesInvoiceItem',
|
2018-07-10 13:37:02 +00:00
|
|
|
doctype: 'DocType',
|
|
|
|
isChild: 1,
|
2021-12-16 06:17:25 +00:00
|
|
|
regional: 1,
|
2018-07-10 13:37:02 +00:00
|
|
|
keywordFields: [],
|
2019-11-27 06:46:15 +00:00
|
|
|
tableFields: ['item', 'tax', 'quantity', 'rate', 'amount'],
|
2019-07-19 13:24:31 +00:00
|
|
|
fields: [
|
|
|
|
{
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldname: 'item',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Item`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Link',
|
|
|
|
target: 'Item',
|
2020-02-03 17:55:02 +00:00
|
|
|
required: 1,
|
|
|
|
getFilters(_, doc) {
|
2021-12-10 19:17:28 +00:00
|
|
|
let items = doc.parentdoc.items.map((d) => d.item).filter(Boolean);
|
2022-03-10 06:53:28 +00:00
|
|
|
|
|
|
|
const baseFilter = { for: ['not in', ['purchases']] };
|
|
|
|
if (items.length <= 0) {
|
|
|
|
return baseFilter;
|
2020-02-03 17:55:02 +00:00
|
|
|
}
|
2022-03-10 06:53:28 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
name: ['not in', items],
|
|
|
|
...baseFilter,
|
|
|
|
};
|
2021-12-10 19:17:28 +00:00
|
|
|
},
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'description',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Description`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Text',
|
|
|
|
formula: (row, doc) => doc.getFrom('Item', row.item, 'description'),
|
2021-10-14 18:28:27 +00:00
|
|
|
hidden: 1,
|
2021-12-10 19:17:28 +00:00
|
|
|
formulaDependsOn: ['item'],
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'quantity',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Quantity`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Float',
|
2019-12-12 19:34:37 +00:00
|
|
|
required: 1,
|
2021-12-28 08:15:19 +00:00
|
|
|
default: 1,
|
2022-01-10 08:08:20 +00:00
|
|
|
validate(value, doc) {
|
|
|
|
if (value >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new frappe.errors.ValidationError(
|
2022-02-09 06:37:33 +00:00
|
|
|
frappe.t`Quantity (${value}) cannot be less than zero.`
|
2022-01-10 08:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'rate',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Rate`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Currency',
|
|
|
|
required: 1,
|
2019-12-03 08:10:42 +00:00
|
|
|
formula: async (row, doc) => {
|
2021-12-28 08:15:19 +00:00
|
|
|
const baseRate =
|
|
|
|
(await doc.getFrom('Item', row.item, 'rate')) || frappe.pesa(0);
|
|
|
|
return baseRate.div(doc.exchangeRate);
|
2019-12-03 08:10:42 +00:00
|
|
|
},
|
2021-10-14 18:28:27 +00:00
|
|
|
getCurrency: (row, doc) => doc.currency,
|
2021-12-10 19:17:28 +00:00
|
|
|
formulaDependsOn: ['item'],
|
2022-01-10 08:08:20 +00:00
|
|
|
validate(value, doc) {
|
|
|
|
if (value.gte(0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new frappe.errors.ValidationError(
|
2022-02-09 06:37:33 +00:00
|
|
|
frappe.t`Rate (${frappe.format(
|
|
|
|
value,
|
|
|
|
'Currency'
|
|
|
|
)}) cannot be less zero.`
|
2022-01-10 08:08:20 +00:00
|
|
|
);
|
|
|
|
},
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
2019-11-27 06:46:15 +00:00
|
|
|
{
|
|
|
|
fieldname: 'baseRate',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Rate (Company Currency)`,
|
2019-11-27 06:46:15 +00:00
|
|
|
fieldtype: 'Currency',
|
2021-12-28 08:15:19 +00:00
|
|
|
formula: (row, doc) => row.rate.mul(doc.exchangeRate),
|
2021-12-10 19:17:28 +00:00
|
|
|
readOnly: 1,
|
2019-11-27 06:46:15 +00:00
|
|
|
},
|
2018-07-10 13:37:02 +00:00
|
|
|
{
|
|
|
|
fieldname: 'account',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Account`,
|
2018-07-10 13:37:02 +00:00
|
|
|
hidden: 1,
|
|
|
|
fieldtype: 'Link',
|
|
|
|
target: 'Account',
|
2019-07-19 13:24:31 +00:00
|
|
|
required: 1,
|
2022-02-28 12:06:41 +00:00
|
|
|
readOnly: 1,
|
2021-12-10 19:17:28 +00:00
|
|
|
formula: (row, doc) => doc.getFrom('Item', row.item, 'incomeAccount'),
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'tax',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Tax`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Link',
|
|
|
|
target: 'Tax',
|
2021-10-19 09:05:47 +00:00
|
|
|
formula: (row, doc) => doc.getFrom('Item', row.item, 'tax'),
|
2021-12-10 19:17:28 +00:00
|
|
|
formulaDependsOn: ['item'],
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'amount',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Amount`,
|
2018-07-10 13:37:02 +00:00
|
|
|
fieldtype: 'Currency',
|
2018-09-25 12:00:10 +00:00
|
|
|
readOnly: 1,
|
2021-12-28 08:15:19 +00:00
|
|
|
formula: (row) => row.rate.mul(row.quantity),
|
2021-12-10 19:17:28 +00:00
|
|
|
getCurrency: (row, doc) => doc.currency,
|
2018-07-10 13:37:02 +00:00
|
|
|
},
|
2019-11-27 06:46:15 +00:00
|
|
|
{
|
|
|
|
fieldname: 'baseAmount',
|
2022-02-16 06:19:16 +00:00
|
|
|
label: t`Amount (Company Currency)`,
|
2019-11-27 06:46:15 +00:00
|
|
|
fieldtype: 'Currency',
|
|
|
|
readOnly: 1,
|
2021-12-28 08:15:19 +00:00
|
|
|
formula: (row, doc) => row.amount.mul(doc.exchangeRate),
|
2021-12-10 19:17:28 +00:00
|
|
|
},
|
|
|
|
],
|
2018-07-10 13:37:02 +00:00
|
|
|
};
|