feat: SL and GL reposting

This commit is contained in:
Sagar Sharma 2022-05-17 15:14:07 +05:30
parent fcc09592b9
commit 323bdf85ce
2 changed files with 16 additions and 6 deletions

View File

@ -15,6 +15,8 @@ def execute():
("accounts", "sales_invoice_item"), ("accounts", "sales_invoice_item"),
("accounts", "purchase_invoice_item"), ("accounts", "purchase_invoice_item"),
("buying", "purchase_receipt_item_supplied"), ("buying", "purchase_receipt_item_supplied"),
("subcontracting", "subcontracting_receipt_item"),
("subcontracting", "subcontracting_receipt_supplied_item"),
] ]
for module, doctype in doctypes_to_reload: for module, doctype in doctypes_to_reload:

View File

@ -619,6 +619,7 @@ class update_entries_after(object):
"Purchase Invoice", "Purchase Invoice",
"Delivery Note", "Delivery Note",
"Sales Invoice", "Sales Invoice",
"Subcontracting Receipt",
): ):
if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"): if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_return"):
from erpnext.controllers.sales_and_purchase_return import ( from erpnext.controllers.sales_and_purchase_return import (
@ -635,6 +636,8 @@ class update_entries_after(object):
else: else:
if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"): if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"):
rate_field = "valuation_rate" rate_field = "valuation_rate"
elif sle.voucher_type == "Subcontracting Receipt":
rate_field = "rate"
else: else:
rate_field = "incoming_rate" rate_field = "incoming_rate"
@ -648,6 +651,8 @@ class update_entries_after(object):
else: else:
if sle.voucher_type in ("Delivery Note", "Sales Invoice"): if sle.voucher_type in ("Delivery Note", "Sales Invoice"):
ref_doctype = "Packed Item" ref_doctype = "Packed Item"
elif sle == "Subcontracting Receipt":
ref_doctype = "Subcontracting Receipt Supplied Item"
else: else:
ref_doctype = "Purchase Receipt Item Supplied" 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) 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"): elif flt(sle.actual_qty) < 0 and sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"):
self.update_rate_on_purchase_receipt(sle, outgoing_rate) 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): 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) 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 "Purchase Receipt Item Supplied", sle.voucher_detail_no, "rate", outgoing_rate
) )
# Recalculate subcontracted item's rate in case of subcontracted purchase receipt/invoice def update_rate_on_subcontracting_receipt(self, sle, outgoing_rate):
if frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_subcontracted"): if frappe.db.exists(sle.voucher_type + " Item", sle.voucher_detail_no):
doc = frappe.get_doc(sle.voucher_type, sle.voucher_no) frappe.db.set_value(sle.voucher_type + " Item", sle.voucher_detail_no, "rate", outgoing_rate)
doc.update_valuation_rate(reset_outgoing_rate=False) else:
for d in doc.items + doc.supplied_items: frappe.db.set_value(
d.db_update() "Subcontracting Receipt Supplied Item", sle.voucher_detail_no, "rate", outgoing_rate
)
def get_serialized_values(self, sle): def get_serialized_values(self, sle):
incoming_rate = flt(sle.incoming_rate) incoming_rate = flt(sle.incoming_rate)