diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 4d0520abc8..de76e45cd1 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -69,16 +69,16 @@ status_map = { ["Cancelled", "eval:self.docstatus==2"], ["Closed", "eval:self.status=='Closed'"], ], - "Purchase Invoice": [ - ["Draft", None], - ["Submitted", "eval:self.docstatus==1"], - ["Paid", "eval:self.outstanding_amount==0 and self.docstatus==1"], - ["Return", "eval:self.is_return==1 and self.docstatus==1"], - ["Debit Note Issued", - "eval:self.outstanding_amount <= 0 and self.docstatus==1 and self.is_return==0 and get_value('Purchase Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1})"], - ["Unpaid", "eval:self.outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.docstatus==1"], - ["Overdue", "eval:self.outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.docstatus==1"], - ["Cancelled", "eval:self.docstatus==2"], + "Purchase Invoice": [ + ["Draft", None], + ["Submitted", "eval:self.docstatus==1"], + ["Paid", "eval:self.outstanding_amount==0 and self.docstatus==1"], + ["Return", "eval:self.is_return==1 and self.docstatus==1"], + ["Debit Note Issued", + "eval:self.outstanding_amount <= 0 and self.docstatus==1 and self.is_return==0 and get_value('Purchase Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1})"], + ["Unpaid", "eval:self.outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.docstatus==1"], + ["Overdue", "eval:self.outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.docstatus==1"], + ["Cancelled", "eval:self.docstatus==2"], ], "Material Request": [ ["Draft", None], diff --git a/erpnext/stock/doctype/serial_no/serial_no.json b/erpnext/stock/doctype/serial_no/serial_no.json index fb28b5c079..731a730279 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.json +++ b/erpnext/stock/doctype/serial_no/serial_no.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_import": 1, "allow_rename": 1, "autoname": "field:serial_no", @@ -41,7 +42,6 @@ "delivery_document_no", "delivery_date", "delivery_time", - "is_cancelled", "column_break5", "customer", "customer_name", @@ -56,7 +56,8 @@ "warranty_period", "more_info", "serial_no_details", - "company" + "company", + "status" ], "fields": [ { @@ -306,16 +307,6 @@ "no_copy": 1, "read_only": 1 }, - { - "fieldname": "is_cancelled", - "fieldtype": "Select", - "hidden": 1, - "label": "Is Cancelled", - "oldfieldname": "is_cancelled", - "oldfieldtype": "Select", - "options": "\nYes\nNo", - "report_hide": 1 - }, { "fieldname": "column_break5", "fieldtype": "Column Break", @@ -423,11 +414,20 @@ "remember_last_selected_value": 1, "reqd": 1, "search_index": 1 + }, + { + "fieldname": "status", + "fieldtype": "Select", + "in_standard_filter": 1, + "label": "Status", + "options": "\nActive\nDelivered\nExpired", + "read_only": 1 } ], "icon": "fa fa-barcode", "idx": 1, - "modified": "2020-02-28 19:31:09.357323", + "links": [], + "modified": "2020-04-08 13:29:58.517772", "modified_by": "Administrator", "module": "Stock", "name": "Serial No", diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 772ac58af6..b32c709be3 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -35,6 +35,15 @@ class SerialNo(StockController): self.set_maintenance_status() self.validate_warehouse() self.validate_item() + self.set_status() + + def set_status(self): + if self.delivery_document_type: + self.status = "Delivered" + elif self.warranty_expiry_date and getdate(self.warranty_expiry_date) <= getdate(nowdate()): + self.status = "Expired" + else: + self.status = "Active" def set_maintenance_status(self): if not self.warranty_expiry_date and not self.amc_expiry_date: @@ -197,6 +206,7 @@ class SerialNo(StockController): self.set_purchase_details(last_sle.get("purchase_sle")) self.set_sales_details(last_sle.get("delivery_sle")) self.set_maintenance_status() + self.set_status() def process_serial_no(sle): item_det = get_item_details(sle.item_code) diff --git a/erpnext/stock/doctype/serial_no/serial_no_list.js b/erpnext/stock/doctype/serial_no/serial_no_list.js index 5b1e312f68..651f790583 100644 --- a/erpnext/stock/doctype/serial_no/serial_no_list.js +++ b/erpnext/stock/doctype/serial_no/serial_no_list.js @@ -1,14 +1,12 @@ frappe.listview_settings['Serial No'] = { - add_fields: ["is_cancelled", "item_code", "warehouse", "warranty_expiry_date", "delivery_document_type"], + add_fields: ["item_code", "warehouse", "warranty_expiry_date", "delivery_document_type"], get_indicator: (doc) => { - if (doc.is_cancelled) { - return [__("Cancelled"), "red", "is_cancelled,=,Yes"]; - } else if (doc.delivery_document_type) { - return [__("Delivered"), "green", "delivery_document_type,is,set|is_cancelled,=,No"]; + if (doc.delivery_document_type) { + return [__("Delivered"), "green", "delivery_document_type,is,set"]; } else if (doc.warranty_expiry_date && frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0) { - return [__("Expired"), "red", "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set|is_cancelled,=,No"]; + return [__("Expired"), "red", "warranty_expiry_date,not in,|warranty_expiry_date,<=,Today|delivery_document_type,is,not set"]; } else { - return [__("Active"), "green", "delivery_document_type,is,not set|is_cancelled,=,No"]; + return [__("Active"), "green", "delivery_document_type,is,not set"]; } } }; 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 45ed498a28..0d3e33164a 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -45,7 +45,7 @@ class StockLedgerEntry(Document): def calculate_batch_qty(self): if self.batch_no: - batch_qty = frappe.db.get_value("Stock Ledger Entry", + batch_qty = frappe.db.get_value("Stock Ledger Entry", {"docstatus": 1, "batch_no": self.batch_no, "is_cancelled": "No"}, "sum(actual_qty)") or 0 frappe.db.set_value("Batch", self.batch_no, "batch_qty", batch_qty)