From 5c4d3f89d2dd3102edeeb072b63f8ed5a0a22e13 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Wed, 15 Dec 2021 14:14:16 +0530 Subject: [PATCH] feat: 'Invoice Number' field in Opening Invoice Creation Tool (#28844) --- .../opening_invoice_creation_tool.py | 8 +++++-- .../test_opening_invoice_creation_tool.py | 24 +++++++++++++++---- .../opening_invoice_creation_tool_item.json | 11 ++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py index 2a923f009d..ddb833ff3b 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py @@ -159,7 +159,8 @@ class OpeningInvoiceCreationTool(Document): frappe.scrub(row.party_type): row.party, "is_pos": 0, "doctype": "Sales Invoice" if self.invoice_type == "Sales" else "Purchase Invoice", - "update_stock": 0 + "update_stock": 0, + "invoice_number": row.invoice_number }) accounting_dimension = get_accounting_dimensions() @@ -200,10 +201,13 @@ def start_import(invoices): names = [] for idx, d in enumerate(invoices): try: + invoice_number = None + if d.invoice_number: + invoice_number = d.invoice_number publish(idx, len(invoices), d.doctype) doc = frappe.get_doc(d) doc.flags.ignore_mandatory = True - doc.insert() + doc.insert(set_name=invoice_number) doc.submit() frappe.db.commit() names.append(doc.name) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index c795e83c56..07c72bde7b 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -18,10 +18,10 @@ class TestOpeningInvoiceCreationTool(unittest.TestCase): if not frappe.db.exists("Company", "_Test Opening Invoice Company"): make_company() - def make_invoices(self, invoice_type="Sales", company=None, party_1=None, party_2=None): + def make_invoices(self, invoice_type="Sales", company=None, party_1=None, party_2=None, invoice_number=None): doc = frappe.get_single("Opening Invoice Creation Tool") args = get_opening_invoice_creation_dict(invoice_type=invoice_type, company=company, - party_1=party_1, party_2=party_2) + party_1=party_1, party_2=party_2, invoice_number=invoice_number) doc.update(args) return doc.make_invoices() @@ -92,6 +92,20 @@ class TestOpeningInvoiceCreationTool(unittest.TestCase): # teardown frappe.db.set_value("Company", company, "default_receivable_account", old_default_receivable_account) + def test_renaming_of_invoice_using_invoice_number_field(self): + company = "_Test Opening Invoice Company" + party_1, party_2 = make_customer("Customer A"), make_customer("Customer B") + self.make_invoices(company=company, party_1=party_1, party_2=party_2, invoice_number="TEST-NEW-INV-11") + + sales_inv1 = frappe.get_all('Sales Invoice', filters={'customer':'Customer A'})[0].get("name") + sales_inv2 = frappe.get_all('Sales Invoice', filters={'customer':'Customer B'})[0].get("name") + self.assertEqual(sales_inv1, "TEST-NEW-INV-11") + + #teardown + for inv in [sales_inv1, sales_inv2]: + doc = frappe.get_doc('Sales Invoice', inv) + doc.cancel() + def get_opening_invoice_creation_dict(**args): party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" company = args.get("company", "_Test Company") @@ -107,7 +121,8 @@ def get_opening_invoice_creation_dict(**args): "item_name": "Opening Item", "due_date": "2016-09-10", "posting_date": "2016-09-05", - "temporary_opening_account": get_temporary_opening_account(company) + "temporary_opening_account": get_temporary_opening_account(company), + "invoice_number": args.get("invoice_number") }, { "qty": 2.0, @@ -116,7 +131,8 @@ def get_opening_invoice_creation_dict(**args): "item_name": "Opening Item", "due_date": "2016-09-10", "posting_date": "2016-09-05", - "temporary_opening_account": get_temporary_opening_account(company) + "temporary_opening_account": get_temporary_opening_account(company), + "invoice_number": None } ] }) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool_item/opening_invoice_creation_tool_item.json b/erpnext/accounts/doctype/opening_invoice_creation_tool_item/opening_invoice_creation_tool_item.json index 4ce8cb95b1..040624f926 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool_item/opening_invoice_creation_tool_item.json +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool_item/opening_invoice_creation_tool_item.json @@ -1,9 +1,11 @@ { + "actions": [], "creation": "2017-08-29 04:26:36.159247", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "invoice_number", "party_type", "party", "temporary_opening_account", @@ -103,10 +105,17 @@ { "fieldname": "dimension_col_break", "fieldtype": "Column Break" + }, + { + "description": "Reference number of the invoice from the previous system", + "fieldname": "invoice_number", + "fieldtype": "Data", + "label": "Invoice Number" } ], "istable": 1, - "modified": "2019-07-25 15:00:00.460695", + "links": [], + "modified": "2021-12-13 18:15:41.295007", "modified_by": "Administrator", "module": "Accounts", "name": "Opening Invoice Creation Tool Item",