From a1ffacaf0bb3e9b76f22e96708d69f9c14ea6c42 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 2 Jan 2014 16:30:16 +0530 Subject: [PATCH 1/2] Valuation related charges should only go to stock items --- controllers/accounts_controller.py | 3 --- controllers/buying_controller.py | 38 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index 5388ee120a..11480c9ebe 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -231,9 +231,6 @@ class AccountsController(TransactionBase): # tax_amount represents the amount of tax for the current step current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map) - if hasattr(self, "set_item_tax_amount"): - self.set_item_tax_amount(item, tax, current_tax_amount) - # case when net total is 0 but there is an actual type charge # in this case add the actual amount to tax.tax_amount # and tax.grand_total_for_current_item for the first such iteration diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 35b9d25279..4aa08d6c55 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -163,30 +163,36 @@ class BuyingController(StockController): if not self.meta.get_field("item_tax_amount", parentfield=self.fname): for item in self.item_doclist: del item.fields["item_tax_amount"] - - def set_item_tax_amount(self, item, tax, current_tax_amount): + + # update valuation rate + def update_valuation_rate(self, parentfield): """ item_tax_amount is the total tax amount applied on that item stored for valuation TODO: rename item_tax_amount to valuation_tax_amount """ - if tax.category in ["Valuation", "Valuation and Total"] and \ - self.meta.get_field("item_tax_amount", parentfield=self.fname): - item.item_tax_amount += flt(current_tax_amount, self.precision("item_tax_amount", item)) - - # update valuation rate - def update_valuation_rate(self, parentfield): - for item in self.doclist.get({"parentfield": parentfield}): - item.conversion_factor = item.conversion_factor or flt(webnotes.conn.get_value( - "UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom}, - "conversion_factor")) or 1 + stock_items = self.get_stock_items() + + stock_items_amount = sum([flt(d.amount) for d in + self.doclist.get({"parentfield": parentfield}) + if d.item_code and d.item_code in stock_items]) - if item.item_code and item.qty: + total_valuation_amount = sum([flt(d.tax_amount) for d in + self.doclist.get({"parentfield": "purchase_tax_details"}) + if d.category in ["Valuation", "Valuation and Total"]]) + + + for item in self.doclist.get({"parentfield": parentfield}): + if item.item_code and item.qty and item.item_code in stock_items: + item.item_tax_amount = flt(flt(item.amount) * total_valuation_amount \ + / stock_items_amount, self.precision("item_tax_amount", item)) + self.round_floats_in(item) - - # if no item code, which is sometimes the case in purchase invoice, - # then it is not possible to track valuation against it + + item.conversion_factor = item.conversion_factor or flt(webnotes.conn.get_value( + "UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom}, + "conversion_factor")) or 1 qty_in_stock_uom = flt(item.qty * item.conversion_factor) item.valuation_rate = ((item.amount + item.item_tax_amount + item.rm_supp_cost) / qty_in_stock_uom) From df07c964f74e5527d2ab1a0aaffb2cdd96807619 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 2 Jan 2014 17:42:01 +0600 Subject: [PATCH 2/2] bumped to version 3.4.4 --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index c09c2afac9..e8955b178c 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "app_name": "ERPNext", - "app_version": "3.4.3", + "app_version": "3.4.4", "base_template": "app/portal/templates/base.html", "modules": { "Accounts": { @@ -74,5 +74,5 @@ "type": "module" } }, - "requires_framework_version": "==3.4.2" + "requires_framework_version": "==3.4.3" } \ No newline at end of file