From e2a2328950c9148c1f54446860b43a53d6da6e23 Mon Sep 17 00:00:00 2001 From: Afshan Date: Tue, 25 May 2021 23:43:45 +0530 Subject: [PATCH 1/9] feat: fetching of qty as per received qty from PR to PI --- .../doctype/buying_settings/buying_settings.json | 14 +++++++++++--- erpnext/patches.txt | 1 + ...sider_rejected_quantity_for_purchase_invoice.py | 8 ++++++++ .../doctype/purchase_receipt/purchase_receipt.py | 4 +++- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index 630a1dc8cd57..b3689a315e73 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -9,13 +9,14 @@ "supp_master_name", "supplier_group", "buying_price_list", + "maintain_same_rate_action", + "role_to_override_stop_action", "column_break_3", "po_required", "pr_required", "maintain_same_rate", - "maintain_same_rate_action", - "role_to_override_stop_action", "allow_multiple_items", + "consider_rejected_quantity_for_purchase_invoice", "subcontract", "backflush_raw_materials_of_subcontract_based_on", "column_break_11", @@ -108,6 +109,13 @@ "fieldtype": "Link", "label": "Role Allowed to Override Stop Action", "options": "Role" + }, + { + "default": "1", + "description": "When Checked, Rejected Quantity Will Be Considered While Making Purchase Invoice From Purchase Receipt.", + "fieldname": "consider_rejected_quantity_for_purchase_invoice", + "fieldtype": "Check", + "label": "Consider Rejected Quantity For Purchase Invoice" } ], "icon": "fa fa-cog", @@ -115,7 +123,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-04-04 20:01:44.087066", + "modified": "2021-05-25 23:40:30.871116", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 1e8ce3c6583a..d3c2411741c4 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -781,3 +781,4 @@ erpnext.patches.v13_0.germany_fill_debtor_creditor_number erpnext.patches.v13_0.set_pos_closing_as_failed erpnext.patches.v13_0.update_timesheet_changes erpnext.patches.v13_0.set_training_event_attendance +erpnext.patches.v13_0.consider_rejected_quantity_for_purchase_invoice diff --git a/erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py b/erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py new file mode 100644 index 000000000000..0d4c0a5b03da --- /dev/null +++ b/erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py @@ -0,0 +1,8 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doctype("Buying Settings") + buying_settings = frappe.get_single("Buying Settings") + buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.save() diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index f1292d8cbdde..1bf5a499ab54 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -579,7 +579,6 @@ def update_billing_percentage(pr_doc, update_modified=True): @frappe.whitelist() def make_purchase_invoice(source_name, target_doc=None): - from frappe.model.mapper import get_mapped_doc from erpnext.accounts.party import get_payment_terms_template doc = frappe.get_doc('Purchase Receipt', source_name) @@ -599,6 +598,9 @@ def set_missing_values(source, target): def update_item(source_doc, target_doc, source_parent): target_doc.qty, returned_qty = get_pending_qty(source_doc) + if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_for_purchase_invoice"): + target_doc.qty = source_doc.received_qty + target_doc.rejected_qty = 0 target_doc.stock_qty = flt(target_doc.qty) * flt(target_doc.conversion_factor, target_doc.precision("conversion_factor")) returned_qty_map[source_doc.name] = returned_qty From 1e66aae28a7e8df290db5b4763b7f02ff1685149 Mon Sep 17 00:00:00 2001 From: Afshan Date: Wed, 26 May 2021 21:13:50 +0530 Subject: [PATCH 2/9] fix: test cases --- .../purchase_receipt/test_purchase_receipt.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index e5ef978ca3cc..9f6f343e6745 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -414,11 +414,18 @@ def test_purchase_return_partial(self): self.assertEqual(return_pr_2.items[0].qty, -3) # Make PI against unreturned amount + buying_settings = frappe.get_single("Buying Settings") + buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.save() + pi = make_purchase_invoice(pr.name) pi.submit() self.assertEqual(pi.items[0].qty, 3) + buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.save() + pr.load_from_db() # PR should be completed on billing all unreturned amount self.assertEqual(pr.items[0].billed_amt, 150) @@ -760,8 +767,18 @@ def test_make_purchase_invoice_from_pr_for_returned_qty(self): pr1.items[0].purchase_receipt_item = pr.items[0].name pr1.submit() - pi = make_purchase_invoice(pr.name) - self.assertEqual(pi.items[0].qty, 3) + buying_settings = frappe.get_single("Buying Settings") + buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.save() + + pi1 = make_purchase_invoice(pr.name) + self.assertEqual(pi1.items[0].qty, 3) + + buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.save() + + pi2 = make_purchase_invoice(pr.name) + self.assertEqual(pi2.items[0].qty, 4) pr1.cancel() pr.reload() @@ -791,10 +808,21 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pr2.items[0].purchase_receipt_item = pr1.items[0].name pr2.submit() + buying_settings = frappe.get_single("Buying Settings") + buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.save() + pi2 = make_purchase_invoice(pr1.name) self.assertEqual(pi2.items[0].qty, 2) self.assertEqual(pi2.items[1].qty, 1) + buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.save() + + pi3 = make_purchase_invoice(pr1.name) + self.assertEqual(pi3.items[0].qty, 8) + self.assertEqual(pi3.items[1].qty, 1) + pr2.cancel() pi1.cancel() pr1.reload() From fdc516aa71fd69871f08a00f4ae885bbde407cb7 Mon Sep 17 00:00:00 2001 From: Afshan Date: Mon, 14 Jun 2021 10:09:28 +0530 Subject: [PATCH 3/9] fix: bypass overbilling --- erpnext/controllers/accounts_controller.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index f88e8df72861..21334d7c8b70 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -744,8 +744,9 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield): role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): - frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") - .format(item.item_code, item.idx, max_allowed_amt)) + if not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_for_purchase_invoice")): + frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") + .format(item.item_code, item.idx, max_allowed_amt)) def get_company_default(self, fieldname): from erpnext.accounts.utils import get_company_default From 4c46eef1bccbf44b8e7f8f69a695dca466789f83 Mon Sep 17 00:00:00 2001 From: Afshan Date: Thu, 17 Jun 2021 17:15:28 +0530 Subject: [PATCH 4/9] fix: multiple invoices calculation and description formatting --- erpnext/buying/doctype/buying_settings/buying_settings.json | 6 +++--- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index b3689a315e73..5bdc19e9fe12 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -112,10 +112,10 @@ }, { "default": "1", - "description": "When Checked, Rejected Quantity Will Be Considered While Making Purchase Invoice From Purchase Receipt.", + "description": "If checked, Rejected Quantity will be considered while making Purchase Invoice from Purchase Receipt.", "fieldname": "consider_rejected_quantity_for_purchase_invoice", "fieldtype": "Check", - "label": "Consider Rejected Quantity For Purchase Invoice" + "label": "Consider Rejected Quantity in Purchase Invoice" } ], "icon": "fa fa-cog", @@ -123,7 +123,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-05-25 23:40:30.871116", + "modified": "2021-06-17 16:39:55.707713", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 1bf5a499ab54..2231be77f2d1 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -599,7 +599,7 @@ def set_missing_values(source, target): def update_item(source_doc, target_doc, source_parent): target_doc.qty, returned_qty = get_pending_qty(source_doc) if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_for_purchase_invoice"): - target_doc.qty = source_doc.received_qty + target_doc.qty = source_doc.received_qty - invoiced_qty_map.get(source_doc.name, 0) target_doc.rejected_qty = 0 target_doc.stock_qty = flt(target_doc.qty) * flt(target_doc.conversion_factor, target_doc.precision("conversion_factor")) returned_qty_map[source_doc.name] = returned_qty From 3fca930aeb65a85866a770776b8f25c7e5d3e348 Mon Sep 17 00:00:00 2001 From: Afshan Date: Thu, 17 Jun 2021 17:21:36 +0530 Subject: [PATCH 5/9] fix: replacing field name --- .../doctype/buying_settings/buying_settings.json | 6 +++--- erpnext/controllers/accounts_controller.py | 2 +- erpnext/patches.txt | 2 +- ...onsider_rejected_quantity_in_purchase_invoice.py} | 2 +- .../doctype/purchase_receipt/purchase_receipt.py | 2 +- .../purchase_receipt/test_purchase_receipt.py | 12 ++++++------ 6 files changed, 13 insertions(+), 13 deletions(-) rename erpnext/patches/v13_0/{consider_rejected_quantity_for_purchase_invoice.py => consider_rejected_quantity_in_purchase_invoice.py} (73%) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index 5bdc19e9fe12..162f6faaca49 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -16,7 +16,7 @@ "pr_required", "maintain_same_rate", "allow_multiple_items", - "consider_rejected_quantity_for_purchase_invoice", + "consider_rejected_quantity_in_purchase_invoice", "subcontract", "backflush_raw_materials_of_subcontract_based_on", "column_break_11", @@ -113,7 +113,7 @@ { "default": "1", "description": "If checked, Rejected Quantity will be considered while making Purchase Invoice from Purchase Receipt.", - "fieldname": "consider_rejected_quantity_for_purchase_invoice", + "fieldname": "consider_rejected_quantity_in_purchase_invoice", "fieldtype": "Check", "label": "Consider Rejected Quantity in Purchase Invoice" } @@ -123,7 +123,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-06-17 16:39:55.707713", + "modified": "2021-06-17 17:17:40.024658", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 21334d7c8b70..9d48fbceed83 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -744,7 +744,7 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield): role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): - if not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_for_purchase_invoice")): + if not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice")): frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") .format(item.item_code, item.idx, max_allowed_amt)) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 97bcbeac168b..de792153e4b9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -781,5 +781,5 @@ erpnext.patches.v13_0.germany_fill_debtor_creditor_number erpnext.patches.v13_0.set_pos_closing_as_failed erpnext.patches.v13_0.update_timesheet_changes erpnext.patches.v13_0.set_training_event_attendance -erpnext.patches.v13_0.consider_rejected_quantity_for_purchase_invoice +erpnext.patches.v13_0.consider_rejected_quantity_in_purchase_invoice erpnext.patches.v13_0.rename_issue_status_hold_to_on_hold diff --git a/erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py b/erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py similarity index 73% rename from erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py rename to erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py index 0d4c0a5b03da..9eacd0c77e50 100644 --- a/erpnext/patches/v13_0/consider_rejected_quantity_for_purchase_invoice.py +++ b/erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py @@ -4,5 +4,5 @@ def execute(): frappe.reload_doctype("Buying Settings") buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 2231be77f2d1..10af8b278477 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -598,7 +598,7 @@ def set_missing_values(source, target): def update_item(source_doc, target_doc, source_parent): target_doc.qty, returned_qty = get_pending_qty(source_doc) - if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_for_purchase_invoice"): + if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice"): target_doc.qty = source_doc.received_qty - invoiced_qty_map.get(source_doc.name, 0) target_doc.rejected_qty = 0 target_doc.stock_qty = flt(target_doc.qty) * flt(target_doc.conversion_factor, target_doc.precision("conversion_factor")) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 65a07bdedef3..191b9910aba0 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -418,7 +418,7 @@ def test_purchase_return_partial(self): # Make PI against unreturned amount buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() pi = make_purchase_invoice(pr.name) @@ -426,7 +426,7 @@ def test_purchase_return_partial(self): self.assertEqual(pi.items[0].qty, 3) - buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 buying_settings.save() pr.load_from_db() @@ -771,13 +771,13 @@ def test_make_purchase_invoice_from_pr_for_returned_qty(self): pr1.submit() buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() pi1 = make_purchase_invoice(pr.name) self.assertEqual(pi1.items[0].qty, 3) - buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 buying_settings.save() pi2 = make_purchase_invoice(pr.name) @@ -812,14 +812,14 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pr2.submit() buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_for_purchase_invoice = 0 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() pi2 = make_purchase_invoice(pr1.name) self.assertEqual(pi2.items[0].qty, 2) self.assertEqual(pi2.items[1].qty, 1) - buying_settings.consider_rejected_quantity_for_purchase_invoice = 1 + buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 buying_settings.save() pi3 = make_purchase_invoice(pr1.name) From be1bc10df35246aaf1e7b2760c9eccb0cd8fdf86 Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 18 Jun 2021 19:08:27 +0530 Subject: [PATCH 6/9] fix: allow overbilling for Purchase Invoice only --- erpnext/controllers/accounts_controller.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 9d48fbceed83..d6c8fd7028e1 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -744,9 +744,14 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield): role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): - if not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice")): - frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") - .format(item.item_code, item.idx, max_allowed_amt)) + if ref_dt != "Purchase Invoice": + self.throw_overbill_exception(item, max_allowed_amt) + elif not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice")): + self.throw_overbill_exception(item, max_allowed_amt) + + def throw_overbill_exception(item, max_allowed_amt): + frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") + .format(item.item_code, item.idx, max_allowed_amt)) def get_company_default(self, fieldname): from erpnext.accounts.utils import get_company_default From 22c9ba676a34dd89748bedc50fe39766b8ad8a39 Mon Sep 17 00:00:00 2001 From: Afshan Date: Tue, 22 Jun 2021 17:20:48 +0530 Subject: [PATCH 7/9] fix: calculations and error msg formats --- erpnext/controllers/accounts_controller.py | 4 ++-- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 320df57a0209..e53cf9513fa4 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -828,12 +828,12 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield): role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill') if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): - if ref_dt != "Purchase Invoice": + if self.doctype != "Purchase Invoice": self.throw_overbill_exception(item, max_allowed_amt) elif not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice")): self.throw_overbill_exception(item, max_allowed_amt) - def throw_overbill_exception(item, max_allowed_amt): + def throw_overbill_exception(self, item, max_allowed_amt): frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings") .format(item.item_code, item.idx, max_allowed_amt)) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 2ecd21662503..8f7d36f544c9 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -601,13 +601,15 @@ def set_missing_values(source, target): def update_item(source_doc, target_doc, source_parent): target_doc.qty, returned_qty = get_pending_qty(source_doc) if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice"): - target_doc.qty = source_doc.received_qty - invoiced_qty_map.get(source_doc.name, 0) target_doc.rejected_qty = 0 target_doc.stock_qty = flt(target_doc.qty) * flt(target_doc.conversion_factor, target_doc.precision("conversion_factor")) returned_qty_map[source_doc.name] = returned_qty def get_pending_qty(item_row): - pending_qty = item_row.qty - invoiced_qty_map.get(item_row.name, 0) + qty = item_row.qty + if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice"): + qty = item_row.received_qty + pending_qty = qty - invoiced_qty_map.get(item_row.name, 0) returned_qty = flt(returned_qty_map.get(item_row.name, 0)) if returned_qty: if returned_qty >= pending_qty: From 11d0032871599ba5dfbcaee3dc76cfef86b94ef0 Mon Sep 17 00:00:00 2001 From: Afshan Date: Wed, 23 Jun 2021 16:03:25 +0530 Subject: [PATCH 8/9] fix: test cases --- .../purchase_receipt/test_purchase_receipt.py | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 9e994977b24e..eb8d9243e0b8 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -774,19 +774,9 @@ def test_make_purchase_invoice_from_pr_for_returned_qty(self): pr1.items[0].purchase_receipt_item = pr.items[0].name pr1.submit() - buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 - buying_settings.save() - pi1 = make_purchase_invoice(pr.name) self.assertEqual(pi1.items[0].qty, 3) - buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 - buying_settings.save() - - pi2 = make_purchase_invoice(pr.name) - self.assertEqual(pi2.items[0].qty, 4) - pr1.cancel() pr.reload() pr.cancel() @@ -815,21 +805,10 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pr2.items[0].purchase_receipt_item = pr1.items[0].name pr2.submit() - buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 - buying_settings.save() - pi2 = make_purchase_invoice(pr1.name) self.assertEqual(pi2.items[0].qty, 2) self.assertEqual(pi2.items[1].qty, 1) - buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 - buying_settings.save() - - pi3 = make_purchase_invoice(pr1.name) - self.assertEqual(pi3.items[0].qty, 8) - self.assertEqual(pi3.items[1].qty, 1) - pr2.cancel() pi1.cancel() pr1.reload() From e1dcfef4b99efdf651b253ee05b2f03ee4529e52 Mon Sep 17 00:00:00 2001 From: Afshan Date: Wed, 23 Jun 2021 19:46:53 +0530 Subject: [PATCH 9/9] fix: renamed variable --- .../doctype/buying_settings/buying_settings.json | 10 +++++----- erpnext/controllers/accounts_controller.py | 2 +- erpnext/patches.txt | 2 +- ... bill_for_rejected_quantity_in_purchase_invoice.py} | 2 +- .../stock/doctype/purchase_receipt/purchase_receipt.py | 4 ++-- .../doctype/purchase_receipt/test_purchase_receipt.py | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) rename erpnext/patches/v13_0/{consider_rejected_quantity_in_purchase_invoice.py => bill_for_rejected_quantity_in_purchase_invoice.py} (75%) diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index 162f6faaca49..838a9abf8c07 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -16,7 +16,7 @@ "pr_required", "maintain_same_rate", "allow_multiple_items", - "consider_rejected_quantity_in_purchase_invoice", + "bill_for_rejected_quantity_in_purchase_invoice", "subcontract", "backflush_raw_materials_of_subcontract_based_on", "column_break_11", @@ -112,10 +112,10 @@ }, { "default": "1", - "description": "If checked, Rejected Quantity will be considered while making Purchase Invoice from Purchase Receipt.", - "fieldname": "consider_rejected_quantity_in_purchase_invoice", + "description": "If checked, Rejected Quantity will be included while making Purchase Invoice from Purchase Receipt.", + "fieldname": "bill_for_rejected_quantity_in_purchase_invoice", "fieldtype": "Check", - "label": "Consider Rejected Quantity in Purchase Invoice" + "label": "Bill for Rejected Quantity in Purchase Invoice" } ], "icon": "fa fa-cog", @@ -123,7 +123,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-06-17 17:17:40.024658", + "modified": "2021-06-23 19:40:00.120822", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e53cf9513fa4..1c086e9edcda 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -830,7 +830,7 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield): if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles(): if self.doctype != "Purchase Invoice": self.throw_overbill_exception(item, max_allowed_amt) - elif not cint(frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice")): + elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")): self.throw_overbill_exception(item, max_allowed_amt) def throw_overbill_exception(self, item, max_allowed_amt): diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a705c93f72b0..339e7f99d268 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -288,5 +288,5 @@ execute:frappe.rename_doc("Workspace", "Loan Management", "Loans", force=True) erpnext.patches.v13_0.update_timesheet_changes erpnext.patches.v13_0.add_doctype_to_sla #14-06-2021 erpnext.patches.v13_0.set_training_event_attendance -erpnext.patches.v13_0.consider_rejected_quantity_in_purchase_invoice +erpnext.patches.v13_0.bill_for_rejected_quantity_in_purchase_invoice erpnext.patches.v13_0.rename_issue_status_hold_to_on_hold diff --git a/erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py b/erpnext/patches/v13_0/bill_for_rejected_quantity_in_purchase_invoice.py similarity index 75% rename from erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py rename to erpnext/patches/v13_0/bill_for_rejected_quantity_in_purchase_invoice.py index 9eacd0c77e50..7de9fa1e23e9 100644 --- a/erpnext/patches/v13_0/consider_rejected_quantity_in_purchase_invoice.py +++ b/erpnext/patches/v13_0/bill_for_rejected_quantity_in_purchase_invoice.py @@ -4,5 +4,5 @@ def execute(): frappe.reload_doctype("Buying Settings") buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 + buying_settings.bill_for_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 8f7d36f544c9..e488b695b5f6 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -600,14 +600,14 @@ def set_missing_values(source, target): def update_item(source_doc, target_doc, source_parent): target_doc.qty, returned_qty = get_pending_qty(source_doc) - if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice"): + if frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice"): target_doc.rejected_qty = 0 target_doc.stock_qty = flt(target_doc.qty) * flt(target_doc.conversion_factor, target_doc.precision("conversion_factor")) returned_qty_map[source_doc.name] = returned_qty def get_pending_qty(item_row): qty = item_row.qty - if frappe.db.get_single_value("Buying Settings", "consider_rejected_quantity_in_purchase_invoice"): + if frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice"): qty = item_row.received_qty pending_qty = qty - invoiced_qty_map.get(item_row.name, 0) returned_qty = flt(returned_qty_map.get(item_row.name, 0)) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index eb8d9243e0b8..99abf3a68cf5 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -422,7 +422,7 @@ def test_purchase_return_partial(self): # Make PI against unreturned amount buying_settings = frappe.get_single("Buying Settings") - buying_settings.consider_rejected_quantity_in_purchase_invoice = 0 + buying_settings.bill_for_rejected_quantity_in_purchase_invoice = 0 buying_settings.save() pi = make_purchase_invoice(pr.name) @@ -430,7 +430,7 @@ def test_purchase_return_partial(self): self.assertEqual(pi.items[0].qty, 3) - buying_settings.consider_rejected_quantity_in_purchase_invoice = 1 + buying_settings.bill_for_rejected_quantity_in_purchase_invoice = 1 buying_settings.save() pr.load_from_db()