Created button to link buying items to material requests
This commit is contained in:
parent
ac65e956e8
commit
28945438f2
@ -221,6 +221,44 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
|
||||
tc_name: function() {
|
||||
this.get_terms();
|
||||
},
|
||||
link_requests: function() {
|
||||
|
||||
cur_frm.add_custom_button(__("Link to Material Requests"),
|
||||
function() {
|
||||
my_items = []
|
||||
for (var i in cur_frm.doc.items) {
|
||||
if(!cur_frm.doc.items[i].material_request){
|
||||
my_items.push(cur_frm.doc.items[i].item_code);
|
||||
}
|
||||
|
||||
}
|
||||
frappe.call({
|
||||
method: "erpnext.buying.doctype.purchase_common.purchase_common.get_linked_material_requests",
|
||||
args:{
|
||||
items: my_items
|
||||
},
|
||||
callback: function(r) {
|
||||
//frm.reload_doc();
|
||||
console.log(r.message);
|
||||
for (var i in cur_frm.doc.items) {
|
||||
var qty = cur_frm.doc.items[i].qty;
|
||||
(r.message || []).forEach(function(d) {
|
||||
if (d[0].qty > 0 && qty > 0 && cur_frm.doc.items[i].item_code == d[0].item_code)
|
||||
{
|
||||
cur_frm.doc.items[i].material_request = d[0].mr_name;
|
||||
cur_frm.doc.items[i].material_request_item = d[0].mr_item;
|
||||
my_qty = Math.min(qty, d[0].qty);
|
||||
qty = qty - my_qty;
|
||||
d[0].qty = d[0].qty - my_qty;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import frappe, json
|
||||
from frappe.utils import flt, cstr, cint
|
||||
from frappe import _
|
||||
|
||||
@ -79,4 +79,28 @@ class PurchaseCommon(BuyingController):
|
||||
status = frappe.db.get_value(doctype, docname, "status")
|
||||
|
||||
if status == "Closed":
|
||||
frappe.throw(_("{0} {1} status is {2}").format(doctype, docname, status), frappe.InvalidStatusError)
|
||||
frappe.throw(_("{0} {1} status is {2}").format(doctype, docname, status), frappe.InvalidStatusError)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_material_requests(items):
|
||||
items = json.loads(items)
|
||||
mr_list = []
|
||||
for item in items:
|
||||
material_request = frappe.db.sql("""SELECT distinct mr.name AS mr_name,
|
||||
(mr_item.qty - mr_item.ordered_qty) AS qty,
|
||||
mr_item.item_code AS item_code,
|
||||
mr_item.name AS mr_item
|
||||
FROM `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
|
||||
WHERE mr.name = mr_item.parent
|
||||
AND mr_item.item_code = %(item)s
|
||||
AND mr.material_request_type = 'Purchase'
|
||||
AND mr.per_ordered < 99.99
|
||||
AND mr.docstatus = 1
|
||||
AND mr.status != 'Stopped'
|
||||
ORDER BY mr_item.item_code ASC""",{"item": item}, as_dict=1)
|
||||
if material_request:
|
||||
mr_list.append(material_request)
|
||||
|
||||
return mr_list
|
||||
|
||||
|
@ -56,6 +56,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
}
|
||||
} else if(doc.docstatus===0) {
|
||||
cur_frm.cscript.add_from_mappers();
|
||||
cur_frm.cscript.link_requests();
|
||||
}
|
||||
|
||||
if(doc.docstatus == 1 && in_list(["Closed", "Delivered"], doc.status)) {
|
||||
|
@ -43,6 +43,7 @@ frappe.ui.form.on("Request for Quotation",{
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
make_suppplier_quotation: function(frm) {
|
||||
@ -134,7 +135,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
|
||||
}
|
||||
})
|
||||
}, __("Get items from"));
|
||||
|
||||
cur_frm.cscript.link_requests();
|
||||
// Get items from open Material Requests based on supplier
|
||||
cur_frm.add_custom_button(__('Possible Supplier'), function() {
|
||||
// Create a dialog window for the user to pick their supplier
|
||||
@ -170,6 +171,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
|
||||
}
|
||||
d.show();
|
||||
}, __("Get items from"));
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -16,6 +16,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
|
||||
|
||||
}
|
||||
else if (this.frm.doc.docstatus===0) {
|
||||
|
||||
cur_frm.add_custom_button(__('Material Request'),
|
||||
function() {
|
||||
erpnext.utils.map_current_doc({
|
||||
@ -30,6 +31,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
|
||||
}
|
||||
})
|
||||
}, __("Get items from"));
|
||||
cur_frm.cscript.link_requests();
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user