From e9d1cbb3392494c141041efc40e5c33e004c4249 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 30 Jul 2021 12:36:35 +0530 Subject: [PATCH 1/2] fix: COGS account in purchase receipt (cherry picked from commit 2a14f255cfa8d85815cc22d0bcae76d7e4de8634) # Conflicts: # erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py --- .../doctype/pricing_rule/test_pricing_rule.py | 10 ++++++ erpnext/accounts/utils.py | 6 ++-- erpnext/controllers/accounts_controller.py | 4 +-- .../purchase_receipt/purchase_receipt.py | 2 +- .../purchase_receipt/test_purchase_receipt.py | 35 +++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index e2b23704c884..2e2d425dab74 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -19,6 +19,7 @@ class TestPricingRule(unittest.TestCase): def setUp(self): delete_existing_pricing_rules() + setup_pricing_rule_data() def tearDown(self): delete_existing_pricing_rules() @@ -561,6 +562,8 @@ def test_pricing_rule_for_transaction(self): for doc in [si, si1]: doc.delete() +test_dependencies = ["Campaign"] + def make_pricing_rule(**args): args = frappe._dict(args) @@ -607,6 +610,13 @@ def make_pricing_rule(**args): if args.get(applicable_for): doc.db_set(applicable_for, args.get(applicable_for)) +def setup_pricing_rule_data(): + if not frappe.db.exists('Campaign', '_Test Campaign'): + frappe.get_doc({ + 'doctype': 'Campaign', + 'campaign_name': '_Test Campaign', + 'name': '_Test Campaign' + }).insert() def delete_existing_pricing_rules(): for doctype in ["Pricing Rule", "Pricing Rule Item Code", diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index b425062dc6f3..55ce70488d58 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -579,10 +579,10 @@ def remove_ref_doc_link_from_pe(ref_type, ref_no): frappe.msgprint(_("Payment Entries {0} are un-linked").format("\n".join(linked_pe))) @frappe.whitelist() -def get_company_default(company, fieldname): - value = frappe.get_cached_value('Company', company, fieldname) +def get_company_default(company, fieldname, ignore_validation=False): + value = frappe.get_cached_value('Company', company, fieldname) - if not value: + if not ignore_validation and not value: throw(_("Please set default {0} in Company {1}") .format(frappe.get_meta("Company").get_label(fieldname), company)) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 45574a6ba19b..f2340795a1b6 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1075,9 +1075,9 @@ def throw_overbill_exception(self, item, max_allowed_amt): frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") .format(item.item_code, item.idx, max_allowed_amt)) - def get_company_default(self, fieldname): + def get_company_default(self, fieldname, ignore_validation=False): from erpnext.accounts.utils import get_company_default - return get_company_default(self.company, fieldname) + return get_company_default(self.company, fieldname, ignore_validation=ignore_validation) def get_stock_items(self): stock_items = [] diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index cd8b1bf48a07..233ea1f70456 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -362,7 +362,7 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None): if self.is_return or flt(d.item_tax_amount): loss_account = expenses_included_in_valuation else: - loss_account = self.get_company_default("default_expense_account") + loss_account = self.get_company_default("default_expense_account", ignore_validation=True) or stock_rbnb cost_center = d.cost_center or frappe.get_cached_value("Company", self.company, "cost_center") diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 53e0e488f9e3..b67ab2c50003 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -332,7 +332,25 @@ def test_subcontracting_over_receipt(self): pr1.submit() self.assertRaises(frappe.ValidationError, pr2.submit) +<<<<<<< HEAD frappe.db.rollback() +======= + + pr1.cancel() + se.cancel() + se1.cancel() + se2.cancel() + se3.cancel() + po.reload() + pr2.load_from_db() + + if pr2.docstatus == 1 and frappe.db.get_value('Stock Ledger Entry', + {'voucher_no': pr2.name, 'is_cancelled': 0}, 'name'): + pr2.cancel() + + po.load_from_db() + po.cancel() +>>>>>>> 2a14f255cf (fix: COGS account in purchase receipt) def test_serial_no_supplier(self): pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1) @@ -1055,6 +1073,7 @@ def test_service_item_purchase_with_perpetual_inventory(self): frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value) +<<<<<<< HEAD def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1070,6 +1089,22 @@ def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): ) automatically_fetch_payment_terms() +======= + def test_purchase_receipt_with_exchange_rate_difference(self): + from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice + from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt + + pi = create_purchase_invoice(company="_Test Company with perpetual inventory", + cost_center = "Main - TCP1", + warehouse = "Stores - TCP1", + expense_account ="_Test Account Cost for Goods Sold - TCP1", + currency = "USD", conversion_rate = 70) + + pr = create_purchase_receipt(pi.name) + pr.conversion_rate = 80 + pr.items[0].purchase_invoice = pi.name + pr.items[0].purchase_invoice_item = pi.items[0].name +>>>>>>> 2a14f255cf (fix: COGS account in purchase receipt) po = create_purchase_order(qty=10, rate=100, do_not_save=1) create_payment_terms_template() From bb7d661a04616c011332d0f142316a29a84e4757 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 1 Nov 2021 16:23:39 +0530 Subject: [PATCH 2/2] fix: Resolve conflicts --- .../purchase_receipt/test_purchase_receipt.py | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index b67ab2c50003..f06c12359da3 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -332,9 +332,6 @@ def test_subcontracting_over_receipt(self): pr1.submit() self.assertRaises(frappe.ValidationError, pr2.submit) -<<<<<<< HEAD - frappe.db.rollback() -======= pr1.cancel() se.cancel() @@ -350,7 +347,6 @@ def test_subcontracting_over_receipt(self): po.load_from_db() po.cancel() ->>>>>>> 2a14f255cf (fix: COGS account in purchase receipt) def test_serial_no_supplier(self): pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1) @@ -1073,7 +1069,6 @@ def test_service_item_purchase_with_perpetual_inventory(self): frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value) -<<<<<<< HEAD def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( create_payment_terms_template, @@ -1089,22 +1084,6 @@ def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): ) automatically_fetch_payment_terms() -======= - def test_purchase_receipt_with_exchange_rate_difference(self): - from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice - from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt - - pi = create_purchase_invoice(company="_Test Company with perpetual inventory", - cost_center = "Main - TCP1", - warehouse = "Stores - TCP1", - expense_account ="_Test Account Cost for Goods Sold - TCP1", - currency = "USD", conversion_rate = 70) - - pr = create_purchase_receipt(pi.name) - pr.conversion_rate = 80 - pr.items[0].purchase_invoice = pi.name - pr.items[0].purchase_invoice_item = pi.items[0].name ->>>>>>> 2a14f255cf (fix: COGS account in purchase receipt) po = create_purchase_order(qty=10, rate=100, do_not_save=1) create_payment_terms_template()