From e2a2328950c9148c1f54446860b43a53d6da6e23 Mon Sep 17 00:00:00 2001 From: Afshan Date: Tue, 25 May 2021 23:43:45 +0530 Subject: [PATCH 1/2] 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 630a1dc8cd570..b3689a315e73f 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 1e8ce3c6583a5..d3c2411741c42 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 0000000000000..0d4c0a5b03da7 --- /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 f1292d8cbdde4..1bf5a499ab544 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/2] 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 e5ef978ca3cc6..9f6f343e6745d 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()