bom fixes: item selection before server call

This commit is contained in:
Nabin Hait 2012-12-05 12:36:19 +05:30
parent ff4d616133
commit 1ad42f09df
4 changed files with 44 additions and 32 deletions

View File

@ -162,7 +162,7 @@ cur_frm.cscript.update_stock = function(doc, dt, dn) {
cur_frm.cscript.warehouse = function(doc, cdt , cdn) { cur_frm.cscript.warehouse = function(doc, cdt , cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (!d.item_code) {alert("please enter item code first"); return}; if (!d.item_code) { msgprint("please enter item code first"); return };
if (d.warehouse) { if (d.warehouse) {
arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.warehouse +"'}"; arg = "{'item_code':'" + d.item_code + "','warehouse':'" + d.warehouse +"'}";
get_server_fields('get_actual_qty',arg,'entries',doc,cdt,cdn,1); get_server_fields('get_actual_qty',arg,'entries',doc,cdt,cdn,1);

View File

@ -902,7 +902,7 @@ def assign_task_to_owner(inv, msg, users):
def get_bank_cash_account(mode_of_payment): def get_bank_cash_account(mode_of_payment):
val = webnotes.conn.get_value("Mode of Payment", mode_of_payment, "default_account") val = webnotes.conn.get_value("Mode of Payment", mode_of_payment, "default_account")
if not val: if not val:
webnotes.msgprint("Default Account not set in Mode of Payment: ") webnotes.msgprint("Default Account not set in Mode of Payment: %s" % mode_of_payment)
return { return {
"cash_bank_account": val "cash_bank_account": val
} }

View File

@ -8,11 +8,11 @@
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// On REFRESH // On REFRESH
cur_frm.cscript.refresh = function(doc,dt,dn){ cur_frm.cscript.refresh = function(doc,dt,dn){
@ -50,33 +50,42 @@ cur_frm.cscript.hour_rate = function(doc, dt, dn) {
cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate; cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate;
cur_frm.cscript.item_code = function(doc,dt,dn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) {
get_bom_material_detail(doc, dt, dn); get_bom_material_detail(doc, cdt, cdn);
} }
cur_frm.cscript.bom_no = function(doc,dt,dn) { cur_frm.cscript.bom_no = function(doc, cdt, cdn) {
get_bom_material_detail(doc, dt, dn); get_bom_material_detail(doc, cdt, cdn);
} }
var get_bom_material_detail= function(doc, cdt, cdn) {
var get_bom_material_detail= function(doc,dt,dn) { var d = locals[cdt][cdn];
var d = locals[dt][dn];
var callback = function(doc, dt, dn) {
calculate_rm_cost(doc, dt, dn);
calculate_total(doc);
}
var bom_no = (d.bom_no!=null) ? d.bom_no: ''
if (d.item_code) { if (d.item_code) {
arg = {'item_code': d.item_code, 'bom_no': bom_no, 'qty': d.qty}; wn.call({
get_server_fields('get_bom_material_detail', JSON.stringify(arg), 'bom_materials', doc, dt, dn, 1, callback); doc: cur_frm.doc,
method: "get_bom_material_detail",
args: {
'item_code': d.item_code,
'bom_no': d.bom_no != null ? d.bom_no: '',
'qty': d.qty
},
callback: function(r) {
d = locals[cdt][cdn];
$.extend(d, r.message);
refresh_field("bom_materials");
doc = locals[doc.doctype][doc.name];
calculate_rm_cost(doc, cdt, cdn);
calculate_total(doc);
},
freeze: true
});
} }
} }
cur_frm.cscript.qty = function(doc, dt, dn) { cur_frm.cscript.qty = function(doc, cdt, cdn) {
calculate_rm_cost(doc, dt, dn); calculate_rm_cost(doc, cdt, cdn);
calculate_total(doc); calculate_total(doc);
} }
@ -84,9 +93,9 @@ cur_frm.cscript.qty = function(doc, dt, dn) {
cur_frm.cscript.rate = cur_frm.cscript.qty; cur_frm.cscript.rate = cur_frm.cscript.qty;
cur_frm.cscript.is_default = function(doc, dt, dn) { cur_frm.cscript.is_default = function(doc, cdt, cdn) {
if (doc.docstatus == 1) if (doc.docstatus == 1)
$c_obj(make_doclist(dt, dn), 'manage_default_bom', '', ''); $c_obj(make_doclist(cdt, cdn), 'manage_default_bom', '', '');
} }
@ -97,11 +106,11 @@ cur_frm.cscript.is_active = function(doc, dt, dn) {
// Calculate Operating Cost // Calculate Operating Cost
var calculate_op_cost = function(doc, dt, dn) { var calculate_op_cost = function(doc, dt, dn) {
var op = getchildren('BOM Operation', doc.name, 'bom_operations'); var op = getchildren('BOM Operation', doc.name, 'bom_operations');
total_op_cost = 0; total_op_cost = 0;
for(var i=0;i<op.length;i++) { for(var i=0;i<op.length;i++) {
op_cost = flt(op[i].hour_rate) * flt(op[i].time_in_mins) / 60; op_cost = flt(op[i].hour_rate) * flt(op[i].time_in_mins) / 60;
set_multiple('BOM Operation',op[i].name, {'operating_cost': op_cost}, 'bom_operations'); set_multiple('BOM Operation',op[i].name, {'operating_cost': op_cost}, 'bom_operations');
total_op_cost += op_cost; total_op_cost += op_cost;
} }
@ -111,11 +120,11 @@ var calculate_op_cost = function(doc, dt, dn) {
// Calculate Raw Material Cost // Calculate Raw Material Cost
var calculate_rm_cost = function(doc, dt, dn) { var calculate_rm_cost = function(doc, dt, dn) {
var rm = getchildren('BOM Item', doc.name, 'bom_materials'); var rm = getchildren('BOM Item', doc.name, 'bom_materials');
total_rm_cost = 0; total_rm_cost = 0;
for(var i=0;i<rm.length;i++) { for(var i=0;i<rm.length;i++) {
amt = flt(rm[i].rate) * flt(rm[i].qty); amt = flt(rm[i].rate) * flt(rm[i].qty);
set_multiple('BOM Item',rm[i].name, {'amount': amt}, 'bom_materials'); set_multiple('BOM Item',rm[i].name, {'amount': amt}, 'bom_materials');
set_multiple('BOM Item',rm[i].name, {'qty_consumed_per_unit': flt(rm[i].qty)/flt(doc.quantity)}, 'bom_materials'); set_multiple('BOM Item',rm[i].name, {'qty_consumed_per_unit': flt(rm[i].qty)/flt(doc.quantity)}, 'bom_materials');
total_rm_cost += amt; total_rm_cost += amt;

View File

@ -86,10 +86,13 @@ class DocType:
def get_bom_material_detail(self, arg): def get_bom_material_detail(self):
""" Get raw material details like uom, desc and rate""" """ Get raw material details like uom, desc and rate"""
arg = webnotes.form_dict.get('args')
import json import json
arg = json.loads(arg) arg = json.loads(arg)
item = self.get_item_det(arg['item_code']) item = self.get_item_det(arg['item_code'])
self.validate_rm_item(item) self.validate_rm_item(item)
@ -98,10 +101,10 @@ class DocType:
rate = self.get_rm_rate(arg) rate = self.get_rm_rate(arg)
ret_item = { ret_item = {
'description' : item and arg['description'] or '', 'description' : item and arg['description'] or '',
'stock_uom' : item and arg['stock_uom'] or '', 'stock_uom' : item and arg['stock_uom'] or '',
'bom_no' : arg['bom_no'], 'bom_no' : arg['bom_no'],
'rate' : rate 'rate' : rate
} }
return ret_item return ret_item