From 5533592b2b85afdcf66b4b3289248f7580c3672a Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 2 Dec 2024 14:22:41 +0530 Subject: [PATCH 1/3] fix: incorrect Gross Margin on project (#44461) (cherry picked from commit 7de9c14a2ce329ea6134fddf5c13424bc5191657) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.py # erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py --- .../doctype/sales_invoice/sales_invoice.py | 9 ++++ .../sales_invoice/test_sales_invoice.py | 45 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index ff81a114d54..f9197851fad 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1556,8 +1556,17 @@ class SalesInvoice(SellingController): ) def update_project(self): +<<<<<<< HEAD if self.project: project = frappe.get_doc("Project", self.project) +======= + unique_projects = list(set([d.project for d in self.get("items") if d.project])) + if self.project and self.project not in unique_projects: + unique_projects.append(self.project) + + for p in unique_projects: + project = frappe.get_doc("Project", p) +>>>>>>> 7de9c14a2c (fix: incorrect Gross Margin on project (#44461)) project.update_billed_amount() project.db_update() diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index f4b9349c577..134298dc7f9 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3843,6 +3843,7 @@ class TestSalesInvoice(FrappeTestCase): self.assertEqual(jv[0], si.grand_total) +<<<<<<< HEAD def check_gl_entries(doc, voucher_no, expected_gle, posting_date): gl_entries = frappe.db.sql( """select account, debit, credit, posting_date @@ -3852,6 +3853,50 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date): order by posting_date asc, account asc""", (voucher_no, posting_date), as_dict=1, +======= + def test_gl_voucher_subtype(self): + si = create_sales_invoice() + gl_entries = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, + pluck="voucher_subtype", + ) + + self.assertTrue(all([x == "Sales Invoice" for x in gl_entries])) + + si = create_sales_invoice(is_return=1, qty=-1) + gl_entries = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, + pluck="voucher_subtype", + ) + + self.assertTrue(all([x == "Credit Note" for x in gl_entries])) + + def test_total_billed_amount(self): + si = create_sales_invoice(do_not_submit=True) + + project = frappe.new_doc("Project") + project.project_name = "Test Total Billed Amount" + project.save() + + si.project = project.name + si.save() + si.submit() + + doc = frappe.get_doc("Project", project.name) + self.assertEqual(doc.total_billed_amount, si.grand_total) + + +def set_advance_flag(company, flag, default_account): + frappe.db.set_value( + "Company", + company, + { + "book_advance_payments_in_separate_party_account": flag, + "default_advance_received_account": default_account, + }, +>>>>>>> 7de9c14a2c (fix: incorrect Gross Margin on project (#44461)) ) for i, gle in enumerate(gl_entries): From 86ff3e0c106fe00c2ae37877a88bfd0261323e37 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 3 Dec 2024 15:06:16 +0530 Subject: [PATCH 2/3] chore: fix conflicts --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index f9197851fad..b3ef8e23985 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1556,17 +1556,12 @@ class SalesInvoice(SellingController): ) def update_project(self): -<<<<<<< HEAD - if self.project: - project = frappe.get_doc("Project", self.project) -======= unique_projects = list(set([d.project for d in self.get("items") if d.project])) if self.project and self.project not in unique_projects: unique_projects.append(self.project) for p in unique_projects: project = frappe.get_doc("Project", p) ->>>>>>> 7de9c14a2c (fix: incorrect Gross Margin on project (#44461)) project.update_billed_amount() project.db_update() From ccd7992e9949d821df605581e1b2b1e1e3089313 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 3 Dec 2024 15:08:38 +0530 Subject: [PATCH 3/3] chore: fix conflicts --- .../sales_invoice/test_sales_invoice.py | 49 ++++--------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 134298dc7f9..6e4c6002016 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3842,37 +3842,6 @@ class TestSalesInvoice(FrappeTestCase): self.assertTrue(jv) self.assertEqual(jv[0], si.grand_total) - -<<<<<<< HEAD -def check_gl_entries(doc, voucher_no, expected_gle, posting_date): - gl_entries = frappe.db.sql( - """select account, debit, credit, posting_date - from `tabGL Entry` - where voucher_type='Sales Invoice' and voucher_no=%s and posting_date > %s - and is_cancelled = 0 - order by posting_date asc, account asc""", - (voucher_no, posting_date), - as_dict=1, -======= - def test_gl_voucher_subtype(self): - si = create_sales_invoice() - gl_entries = frappe.get_all( - "GL Entry", - filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, - pluck="voucher_subtype", - ) - - self.assertTrue(all([x == "Sales Invoice" for x in gl_entries])) - - si = create_sales_invoice(is_return=1, qty=-1) - gl_entries = frappe.get_all( - "GL Entry", - filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, - pluck="voucher_subtype", - ) - - self.assertTrue(all([x == "Credit Note" for x in gl_entries])) - def test_total_billed_amount(self): si = create_sales_invoice(do_not_submit=True) @@ -3888,15 +3857,15 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date): self.assertEqual(doc.total_billed_amount, si.grand_total) -def set_advance_flag(company, flag, default_account): - frappe.db.set_value( - "Company", - company, - { - "book_advance_payments_in_separate_party_account": flag, - "default_advance_received_account": default_account, - }, ->>>>>>> 7de9c14a2c (fix: incorrect Gross Margin on project (#44461)) +def check_gl_entries(doc, voucher_no, expected_gle, posting_date): + gl_entries = frappe.db.sql( + """select account, debit, credit, posting_date + from `tabGL Entry` + where voucher_type='Sales Invoice' and voucher_no=%s and posting_date > %s + and is_cancelled = 0 + order by posting_date asc, account asc""", + (voucher_no, posting_date), + as_dict=1, ) for i, gle in enumerate(gl_entries):