Merge pull request #21201 from marination/serial-no-status

fix: Added Status field in Serial No for filter and report builder
This commit is contained in:
Deepesh Garg 2020-04-10 20:48:06 +05:30 committed by GitHub
commit 5e274965cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 31 deletions

View File

@ -69,16 +69,16 @@ status_map = {
["Cancelled", "eval:self.docstatus==2"], ["Cancelled", "eval:self.docstatus==2"],
["Closed", "eval:self.status=='Closed'"], ["Closed", "eval:self.status=='Closed'"],
], ],
"Purchase Invoice": [ "Purchase Invoice": [
["Draft", None], ["Draft", None],
["Submitted", "eval:self.docstatus==1"], ["Submitted", "eval:self.docstatus==1"],
["Paid", "eval:self.outstanding_amount==0 and self.docstatus==1"], ["Paid", "eval:self.outstanding_amount==0 and self.docstatus==1"],
["Return", "eval:self.is_return==1 and self.docstatus==1"], ["Return", "eval:self.is_return==1 and self.docstatus==1"],
["Debit Note Issued", ["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})"], "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"], ["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"], ["Overdue", "eval:self.outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.docstatus==1"],
["Cancelled", "eval:self.docstatus==2"], ["Cancelled", "eval:self.docstatus==2"],
], ],
"Material Request": [ "Material Request": [
["Draft", None], ["Draft", None],

View File

@ -1,4 +1,5 @@
{ {
"actions": [],
"allow_import": 1, "allow_import": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "field:serial_no", "autoname": "field:serial_no",
@ -41,7 +42,6 @@
"delivery_document_no", "delivery_document_no",
"delivery_date", "delivery_date",
"delivery_time", "delivery_time",
"is_cancelled",
"column_break5", "column_break5",
"customer", "customer",
"customer_name", "customer_name",
@ -56,7 +56,8 @@
"warranty_period", "warranty_period",
"more_info", "more_info",
"serial_no_details", "serial_no_details",
"company" "company",
"status"
], ],
"fields": [ "fields": [
{ {
@ -306,16 +307,6 @@
"no_copy": 1, "no_copy": 1,
"read_only": 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", "fieldname": "column_break5",
"fieldtype": "Column Break", "fieldtype": "Column Break",
@ -423,11 +414,20 @@
"remember_last_selected_value": 1, "remember_last_selected_value": 1,
"reqd": 1, "reqd": 1,
"search_index": 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", "icon": "fa fa-barcode",
"idx": 1, "idx": 1,
"modified": "2020-02-28 19:31:09.357323", "links": [],
"modified": "2020-04-08 13:29:58.517772",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Serial No", "name": "Serial No",

View File

@ -35,6 +35,15 @@ class SerialNo(StockController):
self.set_maintenance_status() self.set_maintenance_status()
self.validate_warehouse() self.validate_warehouse()
self.validate_item() 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): def set_maintenance_status(self):
if not self.warranty_expiry_date and not self.amc_expiry_date: 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_purchase_details(last_sle.get("purchase_sle"))
self.set_sales_details(last_sle.get("delivery_sle")) self.set_sales_details(last_sle.get("delivery_sle"))
self.set_maintenance_status() self.set_maintenance_status()
self.set_status()
def process_serial_no(sle): def process_serial_no(sle):
item_det = get_item_details(sle.item_code) item_det = get_item_details(sle.item_code)

View File

@ -1,14 +1,12 @@
frappe.listview_settings['Serial No'] = { 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) => { get_indicator: (doc) => {
if (doc.is_cancelled) { if (doc.delivery_document_type) {
return [__("Cancelled"), "red", "is_cancelled,=,Yes"]; return [__("Delivered"), "green", "delivery_document_type,is,set"];
} else if (doc.delivery_document_type) {
return [__("Delivered"), "green", "delivery_document_type,is,set|is_cancelled,=,No"];
} else if (doc.warranty_expiry_date && frappe.datetime.get_diff(doc.warranty_expiry_date, frappe.datetime.nowdate()) <= 0) { } 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 { } else {
return [__("Active"), "green", "delivery_document_type,is,not set|is_cancelled,=,No"]; return [__("Active"), "green", "delivery_document_type,is,not set"];
} }
} }
}; };

View File

@ -45,7 +45,7 @@ class StockLedgerEntry(Document):
def calculate_batch_qty(self): def calculate_batch_qty(self):
if self.batch_no: 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"}, {"docstatus": 1, "batch_no": self.batch_no, "is_cancelled": "No"},
"sum(actual_qty)") or 0 "sum(actual_qty)") or 0
frappe.db.set_value("Batch", self.batch_no, "batch_qty", batch_qty) frappe.db.set_value("Batch", self.batch_no, "batch_qty", batch_qty)