Browse Source

feat: 'Invoice Number' field in Opening Invoice Creation Tool (#28844)

develop
Subin Tom 3 years ago
committed by GitHub
parent
commit
5c4d3f89d2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
  2. 24
      erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py
  3. 11
      erpnext/accounts/doctype/opening_invoice_creation_tool_item/opening_invoice_creation_tool_item.json

8
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, frappe.scrub(row.party_type): row.party,
"is_pos": 0, "is_pos": 0,
"doctype": "Sales Invoice" if self.invoice_type == "Sales" else "Purchase Invoice", "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() accounting_dimension = get_accounting_dimensions()
@ -200,10 +201,13 @@ def start_import(invoices):
names = [] names = []
for idx, d in enumerate(invoices): for idx, d in enumerate(invoices):
try: try:
invoice_number = None
if d.invoice_number:
invoice_number = d.invoice_number
publish(idx, len(invoices), d.doctype) publish(idx, len(invoices), d.doctype)
doc = frappe.get_doc(d) doc = frappe.get_doc(d)
doc.flags.ignore_mandatory = True doc.flags.ignore_mandatory = True
doc.insert() doc.insert(set_name=invoice_number)
doc.submit() doc.submit()
frappe.db.commit() frappe.db.commit()
names.append(doc.name) names.append(doc.name)

24
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"): if not frappe.db.exists("Company", "_Test Opening Invoice Company"):
make_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") doc = frappe.get_single("Opening Invoice Creation Tool")
args = get_opening_invoice_creation_dict(invoice_type=invoice_type, company=company, 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) doc.update(args)
return doc.make_invoices() return doc.make_invoices()
@ -92,6 +92,20 @@ class TestOpeningInvoiceCreationTool(unittest.TestCase):
# teardown # teardown
frappe.db.set_value("Company", company, "default_receivable_account", old_default_receivable_account) 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): def get_opening_invoice_creation_dict(**args):
party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier"
company = args.get("company", "_Test Company") company = args.get("company", "_Test Company")
@ -107,7 +121,8 @@ def get_opening_invoice_creation_dict(**args):
"item_name": "Opening Item", "item_name": "Opening Item",
"due_date": "2016-09-10", "due_date": "2016-09-10",
"posting_date": "2016-09-05", "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, "qty": 2.0,
@ -116,7 +131,8 @@ def get_opening_invoice_creation_dict(**args):
"item_name": "Opening Item", "item_name": "Opening Item",
"due_date": "2016-09-10", "due_date": "2016-09-10",
"posting_date": "2016-09-05", "posting_date": "2016-09-05",
"temporary_opening_account": get_temporary_opening_account(company) "temporary_opening_account": get_temporary_opening_account(company),
"invoice_number": None
} }
] ]
}) })

11
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", "creation": "2017-08-29 04:26:36.159247",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"invoice_number",
"party_type", "party_type",
"party", "party",
"temporary_opening_account", "temporary_opening_account",
@ -103,10 +105,17 @@
{ {
"fieldname": "dimension_col_break", "fieldname": "dimension_col_break",
"fieldtype": "Column Break" "fieldtype": "Column Break"
},
{
"description": "Reference number of the invoice from the previous system",
"fieldname": "invoice_number",
"fieldtype": "Data",
"label": "Invoice Number"
} }
], ],
"istable": 1, "istable": 1,
"modified": "2019-07-25 15:00:00.460695", "links": [],
"modified": "2021-12-13 18:15:41.295007",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Opening Invoice Creation Tool Item", "name": "Opening Invoice Creation Tool Item",

Loading…
Cancel
Save