refactor: currency field and code cleanup

This commit is contained in:
ruthra kumar 2022-02-08 18:53:08 +05:30
parent 4284017e9d
commit bc244d0740

View File

@ -13,62 +13,60 @@ def get_columns():
"fieldname": "name", "fieldname": "name",
"fieldtype": "Link", "fieldtype": "Link",
"options": "Sales Order", "options": "Sales Order",
"read_only": 1,
}, },
{ {
"label": _("Submitted"), "label": _("Posting Date"),
"fieldname": "submitted", "fieldname": "submitted",
"fieldtype": "Date", "fieldtype": "Date",
"read_only": 1
}, },
{ {
"label": _("Payment Term"), "label": _("Payment Term"),
"fieldname": "payment_term", "fieldname": "payment_term",
"fieldtype": "Data", "fieldtype": "Data",
"read_only": 1
}, },
{ {
"label": _("Description"), "label": _("Description"),
"fieldname": "description", "fieldname": "description",
"fieldtype": "Data", "fieldtype": "Data",
"read_only": 1
}, },
{ {
"label": _("Due Date"), "label": _("Due Date"),
"fieldname": "due_date", "fieldname": "due_date",
"fieldtype": "Date", "fieldtype": "Date",
"read_only": 1
}, },
{ {
"label": _("Invoice Portion"), "label": _("Invoice Portion"),
"fieldname": "invoice_portion", "fieldname": "invoice_portion",
"fieldtype": "Percent", "fieldtype": "Percent",
"read_only": 1,
}, },
{ {
"label": _("Payment Amount"), "label": _("Payment Amount"),
"fieldname": "payment_amount", "fieldname": "payment_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"read_only": 1, "options": "currency",
}, },
{ {
"label": _("Paid Amount"), "label": _("Paid Amount"),
"fieldname": "paid_amount", "fieldname": "paid_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"read_only": 1 "options": "currency",
}, },
{ {
"label": _("Invoices"), "label": _("Invoices"),
"fieldname": "invoices", "fieldname": "invoices",
"fieldtype": "Link", "fieldtype": "Link",
"options": "Sales Invoice", "options": "Sales Invoice",
"read_only": 1,
}, },
{ {
"label": _("Status"), "label": _("Status"),
"fieldname": "status", "fieldname": "status",
"fieldtype": "Data", "fieldtype": "Data",
"read_only": 1 },
{
"label": _("Currency"),
"fieldname": "currency",
"fieldtype": "Currency",
"hidden": 1
} }
] ]
return columns return columns
@ -152,12 +150,13 @@ def get_so_with_invoices(filters):
return sorders, invoices return sorders, invoices
def set_payment_terms_statuses(sales_orders, invoices): def set_payment_terms_statuses(sales_orders, invoices, filters):
""" """
compute status for payment terms with associated sales invoice using FIFO compute status for payment terms with associated sales invoice using FIFO
""" """
for so in sales_orders: for so in sales_orders:
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.payment_amount - so.paid_amount > 0:
amount = so.payment_amount - so.paid_amount amount = so.payment_amount - so.paid_amount
@ -200,7 +199,7 @@ def prepare_chart(s_orders):
def execute(filters=None): def execute(filters=None):
columns = get_columns() columns = get_columns()
sales_orders, so_invoices = get_so_with_invoices(filters) sales_orders, so_invoices = get_so_with_invoices(filters)
sales_orders, so_invoices = set_payment_terms_statuses(sales_orders, so_invoices) sales_orders, so_invoices = set_payment_terms_statuses(sales_orders, so_invoices, filters)
prepare_chart(sales_orders) prepare_chart(sales_orders)