refactor: disallow '0' qty return invoices with stock effect
(cherry picked from commit 898affbee9)
This commit is contained in:
@@ -169,6 +169,13 @@ class AccountsController(TransactionBase):
|
|||||||
if not self.get("is_return") and not self.get("is_debit_note"):
|
if not self.get("is_return") and not self.get("is_debit_note"):
|
||||||
self.validate_qty_is_not_zero()
|
self.validate_qty_is_not_zero()
|
||||||
|
|
||||||
|
if (
|
||||||
|
self.doctype in ["Sales Invoice", "Purchase Invoice"]
|
||||||
|
and self.get("is_return")
|
||||||
|
and self.get("update_stock")
|
||||||
|
):
|
||||||
|
self.validate_zero_qty_for_return_invoices_with_stock()
|
||||||
|
|
||||||
if self.get("_action") and self._action != "update_after_submit":
|
if self.get("_action") and self._action != "update_after_submit":
|
||||||
self.set_missing_values(for_validate=True)
|
self.set_missing_values(for_validate=True)
|
||||||
|
|
||||||
@@ -1045,6 +1052,18 @@ class AccountsController(TransactionBase):
|
|||||||
else:
|
else:
|
||||||
return flt(args.get(field, 0) / self.get("conversion_rate", 1))
|
return flt(args.get(field, 0) / self.get("conversion_rate", 1))
|
||||||
|
|
||||||
|
def validate_zero_qty_for_return_invoices_with_stock(self):
|
||||||
|
rows = []
|
||||||
|
for item in self.items:
|
||||||
|
if not flt(item.qty):
|
||||||
|
rows.append(item)
|
||||||
|
if rows:
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"For Return Invoices with Stock effect, '0' qty Items are not allowed. Following rows are affected: {0}"
|
||||||
|
).format(frappe.bold(comma_and(["#" + str(x.idx) for x in rows])))
|
||||||
|
)
|
||||||
|
|
||||||
def validate_qty_is_not_zero(self):
|
def validate_qty_is_not_zero(self):
|
||||||
if self.doctype == "Purchase Receipt":
|
if self.doctype == "Purchase Receipt":
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user