Skip to content

Commit

Permalink
fix: incorrect process loss validation for multiple finished items
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Oct 19, 2023
1 parent 1d186ef commit 0d887fa
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,31 +438,34 @@ def validate_qty(self):
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 not in ["Manufacture", "Repack"]:
return

fg_qty = defaultdict(float)
for d in self.items:
if d.is_finished_item:
fg_qty[d.item_code] += flt(d.qty)

item_wise_qty.setdefault(d.item_code, []).append(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 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):
Expand Down

0 comments on commit 0d887fa

Please sign in to comment.