Stock entry fixes: incoming rate, toggle display of bom related fields

This commit is contained in:
Nabin Hait 2015-03-03 18:26:58 +05:30
parent 57a5c71663
commit 652c7db6e8
3 changed files with 45 additions and 17 deletions

View File

@ -129,10 +129,14 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
}, },
get_items: function() { get_items: function() {
var me = this;
if(!this.frm.doc.fg_completed_qty || !this.frm.doc.bom_no)
frappe.throw(__("BOM and Manufacturing Quantity are required"));
if(this.frm.doc.production_order || this.frm.doc.bom_no) { if(this.frm.doc.production_order || this.frm.doc.bom_no) {
// if production order / bom is mentioned, get items // if production order / bom is mentioned, get items
return this.frm.call({ return this.frm.call({
doc: this.frm.doc, doc: me.frm.doc,
method: "get_items", method: "get_items",
callback: function(r) { callback: function(r) {
if(!r.exc) refresh_field("items"); if(!r.exc) refresh_field("items");
@ -161,8 +165,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
args: {production_order: this.frm.doc.production_order}, args: {production_order: this.frm.doc.production_order},
callback: function(r) { callback: function(r) {
if (!r.exc) { if (!r.exc) {
if (me.frm.doc.purpose == "Material Transfer" && !me.frm.doc.to_warehouse) if (me.frm.doc.purpose == "Material Transfer for Manufacture" && !me.frm.doc.to_warehouse)
me.frm.set_value("to_warehouse", r.message["wip_warehouse"]); me.frm.set_value("to_warehouse", r.message["wip_warehouse"]);
me.frm.set_value("from_bom", 1);
} }
} }
}); });
@ -353,6 +358,24 @@ cur_frm.cscript.toggle_related_fields = function(doc) {
cur_frm.cscript.toggle_enable_bom(); cur_frm.cscript.toggle_enable_bom();
if(doc.purpose == 'Purchase Return') {
doc.customer = doc.customer_name = doc.customer_address =
doc.delivery_note_no = doc.sales_invoice_no = null;
doc.bom_no = doc.production_order = doc.fg_completed_qty = null;
} else if(doc.purpose == 'Sales Return') {
doc.supplier=doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no=null;
doc.bom_no = doc.production_order = doc.fg_completed_qty = null;
} else if (doc.purpose == 'Subcontract') {
doc.customer = doc.customer_name = doc.customer_address =
doc.delivery_note_no = doc.sales_invoice_no = null;
} else {
doc.customer = doc.customer_name = doc.customer_address =
doc.delivery_note_no = doc.sales_invoice_no = doc.supplier =
doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null;
}
if(in_list(["Material Receipt", "Sales Return", "Purchase Return"], doc.purpose)) {
cur_frm.set_value("from_bom", 0);
}
} }
cur_frm.fields_dict['production_order'].get_query = function(doc) { cur_frm.fields_dict['production_order'].get_query = function(doc) {

View File

@ -141,6 +141,7 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "eval:in_list([\"Material Issue\", \"Material Transfer\", \"Manufacture\", \"Repack\", \t\t\t\t\t\"Subcontract\", \"Material Transfer for Manufacture\"], doc.purpose)",
"fieldname": "from_bom", "fieldname": "from_bom",
"fieldtype": "Check", "fieldtype": "Check",
"label": "From BOM", "label": "From BOM",
@ -201,7 +202,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "eval:!inList([\"Sales Return\", \"Purchase Return\"], doc.purpose)", "depends_on": "from_bom",
"fieldname": "bom_no", "fieldname": "bom_no",
"fieldtype": "Link", "fieldtype": "Link",
"label": "BOM No", "label": "BOM No",
@ -210,7 +211,7 @@
"read_only": 0 "read_only": 0
}, },
{ {
"depends_on": "eval:inList([\"Manufacture\", \"Repack\"], doc.purpose)", "depends_on": "from_bom",
"fieldname": "additional_operating_cost", "fieldname": "additional_operating_cost",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Additional Operating Cost", "label": "Additional Operating Cost",
@ -227,7 +228,7 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"depends_on": "eval:!inList([\"Sales Return\", \"Purchase Return\"], doc.purpose)", "depends_on": "from_bom",
"description": "As per Stock UOM", "description": "As per Stock UOM",
"fieldname": "fg_completed_qty", "fieldname": "fg_completed_qty",
"fieldtype": "Float", "fieldtype": "Float",
@ -246,7 +247,7 @@
}, },
{ {
"default": "1", "default": "1",
"depends_on": "eval:!inList([\"Sales Return\", \"Purchase Return\"], doc.purpose)", "depends_on": "from_bom",
"description": "Including items for sub assemblies", "description": "Including items for sub assemblies",
"fieldname": "use_multi_level_bom", "fieldname": "use_multi_level_bom",
"fieldtype": "Check", "fieldtype": "Check",
@ -257,7 +258,7 @@
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"depends_on": "eval:!inList([\"Sales Return\", \"Purchase Return\"], doc.purpose)", "depends_on": "from_bom",
"fieldname": "get_items", "fieldname": "get_items",
"fieldtype": "Button", "fieldtype": "Button",
"hidden": 0, "hidden": 0,
@ -669,7 +670,7 @@
"is_submittable": 1, "is_submittable": 1,
"issingle": 0, "issingle": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2015-03-03 01:53:07.157141", "modified": "2015-03-03 18:09:12.035606",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Stock Entry", "name": "Stock Entry",

View File

@ -278,6 +278,7 @@ class StockEntry(StockController):
self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty), NegativeStockError) self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty), NegativeStockError)
# get incoming rate # get incoming rate
if not d.bom_no:
if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return" or force: if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return" or force:
incoming_rate = flt(self.get_incoming_rate(args), self.precision("incoming_rate", d)) incoming_rate = flt(self.get_incoming_rate(args), self.precision("incoming_rate", d))
if incoming_rate > 0: if incoming_rate > 0:
@ -293,10 +294,10 @@ class StockEntry(StockController):
def add_operation_cost(self, raw_material_cost, force): def add_operation_cost(self, raw_material_cost, force):
"""Adds operating cost if Production Order is set""" """Adds operating cost if Production Order is set"""
# set incoming rate for fg item # set incoming rate for fg item
if self.purpose in ("Manufacture", "Repack"): if self.purpose in ["Manufacture", "Repack"]:
number_of_fg_items = len([t.t_warehouse for t in self.get("items") if t.t_warehouse]) number_of_fg_items = len([t.t_warehouse for t in self.get("items") if t.t_warehouse])
for d in self.get("items"): for d in self.get("items"):
if (d.t_warehouse and number_of_fg_items == 1): if d.bom_no or (d.t_warehouse and number_of_fg_items == 1):
operation_cost_per_unit = 0.0 operation_cost_per_unit = 0.0
if self.production_order: if self.production_order:
operation_cost_per_unit = self.get_operation_cost_per_unit(d.bom_no, d.qty) operation_cost_per_unit = self.get_operation_cost_per_unit(d.bom_no, d.qty)
@ -540,6 +541,9 @@ class StockEntry(StockController):
return ret return ret
def get_items(self): def get_items(self):
if not self.fg_completed_qty or not self.bom_no:
frappe.throw(_("BOM and Manufacturing Quantity are required"))
self.set('items', []) self.set('items', [])
self.validate_production_order() self.validate_production_order()