fix: incorrect process loss validation for multiple finished items (#37576)

This commit is contained in:
rohitwaghchaure 2023-10-24 15:28:55 +05:30 committed by GitHub
parent d92eb0c603
commit 92cbe580e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -438,31 +438,37 @@ class StockEntry(StockController):
item_code.append(item.item_code)
def validate_fg_completed_qty(self):
item_wise_qty = {}
if self.purpose == "Manufacture" and self.work_order:
for d in self.items:
if d.is_finished_item:
if self.process_loss_qty:
d.qty = self.fg_completed_qty - self.process_loss_qty
if self.purpose != "Manufacture":
return
item_wise_qty.setdefault(d.item_code, []).append(d.qty)
fg_qty = defaultdict(float)
for d in self.items:
if d.is_finished_item:
fg_qty[d.item_code] += flt(d.qty)
if not fg_qty:
return
precision = frappe.get_precision("Stock Entry Detail", "qty")
for item_code, qty_list in item_wise_qty.items():
total = flt(sum(qty_list), precision)
fg_item = list(fg_qty.keys())[0]
fg_item_qty = flt(fg_qty[fg_item], precision)
fg_completed_qty = flt(self.fg_completed_qty, precision)
if (self.fg_completed_qty - total) > 0 and not self.process_loss_qty:
self.process_loss_qty = flt(self.fg_completed_qty - total, precision)
self.process_loss_percentage = flt(self.process_loss_qty * 100 / self.fg_completed_qty)
for d in self.items:
if not fg_qty.get(d.item_code):
continue
if self.process_loss_qty:
total += flt(self.process_loss_qty, precision)
if (fg_completed_qty - fg_item_qty) > 0:
self.process_loss_qty = fg_completed_qty - fg_item_qty
if self.fg_completed_qty != total:
if not self.process_loss_qty:
continue
if fg_completed_qty != (flt(fg_item_qty) + flt(self.process_loss_qty, precision)):
frappe.throw(
_("The finished product {0} quantity {1} and For Quantity {2} cannot be different").format(
frappe.bold(item_code), frappe.bold(total), frappe.bold(self.fg_completed_qty)
)
_(
"Since there is a process loss of {0} units for the finished good {1}, you should reduce the quantity by {0} units for the finished good {1} in the Items Table."
).format(frappe.bold(self.process_loss_qty), frappe.bold(d.item_code))
)
def validate_difference_account(self):