From 6e837599b10b86e7858e9b7fb6bb9aed0c22207e Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 8 Jun 2016 16:35:10 +0530 Subject: [PATCH] [minor] added cost center to item wise sales register, fixes #5301 --- .../item_wise_sales_register.py | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py index 6fc7349bb84..9f303499cbb 100644 --- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py +++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py @@ -21,7 +21,7 @@ def execute(filters=None): "width": 80 }) company_currency = frappe.db.get_value("Company", filters.company, "default_currency") - + data = [] for d in item_list: delivery_note = None @@ -33,7 +33,7 @@ def execute(filters=None): row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.customer, d.customer_name, d.customer_group, d.debit_to, d.mode_of_payment, d.territory, d.project, d.company, d.sales_order, - delivery_note, d.income_account, d.qty, d.base_net_rate, d.base_net_amount] + delivery_note, d.income_account, d.cost_center, d.qty, d.base_net_rate, d.base_net_amount] for tax in tax_accounts: row.append(item_row_tax.get(d.name, {}).get(tax, 0)) @@ -51,12 +51,14 @@ def get_columns(): _("Item Group") + ":Link/Item Group:100", _("Invoice") + ":Link/Sales Invoice:120", _("Posting Date") + ":Date:80", _("Customer") + ":Link/Customer:120", _("Customer Name") + "::120", _("Customer Group") + ":Link/Customer Group:120", - _("Receivable Account") + ":Link/Account:120", - _("Mode of Payment") + ":Link/Mode of Payment:80", _("Territory") + ":Link/Territory:80", + _("Receivable Account") + ":Link/Account:120", + _("Mode of Payment") + ":Link/Mode of Payment:80", _("Territory") + ":Link/Territory:80", _("Project") + ":Link/Project:80", _("Company") + ":Link/Company:100", _("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100", - _("Income Account") + ":Link/Account:140", _("Qty") + ":Float:120", - _("Rate") + ":Currency/currency:120", _("Amount") + ":Currency/currency:120" + _("Income Account") + ":Link/Account:140", _("Cost Center") + ":Link/Cost Center:140", + _("Qty") + ":Float:120", + _("Rate") + ":Currency/currency:120", + _("Amount") + ":Currency/currency:120" ] def get_conditions(filters): @@ -78,9 +80,9 @@ def get_items(filters): return frappe.db.sql(""" select si_item.name, si_item.parent, si.posting_date, si.debit_to, si.project, - si.customer, si.remarks, si.territory, si.company, si.base_net_total, - si_item.item_code, si_item.item_name, si_item.item_group, si_item.sales_order, - si_item.delivery_note, si_item.income_account, si_item.qty, + si.customer, si.remarks, si.territory, si.company, si.base_net_total, + si_item.item_code, si_item.item_name, si_item.item_group, si_item.sales_order, + si_item.delivery_note, si_item.income_account, si_item.cost_center, si_item.qty, si_item.base_net_rate, si_item.base_net_amount, si.customer_name, si.customer_group, si_item.so_detail, si.mode_of_payment from `tabSales Invoice` si, `tabSales Invoice Item` si_item @@ -98,12 +100,12 @@ def get_tax_accounts(item_list, columns): item_row_map.setdefault(d.parent, {}).setdefault(d.item_code, []).append(d) tax_details = frappe.db.sql(""" - select + select parent, account_head, item_wise_tax_detail, charge_type, base_tax_amount_after_discount_amount - from `tabSales Taxes and Charges` - where - parenttype = 'Sales Invoice' and docstatus = 1 + from `tabSales Taxes and Charges` + where + parenttype = 'Sales Invoice' and docstatus = 1 and (account_head is not null and account_head != '') and parent in (%s) """ % ', '.join(['%s']*len(invoice_item_row)), tuple(invoice_item_row.keys())) @@ -111,21 +113,21 @@ def get_tax_accounts(item_list, columns): for parent, account_head, item_wise_tax_detail, charge_type, tax_amount in tax_details: if account_head not in tax_accounts: tax_accounts.append(account_head) - + if item_wise_tax_detail: try: item_wise_tax_detail = json.loads(item_wise_tax_detail) for item_code, tax_amount in item_wise_tax_detail.items(): tax_amount = flt(tax_amount[1]) if isinstance(tax_amount, list) else flt(tax_amount) - - item_net_amount = sum([flt(d.base_net_amount) + + item_net_amount = sum([flt(d.base_net_amount) for d in item_row_map.get(parent, {}).get(item_code, [])]) - + for d in item_row_map.get(parent, {}).get(item_code, []): item_tax_amount = flt((tax_amount * d.base_net_amount) / item_net_amount) if item_net_amount else 0 item_row_tax.setdefault(d.name, {})[account_head] = item_tax_amount - + except ValueError: continue elif charge_type == "Actual" and tax_amount: