From b5a2ccf21d0b0ca9fb4c8d958d29d60dcfb5ecb2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 4 May 2023 15:38:35 +0530 Subject: [PATCH] fix: internal transfer condition --- .../doctype/purchase_receipt/purchase_receipt.py | 2 +- erpnext/stock/stock_ledger.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 530427328a88..3373d8ac8c51 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -379,7 +379,7 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None): ) outgoing_amount = d.base_net_amount - if self.is_internal_supplier and d.valuation_rate: + if self.is_internal_transfer() and d.valuation_rate: outgoing_amount = abs( frappe.db.get_value( "Stock Ledger Entry", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 8b517bf1e0fe..103ed4ac3d05 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -556,7 +556,7 @@ def process_sle(self, sle): sle.voucher_type in ["Purchase Receipt", "Purchase Invoice"] and sle.voucher_detail_no and sle.actual_qty < 0 - and frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_internal_supplier") + and is_internal_transfer(sle) ): sle.outgoing_rate = get_incoming_rate_for_inter_company_transfer(sle) @@ -679,7 +679,7 @@ def get_incoming_outgoing_rate_from_transaction(self, sle): elif ( sle.voucher_type in ["Purchase Receipt", "Purchase Invoice"] and sle.voucher_detail_no - and frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_internal_supplier") + and is_internal_transfer(sle) ): rate = get_incoming_rate_for_inter_company_transfer(sle) else: @@ -1609,3 +1609,15 @@ def get_incoming_rate_for_inter_company_transfer(sle) -> float: ) return rate + + +def is_internal_transfer(sle): + data = frappe.get_cached_value( + sle.voucher_type, + sle.voucher_no, + ["is_internal_supplier", "represents_company", "company"], + as_dict=True, + ) + + if data.is_internal_supplier and data.represents_company == data.company: + return True