From 3a67daa1fd89e422f6a4ebc5d3a46278d025d290 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 21 Jan 2020 19:22:27 +0530 Subject: [PATCH 1/3] fix: Zero division error while making finished good entry against the work order --- erpnext/stock/doctype/stock_entry/stock_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index ac3203bacd2..3f62d185cba 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -484,7 +484,7 @@ class StockEntry(StockController): if self.work_order \ and frappe.db.get_single_value("Manufacturing Settings", "material_consumption"): bom_items = self.get_bom_raw_materials(d.transfer_qty) - raw_material_cost = sum([flt(d.qty)*flt(d.rate) for d in bom_items.values()]) + raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()]) if raw_material_cost: d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate")) From 02f4aa6db6b73c5a5c62a92e8f1f65c908c831c1 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 3 Feb 2020 18:54:35 +0530 Subject: [PATCH 2/3] fix: Unable to submit landed cost voucher (#20494) * fix: Unable to submit landed cost voucher * fix: Test case for multiple landed cost voucher against a Purchase receipt * fix: Test Case --- .../test_landed_cost_voucher.py | 70 +++++++++++++++++++ .../purchase_receipt/purchase_receipt.py | 17 ++--- 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 988cf52ed05..62d369cb9d9 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -162,6 +162,76 @@ class TestLandedCostVoucher(unittest.TestCase): self.assertEqual(lcv.items[0].applicable_charges, 41.07) self.assertEqual(lcv.items[2].applicable_charges, 41.08) + def test_multiple_landed_cost_voucher_against_pr(self): + pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", + supplier_warehouse = "Stores - TCP1", do_not_save=True) + + pr.append("items", { + "item_code": "_Test Item", + "warehouse": "Stores - TCP1", + "cost_center": "Main - TCP1", + "qty": 5, + "rate": 100 + }) + + pr.submit() + + lcv1 = make_landed_cost_voucher(receipt_document_type = 'Purchase Receipt', + receipt_document=pr.name, charges=100, do_not_save=True) + + lcv1.insert() + lcv1.set('items', [ + lcv1.get('items')[0] + ]) + distribute_landed_cost_on_items(lcv1) + + lcv1.submit() + + lcv2 = make_landed_cost_voucher(receipt_document_type = 'Purchase Receipt', + receipt_document=pr.name, charges=100, do_not_save=True) + + lcv2.insert() + lcv2.set('items', [ + lcv2.get('items')[1] + ]) + distribute_landed_cost_on_items(lcv2) + + lcv2.submit() + + pr.load_from_db() + + self.assertEqual(pr.items[0].landed_cost_voucher_amount, 100) + self.assertEqual(pr.items[1].landed_cost_voucher_amount, 100) + +def make_landed_cost_voucher(** args): + args = frappe._dict(args) + ref_doc = frappe.get_doc(args.receipt_document_type, args.receipt_document) + + lcv = frappe.new_doc('Landed Cost Voucher') + lcv.company = '_Test Company' + lcv.distribute_charges_based_on = 'Amount' + + lcv.set('purchase_receipts', [{ + "receipt_document_type": args.receipt_document_type, + "receipt_document": args.receipt_document, + "supplier": ref_doc.supplier, + "posting_date": ref_doc.posting_date, + "grand_total": ref_doc.grand_total + }]) + + lcv.set("taxes", [{ + "description": "Shipping Charges", + "expense_account": "Expenses Included In Valuation - TCP1", + "amount": args.charges + }]) + + if not args.do_not_save: + lcv.insert() + if not args.do_not_submit: + lcv.submit() + + return lcv + def submit_landed_cost_voucher(receipt_document_type, receipt_document, charges=50): ref_doc = frappe.get_doc(receipt_document_type, receipt_document) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 691f92ffa72..3ec4b84ccee 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -348,7 +348,7 @@ class PurchaseReceipt(BuyingController): if warehouse_with_no_account: frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" + "\n".join(warehouse_with_no_account)) - + return process_gl_map(gl_entries) def get_asset_gl_entry(self, gl_entries): @@ -615,23 +615,16 @@ def get_item_account_wise_additional_cost(purchase_document): if not landed_cost_vouchers: return - - total_item_cost = 0 + item_account_wise_cost = {} - item_cost_allocated = [] for lcv in landed_cost_vouchers: - landed_cost_voucher_doc = frappe.get_cached_doc("Landed Cost Voucher", lcv.parent) + landed_cost_voucher_doc = frappe.get_doc("Landed Cost Voucher", lcv.parent) based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on) + total_item_cost = 0 for item in landed_cost_voucher_doc.items: - if item.purchase_receipt_item not in item_cost_allocated: - total_item_cost += item.get(based_on_field) - item_cost_allocated.append(item.purchase_receipt_item) - - for lcv in landed_cost_vouchers: - landed_cost_voucher_doc = frappe.get_cached_doc("Landed Cost Voucher", lcv.parent) - based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on) + total_item_cost += item.get(based_on_field) for item in landed_cost_voucher_doc.items: if item.receipt_document == purchase_document: From 7e93e87244285f86b5d77f8805b05616ccf6d445 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Feb 2020 19:20:36 +0550 Subject: [PATCH 3/3] bumped to version 12.4.3 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 6137307f21a..12177f81da9 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '12.4.2' +__version__ = '12.4.3' def get_default_company(user=None): '''Get default company for user'''