From 1290284c80322eda0e8f63352379d0df524da358 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 24 Jan 2013 13:23:20 +0530 Subject: [PATCH] validation fixes in mantenance schedule and error fixes in setting serial no warranty expiry date --- stock/doctype/stock_ledger/stock_ledger.py | 25 ++++++++-------- .../maintenance_schedule.py | 29 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py index 9f498d27e2..0c0e246a7d 100644 --- a/stock/doctype/stock_ledger/stock_ledger.py +++ b/stock/doctype/stock_ledger/stock_ledger.py @@ -17,7 +17,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cstr, flt, nowdate +from webnotes.utils import add_days, cstr, flt, nowdate, cint from webnotes.model.doc import Document from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj @@ -149,17 +149,18 @@ class DocType: s = Document('Serial No', serial_no) s.delivery_document_type = obj.doc.doctype s.delivery_document_no = obj.doc.name - s.delivery_date = obj.doc.posting_date - s.delivery_time = obj.doc.posting_time - s.customer = obj.doc.customer - s.customer_name = obj.doc.customer_name - s.delivery_address = obj.doc.address_display - s.territory = obj.doc.territory - s.warranty_expiry_date = s.warranty_period and add_days(cstr(obj.doc.posting_date), s.warranty_period) or '' - s.docstatus = 1 - s.status = 'Delivered' - s.modified = nowdate() - s.modified_by = session['user'] + s.delivery_date = obj.doc.posting_date + s.delivery_time = obj.doc.posting_time + s.customer = obj.doc.customer + s.customer_name = obj.doc.customer_name + s.delivery_address = obj.doc.address_display + s.territory = obj.doc.territory + s.warranty_expiry_date = cint(s.warranty_period) and \ + add_days(cstr(obj.doc.posting_date), cint(s.warranty_period)) or s.warranty_expiry_date + s.docstatus = 1 + s.status = 'Delivered' + s.modified = nowdate() + s.modified_by = session['user'] s.save() diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py index 6560c83598..6628c0bdf7 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -277,24 +277,21 @@ class DocType(TransactionBase): def on_update(self): webnotes.conn.set(self.doc, 'status', 'Draft') - #validate that new maintenance start date does not clash with existing mntc end date - #------------------------------------------------------------------------------------------------- def validate_serial_no_warranty(self): for d in getlist(self.doclist, 'item_maintenance_detail'): - if d.serial_no: - dt = sql("select warranty_expiry_date, amc_expiry_date from `tabSerial No` where name = %s", d.serial_no, as_dict=1) - - if dt[0]['warranty_expiry_date']: - if dt[0]['warranty_expiry_date'] >= getdate(d.start_date): - msgprint("Serial no "+d.serial_no+" for item "+d.item_code+" is already under warranty till "+(dt[0]['warranty_expiry_date']).strftime('%Y-%m-%d')+". You can schedule AMC start date after "+(dt[0]['warranty_expiry_date']).strftime('%Y-%m-%d')) - raise Exception - if dt[0]['amc_expiry_date']: - if dt[0]['amc_expiry_date'] >= getdate(d.start_date): - msgprint("Serial no "+d.serial_no+" for item "+d.item_code+" is already under AMC till "+(dt[0]['amc_expiry_date']).strftime('%Y-%m-%d')+". You can schedule new AMC start date after "+(dt[0]['amc_expiry_date']).strftime('%Y-%m-%d')) - raise Exception - - #validate if schedule generated for all items - #------------------------------------------------- + if d.serial_no.strip(): + dt = sql("""select warranty_expiry_date, amc_expiry_date + from `tabSerial No` where name = %s""", d.serial_no, as_dict=1) + if dt[0]['warranty_expiry_date'] and dt[0]['warranty_expiry_date'] >= d.start_date: + webnotes.msgprint("""Serial No: %s is already under warranty upto %s. + Please check AMC Start Date.""" % + (d.serial_no, dt[0]["warranty_expiry_date"]), raise_exception=1) + + if dt[0]['amc_expiry_date'] and dt[0]['amc_expiry_date'] >= d.start_date: + webnotes.msgprint("""Serial No: %s is already under AMC upto %s. + Please check AMC Start Date.""" % + (d.serial_no, sr[0]["amc_expiry_date"]), raise_exception=1) + def validate_schedule(self): item_lst1 =[] item_lst2 =[]