2020-05-18 05:48:44 +00:00
|
|
|
from __future__ import unicode_literals
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-05-18 05:48:44 +00:00
|
|
|
import frappe
|
|
|
|
from frappe.utils import getdate, nowdate
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-05-18 05:48:44 +00:00
|
|
|
def execute():
|
|
|
|
frappe.reload_doc('stock', 'doctype', 'serial_no')
|
|
|
|
|
2020-05-22 05:18:35 +00:00
|
|
|
serial_no_list = frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date, warehouse from `tabSerial No`
|
2020-05-21 13:12:10 +00:00
|
|
|
where (status is NULL OR status='')""", as_dict = 1)
|
|
|
|
if len(serial_no_list) > 20000:
|
|
|
|
frappe.db.auto_commit_on_many_writes = True
|
|
|
|
|
|
|
|
for serial_no in serial_no_list:
|
2020-05-18 05:48:44 +00:00
|
|
|
if serial_no.get("delivery_document_type"):
|
|
|
|
status = "Delivered"
|
|
|
|
elif serial_no.get("warranty_expiry_date") and getdate(serial_no.get("warranty_expiry_date")) <= getdate(nowdate()):
|
|
|
|
status = "Expired"
|
2020-05-22 05:18:35 +00:00
|
|
|
elif not serial_no.get("warehouse"):
|
|
|
|
status = "Inactive"
|
2020-05-18 05:48:44 +00:00
|
|
|
else:
|
|
|
|
status = "Active"
|
|
|
|
|
2020-05-21 13:12:10 +00:00
|
|
|
frappe.db.set_value("Serial No", serial_no.get("name"), "status", status)
|
|
|
|
|
|
|
|
if frappe.db.auto_commit_on_many_writes:
|
|
|
|
frappe.db.auto_commit_on_many_writes = False
|