mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 13:49:13 +00:00
[Agri] Item amount set on item set (#12091)
* [Agri] Item amount set on item set - closes #12008 - fixes #12010 * used frappe.call instead of frm.call in crop * made modifications for sql query for BOM Item - done since Crop doctype in Agri module also uses 'BOM Item' child table * hide BOM no from BOM Item childtable in Crop
This commit is contained in:
@@ -1,7 +1,55 @@
|
||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.provide("erpnext.crop");
|
||||
|
||||
frappe.ui.form.on('Crop', {
|
||||
validate: (frm) => {
|
||||
refresh: (frm) => {
|
||||
frm.fields_dict.materials_required.grid.set_column_disp('bom_no', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
frappe.ui.form.on("BOM Item", {
|
||||
item_code: (frm, cdt, cdn) => {
|
||||
erpnext.crop.update_item_rate_uom(frm, cdt, cdn);
|
||||
},
|
||||
qty: (frm, cdt, cdn) => {
|
||||
erpnext.crop.update_item_qty_amount(frm, cdt, cdn);
|
||||
},
|
||||
rate: (frm, cdt, cdn) => {
|
||||
erpnext.crop.update_item_qty_amount(frm, cdt, cdn);
|
||||
}
|
||||
});
|
||||
|
||||
erpnext.crop.update_item_rate_uom = function(frm, cdt, cdn) {
|
||||
let material_list = ['materials_required', 'produce', 'byproducts'];
|
||||
material_list.forEach((material) => {
|
||||
frm.doc[material].forEach((item, index) => {
|
||||
if (item.name == cdn){
|
||||
frappe.call({
|
||||
method:'erpnext.agriculture.doctype.crop.crop.get_item_details',
|
||||
args: {
|
||||
item_code: item.item_code
|
||||
},
|
||||
callback: (r) => {
|
||||
frappe.model.set_value('BOM Item', item.name, 'uom', r.message.uom);
|
||||
frappe.model.set_value('BOM Item', item.name, 'rate', r.message.rate);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
erpnext.crop.update_item_qty_amount = function(frm, cdt, cdn) {
|
||||
let material_list = ['materials_required', 'produce', 'byproducts'];
|
||||
material_list.forEach((material) => {
|
||||
frm.doc[material].forEach((item, index) => {
|
||||
if (item.name == cdn){
|
||||
if (!frappe.model.get_value('BOM Item', item.name, 'qty'))
|
||||
frappe.model.set_value('BOM Item', item.name, 'qty', 1);
|
||||
frappe.model.set_value('BOM Item', item.name, 'amount', item.qty * item.rate);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -15,4 +15,9 @@ class Crop(Document):
|
||||
frappe.throw("Start day is greater than end day in task '{0}'".format(task.subject))
|
||||
# to calculate the period of the Crop Cycle
|
||||
if task.end_day > max_period: max_period = task.end_day
|
||||
if max_period > self.period: self.period = max_period
|
||||
if max_period > self.period: self.period = max_period
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_details(item_code):
|
||||
item = frappe.get_doc('Item', item_code)
|
||||
return { "uom": item.stock_uom, "rate": item.valuation_rate }
|
||||
Reference in New Issue
Block a user