mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: update PurchaseInvoice to use pesa
This commit is contained in:
parent
4385a93a77
commit
1e6113e92f
@ -1,5 +1,5 @@
|
|||||||
import { getActions } from '../Transaction/Transaction';
|
|
||||||
import InvoiceTemplate from '../SalesInvoice/InvoiceTemplate.vue';
|
import InvoiceTemplate from '../SalesInvoice/InvoiceTemplate.vue';
|
||||||
|
import { getActions } from '../Transaction/Transaction';
|
||||||
import PurchaseInvoice from './PurchaseInvoiceDocument';
|
import PurchaseInvoice from './PurchaseInvoiceDocument';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -61,7 +61,8 @@ export default {
|
|||||||
fieldname: 'exchangeRate',
|
fieldname: 'exchangeRate',
|
||||||
label: 'Exchange Rate',
|
label: 'Exchange Rate',
|
||||||
fieldtype: 'Float',
|
fieldtype: 'Float',
|
||||||
formula: (doc) => doc.getExchangeRate(),
|
default: 1,
|
||||||
|
formula: async (doc) => await doc.getExchangeRate(),
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -75,7 +76,7 @@ export default {
|
|||||||
fieldname: 'netTotal',
|
fieldname: 'netTotal',
|
||||||
label: 'Net Total',
|
label: 'Net Total',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
formula: (doc) => doc.getSum('items', 'amount'),
|
formula: (doc) => doc.getSum('items', 'amount', false),
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
getCurrency: (doc) => doc.currency,
|
getCurrency: (doc) => doc.currency,
|
||||||
},
|
},
|
||||||
@ -83,7 +84,7 @@ export default {
|
|||||||
fieldname: 'baseNetTotal',
|
fieldname: 'baseNetTotal',
|
||||||
label: 'Net Total (Company Currency)',
|
label: 'Net Total (Company Currency)',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
formula: (doc) => doc.netTotal * doc.exchangeRate,
|
formula: (doc) => doc.netTotal.mul(doc.exchangeRate),
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -106,7 +107,7 @@ export default {
|
|||||||
fieldname: 'baseGrandTotal',
|
fieldname: 'baseGrandTotal',
|
||||||
label: 'Grand Total (Company Currency)',
|
label: 'Grand Total (Company Currency)',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
formula: (doc) => doc.grandTotal * doc.exchangeRate,
|
formula: (doc) => doc.grandTotal.mul(doc.exchangeRate),
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ export default {
|
|||||||
label: 'Quantity',
|
label: 'Quantity',
|
||||||
fieldtype: 'Float',
|
fieldtype: 'Float',
|
||||||
required: 1,
|
required: 1,
|
||||||
formula: () => 1,
|
default: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname: 'rate',
|
fieldname: 'rate',
|
||||||
@ -40,9 +40,9 @@ export default {
|
|||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
required: 1,
|
required: 1,
|
||||||
formula: async (row, doc) => {
|
formula: async (row, doc) => {
|
||||||
const baseRate = (await doc.getFrom('Item', row.item, 'rate')) || 0;
|
const baseRate =
|
||||||
const exchangeRate = doc.exchangeRate ?? 1;
|
(await doc.getFrom('Item', row.item, 'rate')) || frappe.pesa(0);
|
||||||
return baseRate / exchangeRate;
|
return baseRate.div(doc.exchangeRate);
|
||||||
},
|
},
|
||||||
getCurrency: (row, doc) => doc.currency,
|
getCurrency: (row, doc) => doc.currency,
|
||||||
},
|
},
|
||||||
@ -50,7 +50,7 @@ export default {
|
|||||||
fieldname: 'baseRate',
|
fieldname: 'baseRate',
|
||||||
label: 'Rate (Company Currency)',
|
label: 'Rate (Company Currency)',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
formula: (row, doc) => row.rate * doc.exchangeRate,
|
formula: (row, doc) => row.rate.mul(doc.exchangeRate),
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ export default {
|
|||||||
label: 'Amount',
|
label: 'Amount',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
formula: (row) => row.quantity * row.rate,
|
formula: (row) => row.rate.mul(row.quantity),
|
||||||
getCurrency: (row, doc) => doc.currency,
|
getCurrency: (row, doc) => doc.currency,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ export default {
|
|||||||
label: 'Amount (Company Currency)',
|
label: 'Amount (Company Currency)',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
readOnly: 1,
|
readOnly: 1,
|
||||||
formula: (row, doc) => row.amount * doc.exchangeRate,
|
formula: (row, doc) => row.amount.mul(doc.exchangeRate),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -8,26 +8,26 @@ export default {
|
|||||||
label: 'Tax Account',
|
label: 'Tax Account',
|
||||||
fieldtype: 'Link',
|
fieldtype: 'Link',
|
||||||
target: 'Account',
|
target: 'Account',
|
||||||
required: 1
|
required: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname: 'rate',
|
fieldname: 'rate',
|
||||||
label: 'Rate',
|
label: 'Rate',
|
||||||
fieldtype: 'Float',
|
fieldtype: 'Float',
|
||||||
required: 1
|
required: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname: 'amount',
|
fieldname: 'amount',
|
||||||
label: 'Amount',
|
label: 'Amount',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
required: 1
|
required: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldname: 'baseAmount',
|
fieldname: 'baseAmount',
|
||||||
label: 'Amount (Company Currency)',
|
label: 'Amount (Company Currency)',
|
||||||
fieldtype: 'Currency',
|
fieldtype: 'Currency',
|
||||||
formula: (row, doc) => row.amount * doc.exchangeRate,
|
formula: (row, doc) => row.amount.mul(doc.exchangeRate),
|
||||||
readOnly: 1
|
readOnly: 1,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import BaseDocument from 'frappejs/model/document';
|
|
||||||
import frappe from 'frappejs';
|
import frappe from 'frappejs';
|
||||||
import { round } from 'frappejs/utils/numberFormat';
|
import BaseDocument from 'frappejs/model/document';
|
||||||
import { getExchangeRate } from '../../../accounting/exchangeRate';
|
import { getExchangeRate } from '../../../accounting/exchangeRate';
|
||||||
|
|
||||||
export default class TransactionDocument extends BaseDocument {
|
export default class TransactionDocument extends BaseDocument {
|
||||||
async getExchangeRate() {
|
async getExchangeRate() {
|
||||||
if (!this.currency) return;
|
if (!this.currency) return 1.0;
|
||||||
|
|
||||||
let accountingSettings = await frappe.getSingle('AccountingSettings');
|
let accountingSettings = await frappe.getSingle('AccountingSettings');
|
||||||
const companyCurrency = accountingSettings.currency;
|
const companyCurrency = accountingSettings.currency;
|
||||||
@ -14,7 +13,7 @@ export default class TransactionDocument extends BaseDocument {
|
|||||||
}
|
}
|
||||||
return await getExchangeRate({
|
return await getExchangeRate({
|
||||||
fromCurrency: this.currency,
|
fromCurrency: this.currency,
|
||||||
toCurrency: companyCurrency
|
toCurrency: companyCurrency,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,31 +21,30 @@ export default class TransactionDocument extends BaseDocument {
|
|||||||
let taxes = {};
|
let taxes = {};
|
||||||
|
|
||||||
for (let row of this.items) {
|
for (let row of this.items) {
|
||||||
if (row.tax) {
|
if (!row.tax) {
|
||||||
let tax = await this.getTax(row.tax);
|
continue;
|
||||||
for (let d of tax.details) {
|
}
|
||||||
let amount = (row.amount * d.rate) / 100;
|
|
||||||
taxes[d.account] = taxes[d.account] || {
|
const tax = await this.getTax(row.tax);
|
||||||
account: d.account,
|
for (let d of tax.details) {
|
||||||
rate: d.rate,
|
taxes[d.account] = taxes[d.account] || {
|
||||||
amount: 0
|
account: d.account,
|
||||||
};
|
rate: d.rate,
|
||||||
// collect amount
|
amount: frappe.pesa(0),
|
||||||
taxes[d.account].amount += amount;
|
};
|
||||||
}
|
|
||||||
|
const amount = row.amount.mul(d.rate).div(100);
|
||||||
|
taxes[d.account].amount = taxes[d.account].amount.add(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return Object.keys(taxes)
|
||||||
Object.keys(taxes)
|
.map((account) => {
|
||||||
.map(account => {
|
const tax = taxes[account];
|
||||||
let tax = taxes[account];
|
tax.baseAmount = tax.amount.mul(this.exchangeRate);
|
||||||
tax.baseAmount = round(tax.amount * this.exchangeRate, 2);
|
return tax;
|
||||||
return tax;
|
})
|
||||||
})
|
.filter((tax) => !tax.amount.isZero());
|
||||||
// clear rows with 0 amount
|
|
||||||
.filter(tax => tax.amount)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTax(tax) {
|
async getTax(tax) {
|
||||||
@ -56,13 +54,8 @@ export default class TransactionDocument extends BaseDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getGrandTotal() {
|
async getGrandTotal() {
|
||||||
let grandTotal = this.netTotal;
|
return (this.taxes || [])
|
||||||
if (this.taxes) {
|
.map(({ amount }) => amount)
|
||||||
for (let row of this.taxes) {
|
.reduce((a, b) => a.add(b), this.netTotal);
|
||||||
grandTotal += row.amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return grandTotal;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user