mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-02 09:14:35 +00:00
fix: validate buying price list on material request and update item rates on change
This commit is contained in:
@@ -92,7 +92,10 @@ frappe.ui.form.on("Material Request", {
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
if (!frm.doc.buying_price_list) {
|
||||
frm.doc.buying_price_list = frappe.defaults.get_default("buying_price_list");
|
||||
const buying_price_list = frappe.defaults.get_default("buying_price_list");
|
||||
if (frappe.has_permission("Price List", "read", buying_price_list)) {
|
||||
frm.set_value("buying_price_list", buying_price_list);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -271,9 +274,7 @@ frappe.ui.form.on("Material Request", {
|
||||
from_warehouse: item.from_warehouse,
|
||||
warehouse: item.warehouse,
|
||||
doctype: frm.doc.doctype,
|
||||
buying_price_list: frm.doc.buying_price_list
|
||||
? frm.doc.buying_price_list
|
||||
: frappe.defaults.get_default("buying_price_list"),
|
||||
buying_price_list: frm.doc.buying_price_list,
|
||||
currency: frappe.defaults.get_default("Currency"),
|
||||
name: frm.doc.name,
|
||||
qty: item.qty || 1,
|
||||
|
||||
@@ -19,6 +19,7 @@ from erpnext.buying.utils import check_on_hold_or_closed_status, validate_for_it
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import get_item_details
|
||||
from erpnext.stock.doctype.item.item import get_item_defaults
|
||||
from erpnext.stock.get_item_details import get_price_list_rate_for
|
||||
from erpnext.stock.stock_balance import get_indented_qty, update_bin_qty
|
||||
|
||||
form_grid_templates = {"items": "templates/form_grid/material_request_grid.html"}
|
||||
@@ -169,8 +170,43 @@ class MaterialRequest(BuyingController):
|
||||
self.reset_default_field_value("set_warehouse", "items", "warehouse")
|
||||
self.reset_default_field_value("set_from_warehouse", "items", "from_warehouse")
|
||||
|
||||
if self.buying_price_list and not frappe.get_value("Price List", self.buying_price_list, "buying"):
|
||||
self.buying_price_list = None
|
||||
|
||||
if not self.buying_price_list:
|
||||
self.buying_price_list = frappe.defaults.get_defaults().buying_price_list
|
||||
buying_price_list = frappe.defaults.get_defaults().buying_price_list
|
||||
if frappe.has_permission("Price List", "read", buying_price_list):
|
||||
self.buying_price_list = buying_price_list
|
||||
|
||||
def on_update(self):
|
||||
if self.buying_price_list and self.has_value_changed("buying_price_list"):
|
||||
self.update_item_rates()
|
||||
|
||||
def update_item_rates(self):
|
||||
price_not_uom_dependent = frappe.get_value(
|
||||
"Price List", self.buying_price_list, "price_not_uom_dependent"
|
||||
)
|
||||
for item in self.items:
|
||||
rate = get_price_list_rate_for(
|
||||
frappe._dict(
|
||||
{
|
||||
"price_list": self.buying_price_list,
|
||||
"uom": item.uom,
|
||||
"transaction_date": self.transaction_date,
|
||||
"qty": item.qty,
|
||||
"stock_uom": item.stock_uom,
|
||||
"price_not_uom_dependent": price_not_uom_dependent,
|
||||
}
|
||||
),
|
||||
item.item_code,
|
||||
)
|
||||
item.db_set({"rate": flt(rate), "amount": flt(flt(rate) * item.qty, item.precision("amount"))})
|
||||
frappe.msgprint(
|
||||
_("Item rates have been updated based on the selected Buying Price List {0}").format(
|
||||
self.buying_price_list
|
||||
),
|
||||
alert=True,
|
||||
)
|
||||
|
||||
def before_update_after_submit(self):
|
||||
self.validate_schedule_date()
|
||||
|
||||
Reference in New Issue
Block a user