mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
Pulled and merged from master
This commit is contained in:
@@ -37,7 +37,10 @@ class DocType:
|
||||
self.doc.projected_qty = flt(self.doc.actual_qty) + flt(self.doc.ordered_qty) + flt(self.doc.indented_qty) + flt(self.doc.planned_qty) - flt(self.doc.reserved_qty)
|
||||
|
||||
self.doc.save()
|
||||
|
||||
|
||||
# check actual qty with total number of serial no
|
||||
self.check_qty_with_serial_no()
|
||||
|
||||
# update valuation for post dated entry
|
||||
if actual_qty:
|
||||
prev_sle = self.get_prev_sle(dt, posting_time, sle_id)
|
||||
@@ -48,6 +51,18 @@ class DocType:
|
||||
|
||||
self.update_item_valuation(sle_id, dt, posting_time, serial_no, prev_sle)
|
||||
|
||||
def check_qty_with_serial_no(self):
|
||||
"""
|
||||
check actual qty with total number of serial no in store
|
||||
Temporary validation added on: 18-07-2011
|
||||
"""
|
||||
if sql("select name from `tabItem` where ifnull(has_serial_no, 'No') = 'Yes' and name = '%s'" % self.doc.item_code):
|
||||
sr_count = sql("select count(name) from `tabSerial No` where item_code = '%s' and warehouse = '%s' and status ='In Store' and docstatus != 2" % (self.doc.item_code, self.doc.warehouse))[0][0]
|
||||
if sr_count != self.doc.actual_qty:
|
||||
msg = "Actual Qty in Bin is mismatched with total number of serial no in store for item: '%s' and warehouse: '%s'" % (self.doc.item_code, self.doc.warehouse)
|
||||
msgprint(msg, raise_exception=1)
|
||||
sendmail(['developer@iwebnotes.com'], sender='automail@webnotestech.com', subject='Serial No Count vs Bin Actual Qty', parts=[['text/plain', msg]])
|
||||
|
||||
# --------------------------------
|
||||
# get first stock ledger entry
|
||||
# --------------------------------
|
||||
|
||||
@@ -176,7 +176,7 @@ Total Available Qty: %s
|
||||
'description' : file and file[0]['description'] or ''
|
||||
|
||||
}
|
||||
return str(ret)
|
||||
return ret
|
||||
|
||||
def check_if_sle_exists(self):
|
||||
"""
|
||||
|
||||
@@ -7,15 +7,16 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
||||
|
||||
// ************************************** refresh ***************************************************
|
||||
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
if(!doc.__islocal && doc.warehouse) set_field_permlevel('warehouse', 1);
|
||||
if(!doc.__islocal && doc.item_code) set_field_permlevel('item_code', 1);
|
||||
if(doc.__islocal) set_field_permlevel('status', 0);
|
||||
if(!doc.__islocal) {
|
||||
flds = ['item_code', 'warehouse', 'purchase_document_type', 'purchase_document_no', 'purchase_date', 'purchase_time', 'purchase_rate', 'supplier']
|
||||
for(i=0;i<flds.length;i++)
|
||||
set_field_permlevel(flds[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************** triggers **************************************************
|
||||
|
||||
// -------------
|
||||
// item details
|
||||
// -------------
|
||||
cur_frm.add_fetch('item_code', 'item_name', 'item_name')
|
||||
@@ -24,23 +25,12 @@ cur_frm.add_fetch('item_code', 'brand', 'brand')
|
||||
cur_frm.add_fetch('item_code', 'description', 'description')
|
||||
cur_frm.add_fetch('item_code', 'warranty_period', 'warranty_period')
|
||||
|
||||
|
||||
// ---------
|
||||
// customer
|
||||
// ---------
|
||||
cur_frm.add_fetch('customer', 'customer_name', 'customer_name')
|
||||
cur_frm.add_fetch('customer', 'address', 'delivery_address')
|
||||
cur_frm.add_fetch('customer', 'territory', 'territory')
|
||||
|
||||
|
||||
// ---------
|
||||
// supplier
|
||||
// ---------
|
||||
//cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name')
|
||||
//cur_frm.add_fetch('customer', 'address', 'supplier_address')
|
||||
|
||||
|
||||
// ----------
|
||||
// territory
|
||||
// ----------
|
||||
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
|
||||
@@ -48,10 +38,8 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
|
||||
}
|
||||
|
||||
// Supplier
|
||||
//-------------
|
||||
cur_frm.cscript.supplier = function(doc,dt,dn) {
|
||||
if(doc.supplier) get_server_fields('get_default_supplier_address', JSON.stringify({supplier: doc.supplier}),'', doc, dt, dn, 1);
|
||||
if(doc.supplier) unhide_field(['supplier_name','address_display']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,39 +16,19 @@ class DocType(TransactionBase):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
|
||||
|
||||
# ********************************* validate warranty / amc status ***************************************
|
||||
|
||||
# --------------------
|
||||
# validate amc status
|
||||
# --------------------
|
||||
def validate_amc_status(self):
|
||||
if self.doc.amc_expiry_date and getdate(self.doc.amc_expiry_date) >= datetime.date.today() and self.doc.maintenance_status == 'Out of AMC':
|
||||
msgprint("AMC expiry date and maintenance status mismatch. Please verify")
|
||||
raise Exception
|
||||
elif (not self.doc.amc_expiry_date or getdate(self.doc.amc_expiry_date) < datetime.date.today()) and self.doc.maintenance_status == 'Under AMC':
|
||||
msgprint("AMC expiry date and maintenance status mismatch. Please verify")
|
||||
raise Exception
|
||||
"""
|
||||
validate amc status
|
||||
"""
|
||||
if (self.doc.maintenance_status == 'Out of AMC' and self.doc.amc_expiry_date and getdate(self.doc.amc_expiry_date) >= datetime.date.today()) or (self.doc.maintenance_status == 'Under AMC' and (not self.doc.amc_expiry_date or getdate(self.doc.amc_expiry_date) < datetime.date.today())):
|
||||
msgprint("AMC expiry date and maintenance status mismatch. Please verify", raise_exception=1)
|
||||
|
||||
|
||||
# -------------------------
|
||||
# validate warranty status
|
||||
# -------------------------
|
||||
def validate_warranty_status(self):
|
||||
if self.doc.warranty_expiry_date and getdate(self.doc.warranty_expiry_date) >= datetime.date.today() and self.doc.maintenance_status == 'Out of Warranty':
|
||||
msgprint("Warranty expiry date and maintenance status mismatch. Please verify")
|
||||
raise Exception
|
||||
elif (not self.doc.warranty_expiry_date or getdate(self.doc.warranty_expiry_date) < datetime.date.today()) and self.doc.maintenance_status == 'Under Warranty':
|
||||
msgprint("Warranty expiry date and maintenance status mismatch. Please verify")
|
||||
raise Exception
|
||||
|
||||
|
||||
# -------------------------------
|
||||
# validate warranty / amc status
|
||||
# -------------------------------
|
||||
def validate_warranty_amc_status(self):
|
||||
self.validate_warranty_status()
|
||||
self.validate_amc_status()
|
||||
"""
|
||||
validate warranty status
|
||||
"""
|
||||
if (self.doc.maintenance_status == 'Out of Warranty' and self.doc.warranty_expiry_date and getdate(self.doc.warranty_expiry_date) >= datetime.date.today()) or (self.doc.maintenance_status == 'Under Warranty' and (not self.doc.warranty_expiry_date or getdate(self.doc.warranty_expiry_date) < datetime.date.today())):
|
||||
msgprint("Warranty expiry date and maintenance status mismatch. Please verify", raise_exception=1)
|
||||
|
||||
|
||||
def validate_warehouse(self):
|
||||
@@ -56,6 +36,9 @@ class DocType(TransactionBase):
|
||||
msgprint("Warehouse is mandatory if this Serial No is <b>In Store</b>", raise_exception=1)
|
||||
|
||||
def validate_item(self):
|
||||
"""
|
||||
Validate whether serial no is required for this item
|
||||
"""
|
||||
item = sql("select name, has_serial_no from tabItem where name = '%s'" % self.doc.item_code)
|
||||
if not item:
|
||||
msgprint("Item is not exists in the system", raise_exception=1)
|
||||
@@ -67,7 +50,8 @@ class DocType(TransactionBase):
|
||||
# validate
|
||||
# ---------
|
||||
def validate(self):
|
||||
self.validate_warranty_amc_status()
|
||||
self.validate_warranty_status()
|
||||
self.validate_amc_status()
|
||||
self.validate_warehouse()
|
||||
self.validate_item()
|
||||
|
||||
@@ -102,7 +86,7 @@ class DocType(TransactionBase):
|
||||
# on update
|
||||
# ----------
|
||||
def on_update(self):
|
||||
if self.doc.warehouse and not sql("select name from `tabStock Ledger Entry` where serial_no = '%s'" % (self.doc.name)) and self.doc.status == 'In Store':
|
||||
if self.doc.localname and self.doc.warehouse and self.doc.status == 'In Store' and not sql("select name from `tabStock Ledger Entry` where serial_no = '%s' and ifnull(is_cancelled, 'No') = 'No'" % (self.doc.name)):
|
||||
self.make_stock_ledger_entry(update_stock = 1)
|
||||
|
||||
|
||||
|
||||
@@ -355,6 +355,9 @@ class DocType:
|
||||
# ----------------------------------
|
||||
def update_serial_no(self, is_submit):
|
||||
sl_obj = get_obj('Stock Ledger')
|
||||
if is_submit:
|
||||
sl_obj.validate_serial_no_warehouse(self, 'mtn_details')
|
||||
|
||||
for d in getlist(self.doclist, 'mtn_details'):
|
||||
if d.serial_no:
|
||||
serial_nos = sl_obj.get_sr_no_list(d.serial_no)
|
||||
@@ -363,7 +366,7 @@ class DocType:
|
||||
if d.s_warehouse:
|
||||
sl_obj.update_serial_delivery_details(self, d, serial_no, is_submit)
|
||||
if d.t_warehouse:
|
||||
sl_obj.update_serial_purchase_details(self, d, serial_no, is_submit, (self.doc.purpose in ['Material Transfer', 'Sales Return']) and 1 or 0)
|
||||
sl_obj.update_serial_purchase_details(self, d, serial_no, is_submit, self.doc.purpose)
|
||||
|
||||
if self.doc.purpose == 'Purchase Return':
|
||||
delete_doc("Serial No", serial_no)
|
||||
|
||||
@@ -57,11 +57,11 @@ class DocType:
|
||||
s = s.strip()
|
||||
sr_war = sql("select warehouse,name from `tabSerial No` where name = '%s'" % (s))
|
||||
if not sr_war:
|
||||
msgprint("Serial No %s does not exists",s, raise_exception = 1)
|
||||
msgprint("Serial No %s does not exists"%s, raise_exception = 1)
|
||||
elif not sr_war[0][0]:
|
||||
msgprint("Please set a warehouse in the Serial No <b>%s</b>" % s, raise_exception = 1)
|
||||
elif sr_war[0][0] != d.warehouse:
|
||||
msgprint("Serial No : %s for Item : %s doesn't exists in Warehouse : %s" % (s, d.item_code, d.warehouse), raise_exception = 1)
|
||||
msgprint("Warehouse not mentioned in the Serial No <b>%s</b>" % s, raise_exception = 1)
|
||||
elif (d.warehouse and sr_war[0][0] != d.warehouse) or (d.s_warehouse and sr_war[0][0] != d.s_warehouse):
|
||||
msgprint("Serial No : %s for Item : %s doesn't exists in Warehouse : %s" % (s, d.item_code, d.warehouse or d.s_warehouse), raise_exception = 1)
|
||||
|
||||
|
||||
# ------------------------------------
|
||||
@@ -119,10 +119,10 @@ class DocType:
|
||||
# ----------------------------------
|
||||
# update serial no purchase details
|
||||
# ----------------------------------
|
||||
def update_serial_purchase_details(self, obj, d, serial_no, is_submit, is_transfer = 0):
|
||||
def update_serial_purchase_details(self, obj, d, serial_no, is_submit, purpose = ''):
|
||||
exists = sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no))
|
||||
if is_submit:
|
||||
if exists and exists[0][2] != 2 and not is_transfer:
|
||||
if exists and exists[0][2] != 2 and purpose not in ['Material Transfer', 'Sales Return']:
|
||||
msgprint("Serial No: %s already %s" % (serial_no, exists and exists[0][1]), raise_exception = 1)
|
||||
elif exists:
|
||||
s = Document('Serial No', exists and exists[0][0])
|
||||
@@ -133,8 +133,10 @@ class DocType:
|
||||
else:
|
||||
if exists and exists[0][1] == 'Delivered' and exists[0][2] != 2:
|
||||
msgprint("Serial No: %s is already delivered, you can not cancel the document." % serial_no, raise_exception=1)
|
||||
elif purpose in ['Material Transfer', 'Sales Return']:
|
||||
sql("update `tabSerial No` set status = '%s', purchase_document_type = '', purchase_document_no = '', warehouse = '%s' where name = '%s'" % (purpose == 'Material Transfer' and 'In Store' or 'Delivered', d.s_warehouse, serial_no))
|
||||
else:
|
||||
sql("update `tabSerial No` set docstatus = '%s', status = '%s', purchase_document_type = '', purchase_document_no = '', purchase_date = '', purchase_rate = '', supplier = null, supplier_name = '', supplier_address = '', warehouse = null where name = '%s'" % (not is_transfer and 2 or 0, is_transfer and 'In Store' or 'Not in Use', serial_no))
|
||||
sql("update `tabSerial No` set docstatus = 2, status = 'Not in Use', purchase_document_type = '', purchase_document_no = '', purchase_date = '', purchase_rate = '', supplier = null, supplier_name = '', supplier_address = '', warehouse = '' where name = '%s'" % serial_no)
|
||||
|
||||
|
||||
# -------------------------------
|
||||
@@ -233,6 +235,7 @@ class DocType:
|
||||
sle.fields['warehouse_type'] = get_value('Warehouse' , args[k], 'warehouse_type')
|
||||
sle.fields[k] = args[k]
|
||||
sle_obj = get_obj(doc=sle)
|
||||
|
||||
# validate
|
||||
sle_obj.validate()
|
||||
sle.save(new = 1)
|
||||
|
||||
Reference in New Issue
Block a user