From 323bdf85ce4398759d9bda456b5de18d3ee31d73 Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Tue, 17 May 2022 15:14:07 +0530 Subject: [PATCH] feat: SL and GL reposting --- .../item_reposting_for_incorrect_sl_and_gl.py | 2 ++ erpnext/stock/stock_ledger.py | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py index f6427ca55a..75a5477be8 100644 --- a/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py +++ b/erpnext/patches/v13_0/item_reposting_for_incorrect_sl_and_gl.py @@ -15,6 +15,8 @@ def execute(): ("accounts", "sales_invoice_item"), ("accounts", "purchase_invoice_item"), ("buying", "purchase_receipt_item_supplied"), + ("subcontracting", "subcontracting_receipt_item"), + ("subcontracting", "subcontracting_receipt_supplied_item"), ] for module, doctype in doctypes_to_reload: diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 3e0ddab6d3..f716ff6d9b 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -619,6 +619,7 @@ class update_entries_after(object): "Purchase Invoice", "Delivery Note", "Sales Invoice", + "Subcontracting Receipt", ): if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"): from erpnext.controllers.sales_and_purchase_return import ( @@ -635,6 +636,8 @@ class update_entries_after(object): else: if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): rate_field = "valuation_rate" + elif sle.voucher_type == "Subcontracting Receipt": + rate_field = "rate" else: rate_field = "incoming_rate" @@ -648,6 +651,8 @@ class update_entries_after(object): else: if sle.voucher_type in ("Delivery Note", "Sales Invoice"): ref_doctype = "Packed Item" + elif sle == "Subcontracting Receipt": + ref_doctype = "Subcontracting Receipt Supplied Item" else: ref_doctype = "Purchase Receipt Item Supplied" @@ -673,6 +678,8 @@ class update_entries_after(object): self.update_rate_on_delivery_and_sales_return(sle, outgoing_rate) elif flt(sle.actual_qty) < 0 and sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): self.update_rate_on_purchase_receipt(sle, outgoing_rate) + elif flt(sle.actual_qty) < 0 and sle.voucher_type == "Subcontracting Receipt": + self.update_rate_on_subcontracting_receipt(sle, outgoing_rate) def update_rate_on_stock_entry(self, sle, outgoing_rate): frappe.db.set_value("Stock Entry Detail", sle.voucher_detail_no, "basic_rate", outgoing_rate) @@ -714,12 +721,13 @@ class update_entries_after(object): "Purchase Receipt Item Supplied", sle.voucher_detail_no, "rate", outgoing_rate ) - # Recalculate subcontracted item's rate in case of subcontracted purchase receipt/invoice - if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_subcontracted"): - doc = frappe.get_doc(sle.voucher_type, sle.voucher_no) - doc.update_valuation_rate(reset_outgoing_rate=False) - for d in doc.items + doc.supplied_items: - d.db_update() + def update_rate_on_subcontracting_receipt(self, sle, outgoing_rate): + if frappe.db.exists(sle.voucher_type + " Item", sle.voucher_detail_no): + frappe.db.set_value(sle.voucher_type + " Item", sle.voucher_detail_no, "rate", outgoing_rate) + else: + frappe.db.set_value( + "Subcontracting Receipt Supplied Item", sle.voucher_detail_no, "rate", outgoing_rate + ) def get_serialized_values(self, sle): incoming_rate = flt(sle.incoming_rate)