From 82e3e25cdbb60581d53c9c49ba9a6ad02d2d9ce6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 23 Feb 2015 16:58:30 +0530 Subject: [PATCH] fixes for base_rate, base_amount, tax_amount: mass search and replace --- .../purchase_invoice/purchase_invoice.py | 14 ++--- .../doctype/sales_invoice/sales_invoice.py | 8 +-- .../report/gross_profit/gross_profit.py | 6 +-- .../item_wise_purchase_register.py | 10 ++-- .../item_wise_sales_register.py | 11 ++-- .../purchase_register/purchase_register.py | 4 +- .../report/sales_register/sales_register.py | 6 +-- .../purchase_analytics/purchase_analytics.js | 2 +- erpnext/controllers/buying_controller.py | 8 +-- erpnext/controllers/trends.py | 6 +-- .../project_wise_stock_tracking.py | 30 +++++------ erpnext/public/js/feature_setup.js | 52 +++++++++++++------ .../page/sales_analytics/sales_analytics.js | 2 +- ..._person_target_variance_item_group_wise.py | 4 +- .../sales_person_wise_transaction_summary.py | 6 +-- ...rritory_target_variance_item_group_wise.py | 5 +- erpnext/shopping_cart/cart.py | 2 +- erpnext/startup/report_data_map.py | 12 ++--- .../purchase_receipt/purchase_receipt.py | 14 ++--- erpnext/stock/get_item_details.py | 2 + 20 files changed, 113 insertions(+), 91 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 4e0570f9b9..a289c03ff8 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -275,36 +275,36 @@ class PurchaseInvoice(BuyingController): # tax table gl entries valuation_tax = {} for tax in self.get("taxes"): - if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount): + if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount): gl_entries.append( self.get_gl_dict({ "account": tax.account_head, "against": self.credit_to, - "debit": tax.add_deduct_tax == "Add" and tax.tax_amount or 0, - "credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0, + "debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0, + "credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0, "remarks": self.remarks, "cost_center": tax.cost_center }) ) # accumulate valuation tax - if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount): + if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount): if auto_accounting_for_stock and not tax.cost_center: frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category))) valuation_tax.setdefault(tax.cost_center, 0) valuation_tax[tax.cost_center] += \ - (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount) + (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount) # item gl entries negative_expense_to_be_booked = 0.0 stock_items = self.get_stock_items() for item in self.get("items"): - if flt(item.base_amount): + if flt(item.base_net_amount): gl_entries.append( self.get_gl_dict({ "account": item.expense_account, "against": self.credit_to, - "debit": item.base_amount, + "debit": item.base_net_amount, "remarks": self.remarks, "cost_center": item.cost_center }) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f3ff9e1517..3b901c4681 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -496,12 +496,12 @@ class SalesInvoice(SellingController): def make_tax_gl_entries(self, gl_entries): for tax in self.get("taxes"): - if flt(tax.tax_amount_after_discount_amount): + if flt(tax.base_tax_amount_after_discount_amount): gl_entries.append( self.get_gl_dict({ "account": tax.account_head, "against": self.debit_to, - "credit": flt(tax.tax_amount_after_discount_amount), + "credit": flt(tax.base_tax_amount_after_discount_amount), "remarks": self.remarks, "cost_center": tax.cost_center }) @@ -510,12 +510,12 @@ class SalesInvoice(SellingController): def make_item_gl_entries(self, gl_entries): # income account gl entries for item in self.get("items"): - if flt(item.base_amount): + if flt(item.base_net_amount): gl_entries.append( self.get_gl_dict({ "account": item.income_account, "against": self.debit_to, - "credit": item.base_amount, + "credit": item.base_net_amount, "remarks": self.remarks, "cost_center": item.cost_center }) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index d2129654ab..7ea9af9ab2 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -95,7 +95,7 @@ class GrossProfitGenerator(object): if self.skip_row(row, self.sales_boms): continue - row.selling_amount = flt(row.base_amount) + row.selling_amount = flt(row.base_net_amount) sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict()) @@ -175,7 +175,7 @@ class GrossProfitGenerator(object): # sorted by posting_date desc, posting_time desc if item_code in self.non_stock_items: # average purchasing rate for non-stock items - item_rate = frappe.db.sql("""select sum(base_amount) / sum(qty) + item_rate = frappe.db.sql("""select sum(base_net_amount) / sum(qty) from `tabPurchase Invoice Item` where item_code = %s and docstatus=1""", item_code) @@ -211,7 +211,7 @@ class GrossProfitGenerator(object): si.customer, si.customer_group, si.territory, item.item_code, item.item_name, item.description, item.warehouse, item.item_group, item.brand, item.dn_detail, item.delivery_note, - item.qty, item.base_rate, item.base_amount, item.name as "item_row", + item.qty, item.base_net_rate, item.base_net_amount, item.name as "item_row", sales.sales_person, sales.sales_designation, sales.allocated_amount, sales.incentives from `tabSales Invoice` si diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py index 27f1249b2e..4a8427e341 100644 --- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py +++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py @@ -28,13 +28,13 @@ def execute(filters=None): expense_account = d.expense_account or aii_account_map.get(d.company) row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.supplier, d.supplier_name, d.credit_to, d.project_name, d.company, d.purchase_order, - purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount] + purchase_receipt, expense_account, d.qty, d.base_net_rate, d.base_net_amount] for tax in tax_accounts: row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0)) total_tax = sum(row[last_col:]) - row += [total_tax, d.base_amount + total_tax] + row += [total_tax, d.base_net_amount + total_tax] data.append(row) @@ -70,7 +70,7 @@ def get_items(filters): return frappe.db.sql("""select pi_item.parent, pi.posting_date, pi.credit_to, pi.company, pi.supplier, pi.remarks, pi.base_net_total, pi_item.item_code, pi_item.item_name, pi_item.item_group, pi_item.project_name, pi_item.purchase_order, pi_item.purchase_receipt, pi_item.po_detail - pi_item.expense_account, pi_item.qty, pi_item.base_rate, pi_item.base_amount, pi.supplier_name + pi_item.expense_account, pi_item.qty, pi_item.base_net_rate, pi_item.base_net_amount, pi.supplier_name from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item where pi.name = pi_item.parent and pi.docstatus = 1 %s %s order by pi.posting_date desc, pi_item.item_code desc""" % (conditions, match_conditions), filters, as_dict=1) @@ -86,7 +86,7 @@ def get_tax_accounts(item_list, columns): for d in item_list: invoice_wise_items.setdefault(d.parent, []).append(d) - tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount + tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, base_tax_amount_after_discount_amount from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice' and docstatus = 1 and ifnull(account_head, '') != '' and category in ('Total', 'Valuation and Total') and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), tuple(invoice_wise_items.keys())) @@ -107,7 +107,7 @@ def get_tax_accounts(item_list, columns): elif charge_type == "Actual" and tax_amount: for d in invoice_wise_items.get(parent, []): item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \ - (tax_amount * d.base_amount) / d.base_net_total + (tax_amount * d.base_net_amount) / d.base_net_total tax_accounts.sort() columns += [account_head + ":Currency:80" for account_head in tax_accounts] 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 fef397f924..524773e396 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 @@ -26,13 +26,13 @@ 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.territory, d.project_name, d.company, d.sales_order, - delivery_note, d.income_account, d.qty, d.base_rate, d.base_amount] + delivery_note, d.income_account, d.qty, d.base_net_rate, d.base_net_amount] for tax in tax_accounts: row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0)) total_tax = sum(row[last_col:]) - row += [total_tax, d.base_amount + total_tax] + row += [total_tax, d.base_net_amount + total_tax] data.append(row) @@ -69,7 +69,7 @@ def get_items(filters): return frappe.db.sql("""select si_item.parent, si.posting_date, si.debit_to, si.project_name, 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_item.base_rate, si_item.base_amount, si.customer_name, + si_item.qty, si_item.base_net_rate, si_item.base_net_amount, si.customer_name, si.customer_group, si_item.so_detail from `tabSales Invoice` si, `tabSales Invoice Item` si_item where si.name = si_item.parent and si.docstatus = 1 %s @@ -83,7 +83,8 @@ def get_tax_accounts(item_list, columns): for d in item_list: invoice_wise_items.setdefault(d.parent, []).append(d) - tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount + tax_details = frappe.db.sql("""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 and ifnull(account_head, '') != '' and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), @@ -104,7 +105,7 @@ def get_tax_accounts(item_list, columns): elif charge_type == "Actual" and tax_amount: for d in invoice_wise_items.get(parent, []): item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \ - flt((tax_amount * d.base_amount) / d.base_net_total) + flt((tax_amount * d.base_net_amount) / d.base_net_total) tax_accounts.sort() columns += [account_head + ":Currency:80" for account_head in tax_accounts] diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py index 724b6781f9..1e9273321b 100644 --- a/erpnext/accounts/report/purchase_register/purchase_register.py +++ b/erpnext/accounts/report/purchase_register/purchase_register.py @@ -114,7 +114,7 @@ def get_invoices(filters): def get_invoice_expense_map(invoice_list): - expense_details = frappe.db.sql("""select parent, expense_account, sum(base_amount) as amount + expense_details = frappe.db.sql("""select parent, expense_account, sum(base_net_amount) as amount from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_account""" % ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) @@ -126,7 +126,7 @@ def get_invoice_expense_map(invoice_list): return invoice_expense_map def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts): - tax_details = frappe.db.sql("""select parent, account_head, sum(tax_amount) as tax_amount + tax_details = frappe.db.sql("""select parent, account_head, sum(base_tax_amount_after_discount_amount) as tax_amount from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" % ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py index 3bd82b690c..5fa03f75a8 100644 --- a/erpnext/accounts/report/sales_register/sales_register.py +++ b/erpnext/accounts/report/sales_register/sales_register.py @@ -78,7 +78,7 @@ def get_columns(invoice_list): tax_accounts = frappe.db.sql_list("""select distinct account_head from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice' - and docstatus = 1 and ifnull(tax_amount_after_discount_amount, 0) != 0 + and docstatus = 1 and ifnull(base_tax_amount_after_discount_amount, 0) != 0 and parent in (%s) order by account_head""" % ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list])) @@ -113,7 +113,7 @@ def get_invoices(filters): conditions, filters, as_dict=1) def get_invoice_income_map(invoice_list): - income_details = frappe.db.sql("""select parent, income_account, sum(base_amount) as amount + income_details = frappe.db.sql("""select parent, income_account, sum(base_net_amount) as amount from `tabSales Invoice Item` where parent in (%s) group by parent, income_account""" % ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) @@ -126,7 +126,7 @@ def get_invoice_income_map(invoice_list): def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts): tax_details = frappe.db.sql("""select parent, account_head, - sum(tax_amount_after_discount_amount) as tax_amount + sum(base_tax_amount_after_discount_amount) as tax_amount from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" % ', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1) diff --git a/erpnext/buying/page/purchase_analytics/purchase_analytics.js b/erpnext/buying/page/purchase_analytics/purchase_analytics.js index 470e44c15c..6afad76705 100644 --- a/erpnext/buying/page/purchase_analytics/purchase_analytics.js +++ b/erpnext/buying/page/purchase_analytics/purchase_analytics.js @@ -209,7 +209,7 @@ erpnext.PurchaseAnalytics = frappe.views.TreeGridReport.extend({ if (posting_date >= from_date && posting_date <= to_date) { var item = me.item_by_name[tl[me.tree_grid.item_key]] || me.item_by_name['Not Set']; - item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty); + item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty); } } }); diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 4e4e507cae..7d01f81fef 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -94,16 +94,16 @@ class BuyingController(StockController): for d in self.get(parentfield): if d.item_code and d.item_code in stock_items: stock_items_qty += flt(d.qty) - stock_items_amount += flt(d.base_amount) + stock_items_amount += flt(d.base_net_amount) last_stock_item_idx = d.idx - total_valuation_amount = sum([flt(d.tax_amount) for d in self.get("taxes") + total_valuation_amount = sum([flt(d.base_tax_amount_after_discount_amount) for d in self.get("taxes") if d.category in ["Valuation", "Valuation and Total"]]) valuation_amount_adjustment = total_valuation_amount for i, item in enumerate(self.get(parentfield)): if item.item_code and item.qty and item.item_code in stock_items: - item_proportion = flt(item.base_amount) / stock_items_amount if stock_items_amount \ + item_proportion = flt(item.base_net_amount) / stock_items_amount if stock_items_amount \ else flt(item.qty) / stock_items_qty if i == (last_stock_item_idx - 1): @@ -124,7 +124,7 @@ class BuyingController(StockController): landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \ if self.doctype == "Purchase Receipt" else 0.0 - item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost + item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost + landed_cost_voucher_amount) / qty_in_stock_uom) else: item.valuation_rate = 0.0 diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py index c2d5e0090c..dc7039ed60 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -132,9 +132,9 @@ def period_wise_columns_query(filters, trans): else: pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120", _(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"] - query_details = " SUM(t2.qty), SUM(t2.base_amount)," + query_details = " SUM(t2.qty), SUM(t2.base_net_amount)," - query_details += 'SUM(t2.qty), SUM(t2.base_amount)' + query_details += 'SUM(t2.qty), SUM(t2.base_net_amount)' return pwc, query_details def get_period_wise_columns(bet_dates, period, pwc): @@ -147,7 +147,7 @@ def get_period_wise_columns(bet_dates, period, pwc): def get_period_wise_query(bet_dates, trans_date, query_details): query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)), - SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_amount, NULL)), + SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_net_amount, NULL)), """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} return query_details diff --git a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py index 538b7edd45..9146e42cf1 100644 --- a/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py +++ b/erpnext/projects/report/project_wise_stock_tracking/project_wise_stock_tracking.py @@ -13,19 +13,19 @@ def execute(filters=None): data = [] for project in proj_details: - data.append([project.name, pr_item_map.get(project.name, 0), - se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0), - project.project_name, project.status, project.company, - project.customer, project.project_value, project.project_start_date, + data.append([project.name, pr_item_map.get(project.name, 0), + se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0), + project.project_name, project.status, project.company, + project.customer, project.project_value, project.project_start_date, project.completion_date]) - return columns, data + return columns, data def get_columns(): return [_("Project Id") + ":Link/Project:140", _("Cost of Purchased Items") + ":Currency:160", - _("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160", - _("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100", - _("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120", + _("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160", + _("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100", + _("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120", _("Project Start Date") + ":Date:120", _("Completion Date") + ":Date:120"] def get_project_details(): @@ -33,8 +33,8 @@ def get_project_details(): project_start_date, completion_date from tabProject where docstatus < 2""", as_dict=1) def get_purchased_items_cost(): - pr_items = frappe.db.sql("""select project_name, sum(base_amount) as amount - from `tabPurchase Receipt Item` where ifnull(project_name, '') != '' + pr_items = frappe.db.sql("""select project_name, sum(base_net_amount) as amount + from `tabPurchase Receipt Item` where ifnull(project_name, '') != '' and docstatus = 1 group by project_name""", as_dict=1) pr_item_map = {} @@ -46,7 +46,7 @@ def get_purchased_items_cost(): def get_issued_items_cost(): se_items = frappe.db.sql("""select se.project_name, sum(se_item.amount) as amount from `tabStock Entry` se, `tabStock Entry Detail` se_item - where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = '' + where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = '' and ifnull(se.project_name, '') != '' group by se.project_name""", as_dict=1) se_item_map = {} @@ -56,14 +56,14 @@ def get_issued_items_cost(): return se_item_map def get_delivered_items_cost(): - dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_amount) as amount + dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_net_amount) as amount from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item where dn.name = dn_item.parent and dn.docstatus = 1 and ifnull(dn.project_name, '') != '' group by dn.project_name""", as_dict=1) - si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_amount) as amount + si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_net_amount) as amount from `tabSales Invoice` si, `tabSales Invoice Item` si_item - where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1 + where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1 and ifnull(si.is_pos, 0) = 1 and ifnull(si.project_name, '') != '' group by si.project_name""", as_dict=1) @@ -75,4 +75,4 @@ def get_delivered_items_cost(): for item in si_items: dn_item_map.setdefault(item.project_name, item.amount) - return dn_item_map \ No newline at end of file + return dn_item_map diff --git a/erpnext/public/js/feature_setup.js b/erpnext/public/js/feature_setup.js index bb831703c6..259c2cf315 100644 --- a/erpnext/public/js/feature_setup.js +++ b/erpnext/public/js/feature_setup.js @@ -111,34 +111,54 @@ erpnext.feature_setup.feature_dict = { 'Sales Order': {'items':['page_break']} }, 'fs_exports': { - 'Delivery Note': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, + 'Delivery Note': { + 'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total', + 'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] + }, 'POS Setting': {'fields':['conversion_rate','currency']}, - 'Quotation': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, - 'Sales Invoice': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}, + 'Quotation': { + 'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total', + 'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] + }, + 'Sales Invoice': { + 'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total', + 'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] + }, 'Sales BOM': {'fields':['currency']}, - 'Sales Order': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']} + 'Sales Order': { + 'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total', + 'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] + } }, 'fs_imports': { 'Purchase Invoice': { - 'fields': ['conversion_rate', 'currency', 'base_grand_total', - 'base_in_words', 'base_net_total', 'base_taxes_and_charges_added', - 'base_taxes_and_charges_deducted'], - 'items': ['base_price_list_rate', 'base_amount','base_rate'] + 'fields': ['conversion_rate', 'currency', 'base_grand_total', 'base_discount_amount', + 'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added', + 'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount'] }, 'Purchase Order': { - 'fields': ['conversion_rate','currency', 'base_grand_total', - 'base_in_words', 'base_net_total', 'base_taxes_and_charges_added', - 'base_taxes_and_charges_deducted'], - 'items': ['base_price_list_rate', 'base_amount','base_rate'] + 'fields': ['conversion_rate','currency', 'base_grand_total', 'base_discount_amount', + 'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added', + 'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'], + 'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount'] }, 'Purchase Receipt': { - 'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', - 'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted'], - 'items': ['base_price_list_rate','base_amount','base_rate'] + 'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total', + 'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted', + 'base_total_taxes_and_charges', 'base_discount_amount'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] }, 'Supplier Quotation': { - 'fields':['conversion_rate','currency'] + 'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total', + 'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted', + 'base_total_taxes_and_charges', 'base_discount_amount'], + 'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount'] } }, diff --git a/erpnext/selling/page/sales_analytics/sales_analytics.js b/erpnext/selling/page/sales_analytics/sales_analytics.js index bbe69d7c3e..197b6aca42 100644 --- a/erpnext/selling/page/sales_analytics/sales_analytics.js +++ b/erpnext/selling/page/sales_analytics/sales_analytics.js @@ -204,7 +204,7 @@ erpnext.SalesAnalytics = frappe.views.TreeGridReport.extend({ if (posting_date >= from_date && posting_date <= to_date) { var item = me.item_by_name[tl[me.tree_grid.item_key]] || me.item_by_name['Not Set']; - item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty); + item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty); } } }); diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py index 7471317b97..93dd74c460 100644 --- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py +++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py @@ -82,7 +82,7 @@ def get_target_distribution_details(filters): def get_achieved_details(filters): start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] - item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date, + item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date, st.sales_person, MONTHNAME(so.transaction_date) as month_name from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st where soi.parent=so.name and so.docstatus=1 and @@ -125,7 +125,7 @@ def get_salesperson_item_month_map(filters): if (filters["target_on"] == "Amount"): tav_dict.target = flt(sd.target_amount) * month_percentage / 100 if ad.month_name == month: - tav_dict.achieved += ad.base_amount + tav_dict.achieved += ad.base_net_amount return sim_map diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py index c970431bec..8cac80c14c 100644 --- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py +++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py @@ -16,7 +16,7 @@ def execute(filters=None): data.append([ d.name, d.customer, d.territory, d.posting_date, d.item_code, item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"), - d.qty, d.base_amount, d.sales_person, d.allocated_percentage, d.contribution_amt + d.qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt ]) return columns, data @@ -36,8 +36,8 @@ def get_entries(filters): date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date" conditions, items = get_conditions(filters, date_field) entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date, - dt_item.item_code, dt_item.qty, dt_item.base_amount, st.sales_person, - st.allocated_percentage, dt_item.base_amount*st.allocated_percentage/100 as contribution_amt + dt_item.item_code, dt_item.qty, dt_item.base_net_amount, st.sales_person, + st.allocated_percentage, dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt from `tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" % diff --git a/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py b/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py index 6c3a2c30f1..4f19c73147 100644 --- a/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py +++ b/erpnext/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe import _, msgprint from frappe.utils import flt -import time from erpnext.accounts.utils import get_fiscal_year from erpnext.controllers.trends import get_period_date_ranges, get_period_month_ranges @@ -81,7 +80,7 @@ def get_target_distribution_details(filters): def get_achieved_details(filters): start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:] - item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date, + item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date, so.territory, MONTHNAME(so.transaction_date) as month_name from `tabSales Order Item` soi, `tabSales Order` so where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and @@ -125,7 +124,7 @@ def get_territory_item_month_map(filters): if (filters["target_on"] == "Amount"): tav_dict.target = flt(td.target_amount) * month_percentage / 100 if ad.month_name == month: - tav_dict.achieved += ad.base_amount + tav_dict.achieved += ad.base_net_amount return tim_map diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 7b836166c5..754eccbe44 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -141,7 +141,7 @@ def decorate_quotation_doc(quotation_doc): d["formatted_amount"] = fmt_money(d.get("amount"), currency=doc.currency) for d in doc.get("taxes", []): - d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount")) / doc.conversion_rate, + d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount_after_discount_amount")), currency=doc.currency) doc.formatted_grand_total_export = fmt_money(doc.grand_total, diff --git a/erpnext/startup/report_data_map.py b/erpnext/startup/report_data_map.py index b864cbc9e7..4bd0afe8f8 100644 --- a/erpnext/startup/report_data_map.py +++ b/erpnext/startup/report_data_map.py @@ -174,7 +174,7 @@ data_map = { } }, "Sales Invoice Item": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { @@ -192,7 +192,7 @@ data_map = { } }, "Sales Order Item[Sales Analytics]": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { @@ -210,7 +210,7 @@ data_map = { } }, "Delivery Note Item[Sales Analytics]": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { @@ -242,7 +242,7 @@ data_map = { } }, "Purchase Invoice Item": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { @@ -260,7 +260,7 @@ data_map = { } }, "Purchase Order Item[Purchase Analytics]": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { @@ -278,7 +278,7 @@ data_map = { } }, "Purchase Receipt Item[Purchase Analytics]": { - "columns": ["name", "parent", "item_code", "qty", "base_amount"], + "columns": ["name", "parent", "item_code", "qty", "base_net_amount"], "conditions": ["docstatus=1", "ifnull(parent, '')!=''"], "order_by": "parent", "links": { diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 9395e84fcf..2785cc13a2 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -295,7 +295,7 @@ class PurchaseReceipt(BuyingController): "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor), - self.precision("base_amount", d)) + self.precision("base_net_amount", d)) })) # stock received but not billed @@ -304,7 +304,7 @@ class PurchaseReceipt(BuyingController): "against": warehouse_account[d.warehouse], "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": flt(d.base_amount, self.precision("base_amount", d)) + "credit": flt(d.base_net_amount, self.precision("base_net_amount", d)) })) negative_expense_to_be_booked += flt(d.item_tax_amount) @@ -332,12 +332,12 @@ class PurchaseReceipt(BuyingController): # divisional loss adjustment if not self.get("other_charges"): sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor), - self.precision("base_amount", d)) + self.precision("base_net_amount", d)) - distributed_amount = flt(flt(d.base_amount, self.precision("base_amount", d))) + \ + distributed_amount = flt(flt(d.base_net_amount, self.precision("base_net_amount", d))) + \ flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost) - divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_amount", d)) + divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_net_amount", d)) if divisional_loss: gl_entries.append(self.get_gl_dict({ "account": stock_rbnb, @@ -354,12 +354,12 @@ class PurchaseReceipt(BuyingController): # Cost center-wise amount breakup for other charges included for valuation valuation_tax = {} for tax in self.get("taxes"): - if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount): + if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount): if not tax.cost_center: frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category))) valuation_tax.setdefault(tax.cost_center, 0) valuation_tax[tax.cost_center] += \ - (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount) + (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount) if negative_expense_to_be_booked and valuation_tax: # Backward compatibility: diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index d7ace2fe1d..44f60d7836 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -170,6 +170,8 @@ def get_basic_details(args, item): "base_rate": 0.0, "amount": 0.0, "base_amount": 0.0, + "net_rate": 0.0, + "net_amount": 0.0, "discount_percentage": 0.0 })