fix: Patch to set status in old serial no data (#21721)

* fix: Patch to set status in old serial no data

* fix: Avoid get_doc in patch

* fix: fetch all values and check status in one query
This commit is contained in:
Marica
2020-05-18 11:18:56 +05:30
committed by GitHub
parent 9b08258955
commit 395da09dae
2 changed files with 18 additions and 0 deletions

View File

@@ -665,3 +665,4 @@ erpnext.patches.v13_0.move_tax_slabs_from_payroll_period_to_income_tax_slab #123
erpnext.patches.v12_0.remove_duplicate_leave_ledger_entries
execute:frappe.delete_doc_if_exists("Page", "appointment-analytic")
erpnext.patches.v12_0.unset_customer_supplier_based_on_type_of_item_price
erpnext.patches.v12_0.set_serial_no_status

View File

@@ -0,0 +1,17 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import getdate, nowdate
def execute():
frappe.reload_doc('stock', 'doctype', 'serial_no')
for serial_no in frappe.db.sql("""select name, delivery_document_type, warranty_expiry_date from `tabSerial No`
where (status is NULL OR status='')""", as_dict = 1):
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"
else:
status = "Active"
frappe.db.set_value("Serial No", serial_no.get("name"), "status", status)