Skip to content

Commit

Permalink
fix: add validation for QI in PR (backport #35677) (#35758)
Browse files Browse the repository at this point in the history
fix: add validation for QI in PR

(cherry picked from commit 2c1ab56)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
  • Loading branch information
mergify[bot] and s-aga-r committed Jun 17, 2023
1 parent e37b6bb commit 0a8b714
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def validate(self):
self.set_status()

self.po_required()
self.validate_items_quality_inspection()
self.validate_with_previous_doc()
self.validate_uom_is_integer("uom", ["qty", "received_qty"])
self.validate_uom_is_integer("stock_uom", "stock_qty")
Expand Down Expand Up @@ -183,6 +184,26 @@ def po_required(self):
if not d.purchase_order:
frappe.throw(_("Purchase Order number required for Item {0}").format(d.item_code))

def validate_items_quality_inspection(self):
for item in self.get("items"):
if item.quality_inspection:
qi = frappe.db.get_value(
"Quality Inspection",
item.quality_inspection,
["reference_type", "reference_name", "item_code"],
as_dict=True,
)

if qi.reference_type != self.doctype or qi.reference_name != self.name:
msg = f"""Row #{item.idx}: Please select a valid Quality Inspection with Reference Type
{frappe.bold(self.doctype)} and Reference Name {frappe.bold(self.name)}."""
frappe.throw(_(msg))

if qi.item_code != item.item_code:
msg = f"""Row #{item.idx}: Please select a valid Quality Inspection with Item Code
{frappe.bold(item.item_code)}."""
frappe.throw(_(msg))

def get_already_received_qty(self, po, po_detail):
qty = frappe.db.sql(
"""select sum(qty) from `tabPurchase Receipt Item`
Expand Down

0 comments on commit 0a8b714

Please sign in to comment.