Skip to content

Commit

Permalink
fix: added validation for incorrect type
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Jun 14, 2023
1 parent be78ae7 commit a9f9284
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions erpnext/stock/deprecated_serial_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def calculate_avg_rate_for_non_batchwise_valuation(self):
if batch_no not in self.non_batchwise_valuation_batches:
continue

if not self.non_batchwise_balance_qty:
continue

self.batch_avg_rate[batch_no] = (
self.non_batchwise_balance_value / self.non_batchwise_balance_qty
)
Expand Down
19 changes: 17 additions & 2 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from frappe import _, bold
from frappe.model.naming import make_autoname
from frappe.query_builder.functions import CombineDatetime, Sum
from frappe.utils import cint, flt, now, nowtime, today
from frappe.utils import cint, flt, get_link_to_form, now, nowtime, today

from erpnext.stock.deprecated_serial_batch import (
DeprecatedBatchNoValuation,
Expand Down Expand Up @@ -79,9 +79,24 @@ def make_serial_batch_no_bundle(self):
self.set_serial_and_batch_bundle(sn_doc)

def validate_actual_qty(self, sn_doc):
link = get_link_to_form("Serial and Batch Bundle", sn_doc.name)

condition = {
"Inward": self.sle.actual_qty > 0,
"Outward": self.sle.actual_qty < 0,
}.get(sn_doc.type_of_transaction)

if not condition:
correct_type = "Inward"
if sn_doc.type_of_transaction == "Inward":
correct_type = "Outward"

msg = f"The type of transaction of Serial and Batch Bundle {link} is {bold(sn_doc.type_of_transaction)} but as per the Actual Qty {self.sle.actual_qty} in the {self.sle.voucher_type} {self.sle.voucher_no} the type of transaction should be {bold(correct_type)}"
frappe.throw(_(msg))

precision = sn_doc.precision("total_qty")
if flt(sn_doc.total_qty, precision) != flt(self.sle.actual_qty, precision):
msg = f"Total qty {flt(sn_doc.total_qty, precision)} of Serial and Batch Bundle {sn_doc.name} is not equal to Actual Qty {flt(self.sle.actual_qty, precision)} in the {self.sle.voucher_type} {self.sle.voucher_no}"
msg = f"Total qty {flt(sn_doc.total_qty, precision)} of Serial and Batch Bundle {link} is not equal to Actual Qty {flt(self.sle.actual_qty, precision)} in the {self.sle.voucher_type} {self.sle.voucher_no}"
frappe.throw(_(msg))

def validate_item(self):
Expand Down

0 comments on commit a9f9284

Please sign in to comment.