fix: default to company currency in report output

This commit is contained in:
ruthra kumar 2022-02-15 12:20:06 +05:30
parent bc244d0740
commit 85ed0fb8d6

View File

@ -41,7 +41,7 @@ def get_columns():
}, },
{ {
"label": _("Payment Amount"), "label": _("Payment Amount"),
"fieldname": "payment_amount", "fieldname": "base_payment_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"options": "currency", "options": "currency",
}, },
@ -113,7 +113,7 @@ def get_so_with_invoices(filters):
ps.description, ps.description,
ps.due_date, ps.due_date,
ps.invoice_portion, ps.invoice_portion,
ps.payment_amount, ps.base_payment_amount,
ps.paid_amount, ps.paid_amount,
) )
.where( .where(
@ -141,7 +141,7 @@ def get_so_with_invoices(filters):
.on(si.name == sii.parent) .on(si.name == sii.parent)
.inner_join(soi) .inner_join(soi)
.on(soi.name == sii.so_detail) .on(soi.name == sii.so_detail)
.select(sii.sales_order, sii.parent.as_("invoice"), si.base_net_total.as_("invoice_amount")) .select(sii.sales_order, sii.parent.as_("invoice"), si.base_grand_total.as_("invoice_amount"))
.where((sii.sales_order.isin([x.name for x in sorders])) & (si.docstatus == 1)) .where((sii.sales_order.isin([x.name for x in sorders])) & (si.docstatus == 1))
.groupby(sii.parent) .groupby(sii.parent)
) )
@ -158,8 +158,8 @@ def set_payment_terms_statuses(sales_orders, invoices, filters):
for so in sales_orders: for so in sales_orders:
so.currency = frappe.get_cached_value('Company', filters.get('company'), 'default_currency') so.currency = frappe.get_cached_value('Company', filters.get('company'), 'default_currency')
for inv in [x for x in invoices if x.sales_order == so.name and x.invoice_amount > 0]: for inv in [x for x in invoices if x.sales_order == so.name and x.invoice_amount > 0]:
if so.payment_amount - so.paid_amount > 0: if so.base_payment_amount - so.paid_amount > 0:
amount = so.payment_amount - so.paid_amount amount = so.base_payment_amount - so.paid_amount
if inv.invoice_amount >= amount: if inv.invoice_amount >= amount:
inv.invoice_amount -= amount inv.invoice_amount -= amount
so.paid_amount += amount so.paid_amount += amount
@ -187,7 +187,7 @@ def prepare_chart(s_orders):
"data": { "data": {
"labels": [term.payment_term for term in s_orders], "labels": [term.payment_term for term in s_orders],
"datasets": [ "datasets": [
{"name": "Payment Amount", "values": [x.payment_amount for x in s_orders],}, {"name": "Payment Amount", "values": [x.base_payment_amount for x in s_orders],},
{"name": "Paid Amount", "values": [x.paid_amount for x in s_orders],}, {"name": "Paid Amount", "values": [x.paid_amount for x in s_orders],},
], ],
}, },