fix: include cost center in patch

This commit is contained in:
Mihir Kandoi
2025-07-18 15:33:31 +05:30
parent c022b80e05
commit b53723acad
2 changed files with 26 additions and 24 deletions

View File

@@ -1,24 +0,0 @@
import frappe
def execute():
docs = frappe.get_all(
"GL Entry",
filters={"voucher_type": "Subcontracting Receipt", "account": ["is", "not set"], "is_cancelled": 0},
pluck="voucher_no",
)
for doc in docs:
doc = frappe.get_doc("Subcontracting Receipt", doc)
for item in doc.supplied_items:
if not item.expense_account:
account = frappe.get_value(
"Subcontracting Receipt Item", item.reference_name, "expense_account"
)
item.db_set("expense_account", account)
repost_doc = frappe.new_doc("Repost Item Valuation")
repost_doc.voucher_type = "Subcontracting Receipt"
repost_doc.voucher_no = doc.name
repost_doc.based_on = "Transaction"
repost_doc.company = doc.company
repost_doc.save()
repost_doc.submit()

View File

@@ -0,0 +1,26 @@
import frappe
def execute():
docs = frappe.get_all(
"GL Entry",
filters={"voucher_type": "Subcontracting Receipt", "account": ["is", "not set"], "is_cancelled": 0},
pluck="voucher_no",
)
for doc in docs:
doc = frappe.get_doc("Subcontracting Receipt", doc)
for item in doc.supplied_items:
account, cost_center = frappe.db.get_values(
"Subcontracting Receipt Item", item.reference_name, ["expense_account", "cost_center"]
)[0]
if not item.expense_account:
item.db_set("expense_account", account)
if not item.cost_center:
item.db_set("cost_center", cost_center)
repost_doc = frappe.new_doc("Repost Item Valuation")
repost_doc.voucher_type = "Subcontracting Receipt"
repost_doc.voucher_no = doc.name
repost_doc.based_on = "Transaction"
repost_doc.company = doc.company
repost_doc.save()
repost_doc.submit()