BOM Related changes (1.Unset as Default BOM, 2.Flat BOM Repair 3.delete_doc issue)
This commit is contained in:
parent
7cd48f1d59
commit
b77bfdb990
@ -19,9 +19,9 @@ $.extend(cur_frm.cscript, {
|
|||||||
},
|
},
|
||||||
hide_show_buttons: function(doc) {
|
hide_show_buttons: function(doc) {
|
||||||
if(doc.docstatus==0) {
|
if(doc.docstatus==0) {
|
||||||
hide_field('Installment Reciept'); show_field('Generate');
|
hide_field('Installment Reciept'); unhide_field('Generate');
|
||||||
} else if (doc.docstatus==1) {
|
} else if (doc.docstatus==1) {
|
||||||
show_field('Installment Reciept');hide_field('Generate');
|
unhide_field('Installment Reciept');hide_field('Generate');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clear_installments: function(doc) {
|
clear_installments: function(doc) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
$import(Production Tips Common)
|
//$import(Production Tips Common)
|
||||||
|
|
||||||
// ONLOAD
|
// ONLOAD
|
||||||
cur_frm.cscript.onload = function(doc,cdt,cdn){
|
cur_frm.cscript.onload = function(doc,cdt,cdn){
|
||||||
@ -14,6 +14,8 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
|
|||||||
// Hide - Un Hide Buttons
|
// Hide - Un Hide Buttons
|
||||||
if (!doc.is_default && doc.__islocal!=1) unhide_field('Set as Default BOM');
|
if (!doc.is_default && doc.__islocal!=1) unhide_field('Set as Default BOM');
|
||||||
else hide_field('Set as Default BOM');
|
else hide_field('Set as Default BOM');
|
||||||
|
if (doc.is_default && doc.__islocal!=1) unhide_field('Unset as Default BOM');
|
||||||
|
else hide_field('Unset as Default BOM');
|
||||||
|
|
||||||
if(doc.__islocal!=1){
|
if(doc.__islocal!=1){
|
||||||
set_field_permlevel('item',1);
|
set_field_permlevel('item',1);
|
||||||
@ -76,12 +78,23 @@ cur_frm.cscript['Set as Default BOM'] = function(doc,cdt,cdn) {
|
|||||||
if (check) {
|
if (check) {
|
||||||
$c('runserverobj', args={'method':'set_as_default_bom', 'docs': compress_doclist([doc])}, function(r,rt) {
|
$c('runserverobj', args={'method':'set_as_default_bom', 'docs': compress_doclist([doc])}, function(r,rt) {
|
||||||
refresh_field('is_default');
|
refresh_field('is_default');
|
||||||
hide_field('Set as Default BOM');
|
hide_field('Set as Default BOM');unhide_field('Unset as Default BOM');
|
||||||
refresh_field('Set as Default BOM');
|
refresh_field('Set as Default BOM');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_frm.cscript['Unset as Default BOM'] = function(doc,cdt,cdn) {
|
||||||
|
var check = confirm("Do you Really want to Unset BOM " + doc.name + " as default for Item " + doc.item);
|
||||||
|
if (check) {
|
||||||
|
$c('runserverobj', args={'method':'unset_as_default_bom', 'docs': compress_doclist([doc])}, function(r,rt) {
|
||||||
|
refresh_field('is_default');
|
||||||
|
hide_field('Unset as Default BOM');unhide_field('Set as Default BOM');
|
||||||
|
refresh_field('Unset as Default BOM');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cur_frm.cscript['Activate BOM'] = function(doc,cdt,cdn) {
|
cur_frm.cscript['Activate BOM'] = function(doc,cdt,cdn) {
|
||||||
var check = confirm("DO YOU REALLY WANT TO ACTIVATE BOM : " + doc.name);
|
var check = confirm("DO YOU REALLY WANT TO ACTIVATE BOM : " + doc.name);
|
||||||
|
|
||||||
@ -92,6 +105,13 @@ cur_frm.cscript['Activate BOM'] = function(doc,cdt,cdn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_frm.cscript['Test Flat BOM'] = function(doc,cdt,cdn) {
|
||||||
|
|
||||||
|
$c('runserverobj', args={'method':'get_current_flat_bom_items', 'docs': compress_doclist(make_doclist(doc.doctype, doc.name))}, function(r,rt) {
|
||||||
|
cur_frm.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
cur_frm.cscript['Inactivate BOM'] = function(doc,cdt,cdn) {
|
cur_frm.cscript['Inactivate BOM'] = function(doc,cdt,cdn) {
|
||||||
var check = confirm("DO YOU REALLY WANT TO INACTIVATE BOM : " + doc.name);
|
var check = confirm("DO YOU REALLY WANT TO INACTIVATE BOM : " + doc.name);
|
||||||
|
|
||||||
|
@ -124,6 +124,14 @@ class DocType:
|
|||||||
sql("update `tabItem` set default_bom = '%s' where name = '%s'" % (self.doc.name,self.doc.item))
|
sql("update `tabItem` set default_bom = '%s' where name = '%s'" % (self.doc.name,self.doc.item))
|
||||||
msgprint(cstr(self.doc.name) + "has been set as Default BOM for Item "+cstr(self.doc.item))
|
msgprint(cstr(self.doc.name) + "has been set as Default BOM for Item "+cstr(self.doc.item))
|
||||||
|
|
||||||
|
def unset_as_default_bom(self):
|
||||||
|
# set Is Default as 1
|
||||||
|
set(self.doc,'is_default', flt(0))
|
||||||
|
|
||||||
|
# update current BOM as default bom in Item Master
|
||||||
|
sql("update `tabItem` set default_bom = null where name = '%s'" % (self.doc.item))
|
||||||
|
msgprint(cstr(self.doc.name) + "has been unset as Default BOM for Item "+cstr(self.doc.item))
|
||||||
|
|
||||||
def check_active_parent_boms(self):
|
def check_active_parent_boms(self):
|
||||||
act_pbom = sql("select distinct t1.parent from `tabBOM Material` t1, `tabBill Of Materials` t2 where t1.bom_no ='%s' and t2.name = t1.parent and t2.is_active = 'Yes' and t2.docstatus = 1 and t1.docstatus =1 " % self.doc.name )
|
act_pbom = sql("select distinct t1.parent from `tabBOM Material` t1, `tabBill Of Materials` t2 where t1.bom_no ='%s' and t2.name = t1.parent and t2.is_active = 'Yes' and t2.docstatus = 1 and t1.docstatus =1 " % self.doc.name )
|
||||||
if act_pbom and act_pbom[0][0]:
|
if act_pbom and act_pbom[0][0]:
|
||||||
@ -248,6 +256,7 @@ class DocType:
|
|||||||
o.operating_cost = flt(flt(o.time_in_mins)/60) * flt(o.hour_rate)
|
o.operating_cost = flt(flt(o.time_in_mins)/60) * flt(o.hour_rate)
|
||||||
if validate != 1:
|
if validate != 1:
|
||||||
o.save()
|
o.save()
|
||||||
|
msgprint('Operation saved')
|
||||||
|
|
||||||
op_cost = flt(op_cost) + flt(o.operating_cost)
|
op_cost = flt(op_cost) + flt(o.operating_cost)
|
||||||
|
|
||||||
@ -443,6 +452,7 @@ class DocType:
|
|||||||
|
|
||||||
#----- Document on Save function------
|
#----- Document on Save function------
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
#msgprint(len(getlist(self.doclist, 'bom_materials')))
|
||||||
self.validate_main_item()
|
self.validate_main_item()
|
||||||
self.validate_duplicate_items()
|
self.validate_duplicate_items()
|
||||||
self.calculate_cost(validate = 1)
|
self.calculate_cost(validate = 1)
|
||||||
@ -487,8 +497,10 @@ class DocType:
|
|||||||
#Get Child Flat BOM Items
|
#Get Child Flat BOM Items
|
||||||
#----------------------------------------
|
#----------------------------------------
|
||||||
def get_child_flat_bom_items(self, item, d):
|
def get_child_flat_bom_items(self, item, d):
|
||||||
|
|
||||||
child_flat_bom_items=[]
|
child_flat_bom_items=[]
|
||||||
if item and (item[0]['is_sub_contracted_item'] == 'Yes' or item[0]['is_pro_applicable'] == 'Yes'):
|
if item and (item[0]['is_sub_contracted_item'] == 'Yes' or item[0]['is_pro_applicable'] == 'Yes'):
|
||||||
|
|
||||||
child_flat_bom_items = sql("select item_code, description, qty_consumed_per_unit, stock_uom, moving_avg_rate, last_purchase_rate, standard_rate, '%s' as parent_bom, bom_mat_no, 'No' as is_pro_applicable from `tabFlat BOM Detail` where parent = '%s' and is_pro_applicable = 'No' and docstatus = 1" % ( d.bom_no, cstr(d.bom_no)))
|
child_flat_bom_items = sql("select item_code, description, qty_consumed_per_unit, stock_uom, moving_avg_rate, last_purchase_rate, standard_rate, '%s' as parent_bom, bom_mat_no, 'No' as is_pro_applicable from `tabFlat BOM Detail` where parent = '%s' and is_pro_applicable = 'No' and docstatus = 1" % ( d.bom_no, cstr(d.bom_no)))
|
||||||
self.cur_flat_bom_items.append([d.item_code, d.description, flt(d.qty), d.stock_uom, flt(d.moving_avg_rate), flt(d.amount_as_per_mar), flt(d.last_purchase_rate), flt(d.amount_as_per_lpr), flt(d.standard_rate), flt(d.amount_as_per_sr), flt(d.qty_consumed_per_unit), (item[0]['is_sub_contracted_item'] == 'Yes') and d.parent or d.bom_no, d.name, (item[0]['is_sub_contracted_item'] == 'Yes') and 'No' or 'Yes'])
|
self.cur_flat_bom_items.append([d.item_code, d.description, flt(d.qty), d.stock_uom, flt(d.moving_avg_rate), flt(d.amount_as_per_mar), flt(d.last_purchase_rate), flt(d.amount_as_per_lpr), flt(d.standard_rate), flt(d.amount_as_per_sr), flt(d.qty_consumed_per_unit), (item[0]['is_sub_contracted_item'] == 'Yes') and d.parent or d.bom_no, d.name, (item[0]['is_sub_contracted_item'] == 'Yes') and 'No' or 'Yes'])
|
||||||
|
|
||||||
@ -505,11 +517,13 @@ class DocType:
|
|||||||
# Get Current Flat BOM Items
|
# Get Current Flat BOM Items
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def get_current_flat_bom_items(self):
|
def get_current_flat_bom_items(self):
|
||||||
|
|
||||||
self.cur_flat_bom_items = []
|
self.cur_flat_bom_items = []
|
||||||
|
|
||||||
cfb_lbl = {'item_code': 0, 'description': 1, 'qty_consumed_per_unit': 2, 'stock_uom': 3, 'moving_avg_rate': 4, 'last_purchase_rate': 5, 'standard_rate': 6, 'parent_bom': 7, 'bom_mat_no': 8, 'is_pro_applicable': 9}
|
cfb_lbl = {'item_code': 0, 'description': 1, 'qty_consumed_per_unit': 2, 'stock_uom': 3, 'moving_avg_rate': 4, 'last_purchase_rate': 5, 'standard_rate': 6, 'parent_bom': 7, 'bom_mat_no': 8, 'is_pro_applicable': 9}
|
||||||
|
|
||||||
for d in getlist(self.doclist, 'bom_materials'):
|
for d in getlist(self.doclist, 'bom_materials'):
|
||||||
|
|
||||||
if d.bom_no:
|
if d.bom_no:
|
||||||
item = sql("select is_sub_contracted_item, is_pro_applicable from `tabItem` where name = '%s'" % d.item_code, as_dict = 1)
|
item = sql("select is_sub_contracted_item, is_pro_applicable from `tabItem` where name = '%s'" % d.item_code, as_dict = 1)
|
||||||
child_flat_bom_items = self.get_child_flat_bom_items(item,d)
|
child_flat_bom_items = self.get_child_flat_bom_items(item,d)
|
||||||
@ -533,7 +547,7 @@ class DocType:
|
|||||||
# On Submit
|
# On Submit
|
||||||
# -----------
|
# -----------
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.update_flat_bom_engine()
|
self.update_flat_bom_engine(1)
|
||||||
|
|
||||||
|
|
||||||
def get_parent_bom_list(self, bom_no):
|
def get_parent_bom_list(self, bom_no):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Please edit this list and import only required elements
|
# Please edit this list and import only required elements
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
|
from webnotes.utils import cint, flt
|
||||||
from webnotes.model import db_exists
|
from webnotes.model import db_exists
|
||||||
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
|
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
|
||||||
from webnotes.model.doclist import getlist, copy_doclist
|
from webnotes.model.doclist import getlist, copy_doclist
|
||||||
@ -44,18 +44,20 @@ class DocType:
|
|||||||
def get_operations(self,bom_no):
|
def get_operations(self,bom_no):
|
||||||
# reply = [ 'Operation',operation_no, opn_description,BOM NO , workstation, hour_rate, time_in_minutes, Total Direct Material, Total Operating Cost, Cost]
|
# reply = [ 'Operation',operation_no, opn_description,BOM NO , workstation, hour_rate, time_in_minutes, Total Direct Material, Total Operating Cost, Cost]
|
||||||
# reply = [ 0 , 1 , 2 ,3 , 4 , 5 , 6 , 7 , 8 ,9 , 10 , 11 ]
|
# reply = [ 0 , 1 , 2 ,3 , 4 , 5 , 6 , 7 , 8 ,9 , 10 , 11 ]
|
||||||
|
|
||||||
ret = sql("select operation_no,opn_description,workstation,hour_rate,time_in_mins from `tabBOM Operation` where parent = %s", bom_no, as_dict = 1)
|
ret = sql("select operation_no,opn_description,workstation,hour_rate,time_in_mins from `tabBOM Operation` where parent = %s", bom_no, as_dict = 1)
|
||||||
cost = sql("select dir_mat_as_per_mar , operating_cost , cost_as_per_mar from `tabBill Of Materials` where name = %s", bom_no, as_dict = 1)
|
cost = sql("select dir_mat_as_per_mar , operating_cost , cost_as_per_mar from `tabBill Of Materials` where name = %s", bom_no, as_dict = 1)
|
||||||
|
|
||||||
# Validate the BOM ENTRIES
|
# Validate the BOM ENTRIES
|
||||||
#check = get_obj('Bill Of Materials', bom_no, with_children =1).validate()
|
#check = get_obj('Bill Of Materials', bom_no, with_children =1).validate()
|
||||||
reply = []
|
reply = []
|
||||||
|
|
||||||
|
if ret:
|
||||||
for r in ret:
|
for r in ret:
|
||||||
reply.append(['operation',cint(r['operation_no']), r['opn_description'] or '','%s'% bom_no,r['workstation'],flt(r['hour_rate']),flt(r['time_in_mins']),0,0,0])
|
reply.append(['operation',cint(r['operation_no']), r['opn_description'] or '','%s'% bom_no,r['workstation'],flt(r['hour_rate']),flt(r['time_in_mins']),0,0,0])
|
||||||
|
|
||||||
reply[0][7]= flt(cost[0]['dir_mat_as_per_mar'])
|
reply[0][7]= flt(cost[0]['dir_mat_as_per_mar'])
|
||||||
reply[0][8]=flt(cost[0]['operating_cost'])
|
reply[0][8]=flt(cost[0]['operating_cost'])
|
||||||
reply[0][9]=flt(cost[0]['cost_as_per_mar'])
|
reply[0][9]=flt(cost[0]['cost_as_per_mar'])
|
||||||
#msgprint(bom_no)
|
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
def get_item_bom(self,data):
|
def get_item_bom(self,data):
|
||||||
@ -78,7 +80,6 @@ class DocType:
|
|||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#------------- Wrapper Code --------------
|
#------------- Wrapper Code --------------
|
||||||
# BOM TREE
|
# BOM TREE
|
||||||
def calculate_cost( self, bom_no):
|
def calculate_cost( self, bom_no):
|
||||||
|
@ -55,10 +55,12 @@ class DocType:
|
|||||||
serial_nos = self.get_sr_no_list(d.serial_no)
|
serial_nos = self.get_sr_no_list(d.serial_no)
|
||||||
for s in serial_nos:
|
for s in serial_nos:
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
sr_war = sql("select warehouse from `tabSerial No` where name = '%s'" % (s))
|
sr_war = sql("select warehouse,name from `tabSerial No` where name = '%s'" % (s))
|
||||||
if not sr_war:
|
if not sr_war:
|
||||||
|
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)
|
msgprint("Please set a warehouse in the Serial No <b>%s</b>" % s, raise_exception = 1)
|
||||||
if sr_war[0][0] != d.warehouse:
|
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("Serial No : %s for Item : %s doesn't exists in Warehouse : %s" % (s, d.item_code, d.warehouse), raise_exception = 1)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user