refactor(stock): pass inter_company_reference as an argument

validate_internal_transfer_qty stashed the value on a name-mangled instance
attribute (self.__inter_company_reference) that get_item_wise_inter_transfer_qty
read back, creating an implicit call-ordering contract: calling the latter on a
fresh service without the former first raised AttributeError. Compute it as a local
and pass it as a method argument, removing the hidden cross-method state.

Verified: ledger snapshots + PR internal-transfer suite stay green.
This commit is contained in:
Nabin Hait
2026-06-05 12:19:52 +05:30
parent f4705fd5a8
commit 3dba21f814

View File

@@ -72,13 +72,13 @@ class StockInternalTransferService:
if self.doc.doctype not in ["Purchase Invoice", "Purchase Receipt"]:
return
self.__inter_company_reference = (
inter_company_reference = (
self.doc.get("inter_company_reference")
if self.doc.doctype == "Purchase Invoice"
else self.doc.get("inter_company_invoice_reference")
)
item_wise_transfer_qty = self.get_item_wise_inter_transfer_qty()
item_wise_transfer_qty = self.get_item_wise_inter_transfer_qty(inter_company_reference)
if not item_wise_transfer_qty:
return
@@ -105,11 +105,11 @@ class StockInternalTransferService:
bold(key[1]),
bold(flt(transferred_qty, precision)),
bold(parent_doctype),
get_link_to_form(parent_doctype, self.__inter_company_reference),
get_link_to_form(parent_doctype, inter_company_reference),
)
)
def get_item_wise_inter_transfer_qty(self):
def get_item_wise_inter_transfer_qty(self, inter_company_reference):
parent_doctype = {
"Purchase Receipt": "Delivery Note",
"Purchase Invoice": "Sales Invoice",
@@ -129,7 +129,7 @@ class StockInternalTransferService:
child_tab.item_code,
child_tab.qty,
)
.where((parent_tab.name == self.__inter_company_reference) & (parent_tab.docstatus == 1))
.where((parent_tab.name == inter_company_reference) & (parent_tab.docstatus == 1))
)
data = query.run(as_dict=True)