From 7069e2a5a000f3dd5f474a5ee900227d85e14669 Mon Sep 17 00:00:00 2001 From: Ritvik Sardana Date: Fri, 21 Jul 2023 17:18:35 +0530 Subject: [PATCH 1/3] fix: removed validate_item_code function in sales_invoice --- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 2 +- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 4ec103c9f2..db94f829a1 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -773,7 +773,7 @@ frappe.ui.form.on('Sales Invoice', { update_stock: function(frm, dt, dn) { frm.events.hide_fields(frm); - frm.fields_dict.items.grid.toggle_reqd("item_code", frm.doc.update_stock); + // frm.fields_dict.items.grid.toggle_reqd("item_code", frm.doc.update_stock); frm.trigger('reset_posting_time'); }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index b3212b5a7b..4f6374f3df 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -113,7 +113,7 @@ class SalesInvoice(SellingController): if cint(self.update_stock): self.validate_dropship_item() - self.validate_item_code() + # self.validate_item_code() self.validate_warehouse() self.update_current_stock() self.validate_delivery_note() From 82b36e2ec85916c87a695495c670e83d3a6634ec Mon Sep 17 00:00:00 2001 From: Ritvik Sardana Date: Mon, 24 Jul 2023 12:47:29 +0530 Subject: [PATCH 2/3] fix: added test for pos closing without item code --- .../test_pos_closing_entry.py | 18 ++++++++ .../doctype/pos_invoice/test_pos_invoice.py | 43 +++++++++++++------ .../doctype/sales_invoice/sales_invoice.js | 1 - .../doctype/sales_invoice/sales_invoice.py | 6 --- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py index 8eb28dfaa2..1deb3c52ac 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py @@ -49,6 +49,24 @@ class TestPOSClosingEntry(unittest.TestCase): self.assertEqual(pcv_doc.total_quantity, 2) self.assertEqual(pcv_doc.net_total, 6700) + def test_pos_closing_without_item_code(self): + """ + Test if POS Closing Entry is created without item code + """ + test_user, pos_profile = init_user_and_profile() + opening_entry = create_opening_entry(pos_profile, test_user.name) + + pos_inv = create_pos_invoice( + rate=3500, do_not_submit=1, item_name="Test Item", without_item_code=1 + ) + pos_inv.append("payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 3500}) + pos_inv.submit() + + pcv_doc = make_closing_entry_from_opening(opening_entry) + pcv_doc.submit() + + self.assertTrue(pcv_doc.name) + def test_cancelling_of_pos_closing_entry(self): test_user, pos_profile = init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 0fce61f1e7..fa59003231 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -986,19 +986,36 @@ def create_pos_invoice(**args): msg = f"Serial No {args.serial_no} not available for Item {args.item}" frappe.throw(_(msg)) - pos_inv.append( - "items", - { - "item_code": args.item or args.item_code or "_Test Item", - "warehouse": args.warehouse or "_Test Warehouse - _TC", - "qty": args.qty or 1, - "rate": args.rate if args.get("rate") is not None else 100, - "income_account": args.income_account or "Sales - _TC", - "expense_account": args.expense_account or "Cost of Goods Sold - _TC", - "cost_center": args.cost_center or "_Test Cost Center - _TC", - "serial_and_batch_bundle": bundle_id, - }, - ) + # append in pos invoice items without item_code by checking flag without_item_code + if args.without_item_code: + pos_inv.append( + "items", + { + "item_name": args.item_name or "_Test Item", + "description": args.item_name or "_Test Item", + "warehouse": args.warehouse or "_Test Warehouse - _TC", + "qty": args.qty or 1, + "rate": args.rate if args.get("rate") is not None else 100, + "income_account": args.income_account or "Sales - _TC", + "expense_account": args.expense_account or "Cost of Goods Sold - _TC", + "cost_center": args.cost_center or "_Test Cost Center - _TC", + }, + ) + + else: + pos_inv.append( + "items", + { + "item_code": args.item or args.item_code or "_Test Item", + "warehouse": args.warehouse or "_Test Warehouse - _TC", + "qty": args.qty or 1, + "rate": args.rate if args.get("rate") is not None else 100, + "income_account": args.income_account or "Sales - _TC", + "expense_account": args.expense_account or "Cost of Goods Sold - _TC", + "cost_center": args.cost_center or "_Test Cost Center - _TC", + "serial_and_batch_bundle": bundle_id, + }, + ) if not args.do_not_save: pos_inv.insert() diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index db94f829a1..76eac95f95 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -773,7 +773,6 @@ frappe.ui.form.on('Sales Invoice', { update_stock: function(frm, dt, dn) { frm.events.hide_fields(frm); - // frm.fields_dict.items.grid.toggle_reqd("item_code", frm.doc.update_stock); frm.trigger('reset_posting_time'); }, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 4f6374f3df..974a876429 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -113,7 +113,6 @@ class SalesInvoice(SellingController): if cint(self.update_stock): self.validate_dropship_item() - # self.validate_item_code() self.validate_warehouse() self.update_current_stock() self.validate_delivery_note() @@ -854,11 +853,6 @@ class SalesInvoice(SellingController): ): frappe.throw(_("Paid amount + Write Off Amount can not be greater than Grand Total")) - def validate_item_code(self): - for d in self.get("items"): - if not d.item_code and self.is_opening == "No": - msgprint(_("Item Code required at Row No {0}").format(d.idx), raise_exception=True) - def validate_warehouse(self): super(SalesInvoice, self).validate_warehouse() From 8b4228d61635d43fcab182870e32d9028991b07f Mon Sep 17 00:00:00 2001 From: Ritvik Sardana Date: Mon, 24 Jul 2023 13:59:24 +0530 Subject: [PATCH 3/3] fix: removed duplicate code --- .../doctype/pos_invoice/test_pos_invoice.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index fa59003231..00c402f97b 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -986,19 +986,23 @@ def create_pos_invoice(**args): msg = f"Serial No {args.serial_no} not available for Item {args.item}" frappe.throw(_(msg)) + pos_invoice_item = { + "warehouse": args.warehouse or "_Test Warehouse - _TC", + "qty": args.qty or 1, + "rate": args.rate if args.get("rate") is not None else 100, + "income_account": args.income_account or "Sales - _TC", + "expense_account": args.expense_account or "Cost of Goods Sold - _TC", + "cost_center": args.cost_center or "_Test Cost Center - _TC", + "serial_and_batch_bundle": bundle_id, + } # append in pos invoice items without item_code by checking flag without_item_code if args.without_item_code: pos_inv.append( "items", { + **pos_invoice_item, "item_name": args.item_name or "_Test Item", "description": args.item_name or "_Test Item", - "warehouse": args.warehouse or "_Test Warehouse - _TC", - "qty": args.qty or 1, - "rate": args.rate if args.get("rate") is not None else 100, - "income_account": args.income_account or "Sales - _TC", - "expense_account": args.expense_account or "Cost of Goods Sold - _TC", - "cost_center": args.cost_center or "_Test Cost Center - _TC", }, ) @@ -1006,14 +1010,8 @@ def create_pos_invoice(**args): pos_inv.append( "items", { + **pos_invoice_item, "item_code": args.item or args.item_code or "_Test Item", - "warehouse": args.warehouse or "_Test Warehouse - _TC", - "qty": args.qty or 1, - "rate": args.rate if args.get("rate") is not None else 100, - "income_account": args.income_account or "Sales - _TC", - "expense_account": args.expense_account or "Cost of Goods Sold - _TC", - "cost_center": args.cost_center or "_Test Cost Center - _TC", - "serial_and_batch_bundle": bundle_id, }, )