From 47e14a9de44348c9a5cf5c441e12c857af58b746 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 13 Aug 2013 13:01:12 +0530 Subject: [PATCH] [fix] [minor] rate calculation on server side, only if blank/0 (honour client side calculation sequence), shopping cart settings --- accounts/doctype/sales_invoice/test_sales_invoice.py | 2 -- controllers/buying_controller.py | 2 +- controllers/selling_controller.py | 2 +- stock/doctype/delivery_note/test_delivery_note.py | 2 +- utilities/transaction_base.py | 4 ++-- .../shopping_cart_settings/shopping_cart_settings.py | 8 ++++---- .../shopping_cart_settings/test_shopping_cart_settings.py | 6 +++--- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py index 05e4d92fa7..cdd61b9d81 100644 --- a/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -916,7 +916,6 @@ test_records = [ "item_name": "_Test Item Home Desktop 100", "qty": 10, "ref_rate": 62.5, - "export_rate": 62.5, "stock_uom": "_Test UOM", "item_tax_rate": json.dumps({"_Test Account Excise Duty - _TC": 10}), "income_account": "Sales - _TC", @@ -930,7 +929,6 @@ test_records = [ "item_name": "_Test Item Home Desktop 200", "qty": 5, "ref_rate": 190.66, - "export_rate": 190.66, "stock_uom": "_Test UOM", "income_account": "Sales - _TC", "cost_center": "_Test Cost Center - _TC", diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 63070a58a7..938db8c993 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -98,7 +98,7 @@ class BuyingController(StockController): if item.discount_rate == 100.0: item.import_rate = 0.0 - elif item.import_ref_rate: + elif not item.import_rate: item.import_rate = flt(item.import_ref_rate * (1.0 - (item.discount_rate / 100.0)), self.precision("import_rate", item)) diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index 033ac83db8..fb762affed 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -191,7 +191,7 @@ class SellingController(StockController): if item.adj_rate == 100: item.export_rate = 0 - elif item.ref_rate: + elif not item.export_rate: item.export_rate = flt(item.ref_rate * (1.0 - (item.adj_rate / 100.0)), self.precision("export_rate", item)) diff --git a/stock/doctype/delivery_note/test_delivery_note.py b/stock/doctype/delivery_note/test_delivery_note.py index 2e3ab07688..c1f09dd517 100644 --- a/stock/doctype/delivery_note/test_delivery_note.py +++ b/stock/doctype/delivery_note/test_delivery_note.py @@ -33,7 +33,7 @@ class TestDeliveryNote(unittest.TestCase): self.assertEquals(len(si), len(dn.doclist)) # modify export_amount - si[1].ref_rate = 200 + si[1].export_rate = 200 self.assertRaises(webnotes.ValidationError, webnotes.bean(si).insert) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 47e35f1b8d..d2bffcfeac 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -77,9 +77,9 @@ class TransactionBase(StatusUpdater): """ customer_defaults = self.get_customer_defaults() - customer_defaults["price_list_name"] = customer_defaults.get("price_list") or \ + customer_defaults["selling_price_list"] = customer_defaults.get("price_list") or \ webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \ - self.doc.price_list + self.doc.selling_price_list for fieldname, val in customer_defaults.items(): if self.meta.get_field(fieldname): diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.py b/website/doctype/shopping_cart_settings/shopping_cart_settings.py index f06c1f7291..74cc217d28 100644 --- a/website/doctype/shopping_cart_settings/shopping_cart_settings.py +++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.py @@ -43,7 +43,7 @@ class DocType(DocListController): def validate_price_lists(self): territory_name_map = self.validate_overlapping_territories("price_lists", - "price_list") + "selling_price_list") # validate that a Shopping Cart Price List exists for the root territory # as a catch all! @@ -92,9 +92,9 @@ class DocType(DocListController): raise_exception=ShoppingCartSetupError) price_list_currency_map = webnotes.conn.get_values("Price List", - [d.price_list for d in self.doclist.get({"parentfield": "price_lists"})], + [d.selling_price_list for d in self.doclist.get({"parentfield": "price_lists"})], "currency") - + expected_to_exist = [currency + "-" + company_currency for currency in price_list_currency_map.values() if currency != company_currency] @@ -126,7 +126,7 @@ class DocType(DocListController): return name def get_price_list(self, billing_territory): - price_list = self.get_name_from_territory(billing_territory, "price_lists", "price_list") + price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list") return price_list and price_list[0] or None def get_tax_master(self, billing_territory): diff --git a/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py b/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py index cbba566d7a..3417cec13a 100644 --- a/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py +++ b/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py @@ -26,7 +26,7 @@ class TestShoppingCartSettings(unittest.TestCase): cart_settings.doclist.append({ "doctype": "Shopping Cart Price List", "parentfield": "price_lists", - "price_list": price_list + "selling_price_list": price_list }) for price_list in ("_Test Price List Rest of the World", "_Test Price List India", @@ -34,13 +34,13 @@ class TestShoppingCartSettings(unittest.TestCase): _add_price_list(price_list) controller = cart_settings.make_controller() - controller.validate_overlapping_territories("price_lists", "price_list") + controller.validate_overlapping_territories("price_lists", "selling_price_list") _add_price_list("_Test Price List 2") controller = cart_settings.make_controller() self.assertRaises(ShoppingCartSetupError, controller.validate_overlapping_territories, - "price_lists", "price_list") + "price_lists", "selling_price_list") return cart_settings