From 7290dd87bee72a86e2fef3f84810d251fc4d7112 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 28 Mar 2023 14:33:47 +0530 Subject: [PATCH] fix: linters and travis --- erpnext/stock/doctype/batch/batch.py | 8 +- .../stock/doctype/package_item/__init__.py | 0 .../doctype/package_item/package_item.js | 8 - .../doctype/package_item/package_item.json | 138 ------------------ .../doctype/package_item/package_item.py | 9 -- .../doctype/package_item/test_package_item.py | 9 -- .../serial_and_batch_bundle.py | 21 +-- erpnext/stock/doctype/serial_no/serial_no.py | 11 -- .../stock/doctype/stock_entry/stock_entry.py | 2 + .../stock_ledger_entry/stock_ledger_entry.py | 15 +- 10 files changed, 26 insertions(+), 195 deletions(-) delete mode 100644 erpnext/stock/doctype/package_item/__init__.py delete mode 100644 erpnext/stock/doctype/package_item/package_item.js delete mode 100644 erpnext/stock/doctype/package_item/package_item.json delete mode 100644 erpnext/stock/doctype/package_item/package_item.py delete mode 100644 erpnext/stock/doctype/package_item/test_package_item.py diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index a9df1e81f9..84ab74a8c6 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -316,10 +316,10 @@ def validate_serial_no_with_batch(serial_nos, item_code): frappe.throw(_("There is no batch found against the {0}: {1}").format(message, serial_no_link)) -def make_batch(args): - if frappe.db.get_value("Item", args.item, "has_batch_no"): - args.doctype = "Batch" - return frappe.get_doc(args).insert().name +def make_batch(kwargs): + if frappe.db.get_value("Item", kwargs.item, "has_batch_no"): + kwargs.doctype = "Batch" + return frappe.get_doc(kwargs).insert().name @frappe.whitelist() diff --git a/erpnext/stock/doctype/package_item/__init__.py b/erpnext/stock/doctype/package_item/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/stock/doctype/package_item/package_item.js b/erpnext/stock/doctype/package_item/package_item.js deleted file mode 100644 index 65fda46238..0000000000 --- a/erpnext/stock/doctype/package_item/package_item.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Package Item', { - // refresh: function(frm) { - - // } -}); diff --git a/erpnext/stock/doctype/package_item/package_item.json b/erpnext/stock/doctype/package_item/package_item.json deleted file mode 100644 index 5b0246f9f8..0000000000 --- a/erpnext/stock/doctype/package_item/package_item.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "actions": [], - "creation": "2022-09-29 14:56:38.338267", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "item_details_tab", - "company", - "item_code", - "column_break_4", - "warehouse", - "qty", - "serial_no_and_batch_no_tab", - "transactions", - "reference_details_tab", - "voucher_type", - "voucher_no", - "column_break_12", - "voucher_detail_no", - "amended_from" - ], - "fields": [ - { - "fieldname": "item_code", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Item Code", - "options": "Item", - "reqd": 1 - }, - { - "fieldname": "amended_from", - "fieldtype": "Link", - "label": "Amended From", - "no_copy": 1, - "options": "Package Item", - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "item_details_tab", - "fieldtype": "Tab Break", - "label": "Item Details" - }, - { - "fieldname": "warehouse", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Warehouse", - "options": "Warehouse", - "reqd": 1 - }, - { - "fieldname": "column_break_4", - "fieldtype": "Column Break" - }, - { - "fieldname": "company", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Company", - "options": "Company", - "reqd": 1 - }, - { - "fieldname": "qty", - "fieldtype": "Float", - "label": "Total Qty" - }, - { - "fieldname": "reference_details_tab", - "fieldtype": "Tab Break", - "label": "Reference Details" - }, - { - "fieldname": "voucher_type", - "fieldtype": "Link", - "label": "Voucher Type", - "options": "DocType", - "reqd": 1 - }, - { - "fieldname": "voucher_no", - "fieldtype": "Dynamic Link", - "label": "Voucher No", - "options": "voucher_type" - }, - { - "fieldname": "voucher_detail_no", - "fieldtype": "Data", - "label": "Voucher Detail No", - "read_only": 1 - }, - { - "fieldname": "serial_no_and_batch_no_tab", - "fieldtype": "Tab Break", - "label": "Serial No and Batch No" - }, - { - "fieldname": "column_break_12", - "fieldtype": "Column Break" - }, - { - "fieldname": "transactions", - "fieldtype": "Table", - "label": "Items", - "options": "Serial and Batch No Transaction", - "reqd": 1 - } - ], - "index_web_pages_for_search": 1, - "is_submittable": 1, - "links": [], - "modified": "2022-10-06 22:07:31.732744", - "modified_by": "Administrator", - "module": "Stock", - "name": "Package Item", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "submit": 1, - "write": 1 - } - ], - "sort_field": "modified", - "sort_order": "DESC", - "states": [] -} \ No newline at end of file diff --git a/erpnext/stock/doctype/package_item/package_item.py b/erpnext/stock/doctype/package_item/package_item.py deleted file mode 100644 index c0a2eaa53a..0000000000 --- a/erpnext/stock/doctype/package_item/package_item.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -# import frappe -from frappe.model.document import Document - - -class PackageItem(Document): - pass diff --git a/erpnext/stock/doctype/package_item/test_package_item.py b/erpnext/stock/doctype/package_item/test_package_item.py deleted file mode 100644 index 6dcc9cbfe9..0000000000 --- a/erpnext/stock/doctype/package_item/test_package_item.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -# import frappe -from frappe.tests.utils import FrappeTestCase - - -class TestPackageItem(FrappeTestCase): - pass diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index afcc6768a9..0624ae94a7 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -52,10 +52,13 @@ class SerialandBatchBundle(Document): if ( not serial_no_warehouse.get(serial_no) or serial_no_warehouse.get(serial_no) != self.warehouse ): - frappe.throw( - _(f"Serial No {bold(serial_no)} is not present in the warehouse {bold(self.warehouse)}.") + self.throw_error_message( + f"Serial No {bold(serial_no)} is not present in the warehouse {bold(self.warehouse)}." ) + def throw_error_message(self, message): + frappe.throw(_(message), title=_("Error")) + def set_incoming_rate(self, row=None, save=False): if self.type_of_transaction == "Outward": self.set_incoming_rate_for_outward_transaction(row, save) @@ -223,10 +226,10 @@ class SerialandBatchBundle(Document): return if self.voucher_no and not frappe.db.exists(self.voucher_type, self.voucher_no): - frappe.throw(_(f"The {self.voucher_type} # {self.voucher_no} does not exist")) + self.throw_error_message(f"The {self.voucher_type} # {self.voucher_no} does not exist") if frappe.get_cached_value(self.voucher_type, self.voucher_no, "docstatus") != 1: - frappe.throw(_(f"The {self.voucher_type} # {self.voucher_no} should be submit first.")) + self.throw_error_message(f"The {self.voucher_type} # {self.voucher_no} should be submit first.") def check_future_entries_exists(self): if not self.has_serial_no: @@ -286,10 +289,8 @@ class SerialandBatchBundle(Document): qty_field = "consumed_qty" if abs(flt(self.total_qty, precision)) - abs(flt(row.get(qty_field), precision)) > 0.01: - frappe.throw( - _( - f"Total quantity {self.total_qty} in the Serial and Batch Bundle {self.name} does not match with the Item {self.item_code} in the {self.voucher_type} # {self.voucher_no}" - ) + self.throw_error_message( + f"Total quantity {self.total_qty} in the Serial and Batch Bundle {self.name} does not match with the Item {self.item_code} in the {self.voucher_type} # {self.voucher_no}" ) def set_is_outward(self): @@ -364,12 +365,12 @@ class SerialandBatchBundle(Document): if serial_nos: for key, value in collections.Counter(serial_nos).items(): if value > 1: - frappe.throw(_(f"Duplicate Serial No {key} found")) + self.throw_error_message(f"Duplicate Serial No {key} found") if batch_nos: for key, value in collections.Counter(batch_nos).items(): if value > 1: - frappe.throw(_(f"Duplicate Batch No {key} found")) + self.throw_error_message(f"Duplicate Batch No {key} found") def before_cancel(self): self.delink_serial_and_batch_bundle() diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 03c40ebdd6..64684d990f 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -133,17 +133,6 @@ def get_items_html(serial_nos, item_code): ) -def get_item_details(item_code): - return frappe.db.sql( - """select name, has_batch_no, docstatus, - is_stock_item, has_serial_no, serial_no_series, description, item_name, - item_group, stock_uom - from tabItem where name=%s""", - item_code, - as_dict=True, - )[0] - - def get_serial_nos(serial_no): if isinstance(serial_no, list): return serial_no diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 8ba8d11f11..fb5a93c191 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -900,6 +900,8 @@ class StockEntry(StockController): def make_serial_and_batch_bundle_for_outward(self): serial_or_batch_items = get_serial_or_batch_items(self.items) + if not serial_or_batch_items: + return for row in self.items: if row.serial_and_batch_bundle or row.item_code not in serial_or_batch_items: diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 35d7661c54..cdb3e5f6b3 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -90,20 +90,20 @@ class StockLedgerEntry(Document): self.db_set(values_to_be_change) if not item_detail: - frappe.throw(_("Item {0} not found").format(self.item_code)) + self.throw_error_message(f"Item {self.item_code} not found") if item_detail.has_variants: - frappe.throw( - _("Stock cannot exist for Item {0} since has variants").format(self.item_code), + self.throw_error_message( + f"Stock cannot exist for Item {self.item_code} since has variants", ItemTemplateCannotHaveStock, ) if item_detail.is_stock_item != 1: - frappe.throw(_("Item {0} must be a stock Item").format(self.item_code)) + self.throw_error_message("Item {0} must be a stock Item").format(self.item_code) if item_detail.has_serial_no or item_detail.has_batch_no: if not self.serial_and_batch_bundle: - frappe.throw(_(f"Serial No / Batch No are mandatory for Item {self.item_code}")) + self.throw_error_message(f"Serial No / Batch No are mandatory for Item {self.item_code}") else: bundle_data = frappe.get_cached_value( "Serial and Batch Bundle", self.serial_and_batch_bundle, ["item_code", "docstatus"], as_dict=1 @@ -113,7 +113,10 @@ class StockLedgerEntry(Document): self.submit_serial_and_batch_bundle() if self.serial_and_batch_bundle and not (item_detail.has_serial_no or item_detail.has_batch_no): - frappe.throw(_(f"Serial No and Batch No are not allowed for Item {self.item_code}")) + self.throw_error_message(f"Serial No and Batch No are not allowed for Item {self.item_code}") + + def throw_error_message(self, message, exception=frappe.ValidationError): + frappe.throw(_(message), exception) def submit_serial_and_batch_bundle(self): doc = frappe.get_doc("Serial and Batch Bundle", self.serial_and_batch_bundle)