fix: batch based item price not working (#43172)

This commit is contained in:
rohitwaghchaure
2024-09-13 12:03:36 +05:30
committed by GitHub
parent 2b96e37c34
commit d9e4ed13cb
2 changed files with 47 additions and 3 deletions

View File

@@ -1512,6 +1512,31 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
} }
} }
batch_no(frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.use_serial_batch_fields && row.batch_no) {
var params = this._get_args(row);
params.batch_no = row.batch_no;
params.uom = row.uom;
frappe.call({
method: "erpnext.stock.get_item_details.get_batch_based_item_price",
args: {
params: params,
item_code: row.item_code,
},
callback: function(r) {
if (!r.exc && r.message) {
row.price_list_rate = r.message;
row.rate = r.message;
refresh_field("rate", row.name, row.parentfield);
refresh_field("price_list_rate", row.name, row.parentfield);
}
}
})
}
}
toggle_item_grid_columns(company_currency) { toggle_item_grid_columns(company_currency) {
const me = this; const me = this;
// toggle columns // toggle columns

View File

@@ -10,7 +10,7 @@ from frappe.model import child_table_fields, default_fields
from frappe.model.meta import get_field_precision from frappe.model.meta import get_field_precision
from frappe.model.utils import get_fetch_values from frappe.model.utils import get_fetch_values
from frappe.query_builder.functions import IfNull, Sum from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import add_days, add_months, cint, cstr, flt, getdate from frappe.utils import add_days, add_months, cint, cstr, flt, getdate, parse_json
from erpnext import get_company_currency from erpnext import get_company_currency
from erpnext.accounts.doctype.pricing_rule.pricing_rule import ( from erpnext.accounts.doctype.pricing_rule.pricing_rule import (
@@ -902,7 +902,7 @@ def insert_item_price(args):
) )
def get_item_price(args, item_code, ignore_party=False) -> list[dict]: def get_item_price(args, item_code, ignore_party=False, force_batch_no=False) -> list[dict]:
""" """
Get name, price_list_rate from Item Price based on conditions Get name, price_list_rate from Item Price based on conditions
Check if the desired qty is within the increment of the packing list. Check if the desired qty is within the increment of the packing list.
@@ -919,7 +919,6 @@ def get_item_price(args, item_code, ignore_party=False) -> list[dict]:
(ip.item_code == item_code) (ip.item_code == item_code)
& (ip.price_list == args.get("price_list")) & (ip.price_list == args.get("price_list"))
& (IfNull(ip.uom, "").isin(["", args.get("uom")])) & (IfNull(ip.uom, "").isin(["", args.get("uom")]))
& (IfNull(ip.batch_no, "").isin(["", args.get("batch_no")]))
) )
.orderby(ip.valid_from, order=frappe.qb.desc) .orderby(ip.valid_from, order=frappe.qb.desc)
.orderby(IfNull(ip.batch_no, ""), order=frappe.qb.desc) .orderby(IfNull(ip.batch_no, ""), order=frappe.qb.desc)
@@ -927,6 +926,11 @@ def get_item_price(args, item_code, ignore_party=False) -> list[dict]:
.limit(1) .limit(1)
) )
if force_batch_no:
query = query.where(ip.batch_no == args.get("batch_no"))
else:
query = query.where(IfNull(ip.batch_no, "").isin(["", args.get("batch_no")]))
if not ignore_party: if not ignore_party:
if args.get("customer"): if args.get("customer"):
query = query.where(ip.customer == args.get("customer")) query = query.where(ip.customer == args.get("customer"))
@@ -944,6 +948,21 @@ def get_item_price(args, item_code, ignore_party=False) -> list[dict]:
return query.run(as_dict=True) return query.run(as_dict=True)
@frappe.whitelist()
def get_batch_based_item_price(params, item_code) -> float:
if isinstance(params, str):
params = parse_json(params)
item_price = get_item_price(params, item_code, force_batch_no=True)
if not item_price:
item_price = get_item_price(params, item_code, ignore_party=True, force_batch_no=True)
if item_price and item_price[0].uom == params.get("uom"):
return item_price[0].price_list_rate
return 0.0
def get_price_list_rate_for(args, item_code): def get_price_list_rate_for(args, item_code):
""" """
:param customer: link to Customer DocType :param customer: link to Customer DocType