fix: revamp logic (split parent and child)

(cherry picked from commit f7594e2ff9)
This commit is contained in:
Mihir Kandoi
2025-02-21 11:02:38 +05:30
committed by Mergify
parent 1790bcc6d1
commit 7437cea458

View File

@@ -322,17 +322,31 @@ class Project(Document):
self.total_sales_amount = total_sales_amount and total_sales_amount[0][0] or 0 self.total_sales_amount = total_sales_amount and total_sales_amount[0][0] or 0
def update_billed_amount(self): def update_billed_amount(self):
# nosemgrep self.total_billed_amount = self.get_billed_amount_from_parent() + self.get_billed_amount_from_child()
def get_billed_amount_from_parent(self):
total_billed_amount = frappe.db.sql( total_billed_amount = frappe.db.sql(
"""select sum(base_net_amount) """select sum(base_net_amount)
from `tabSales Invoice Item` si_item from `tabSales Invoice` si join `tabSales Invoice Item` si_item on si_item.parent = si.name
join `tabSales Invoice` si on si_item.parent = si.name where si_item.project is null
where (si_item.project = %(name)s or (si_item.project is null and si.project = %(name)s)) and si.project is not null
and si.docstatus = 1""", and si.project = %s
{"name": self.name}, and si.docstatus = 1""",
self.name,
) )
self.total_billed_amount = total_billed_amount and total_billed_amount[0][0] or 0 return total_billed_amount and total_billed_amount[0][0] or 0
def get_billed_amount_from_child(self):
total_billed_amount = frappe.db.sql(
"""select sum(base_net_amount)
from `tabSales Invoice Item`
where project = %s
and docstatus = 1""",
self.name,
)
return total_billed_amount and total_billed_amount[0][0] or 0
def after_rename(self, old_name, new_name, merge=False): def after_rename(self, old_name, new_name, merge=False):
if old_name == self.copied_from: if old_name == self.copied_from: