refactor: use get_product_bundle_list()
to get all product bundle at once
This commit is contained in:
parent
ba61292dfc
commit
bbcb65894b
@ -308,11 +308,19 @@ class DeliveryNote(SellingController):
|
|||||||
def validate_packed_qty(self):
|
def validate_packed_qty(self):
|
||||||
"""Validate that if packed qty exists, it should be equal to qty"""
|
"""Validate that if packed qty exists, it should be equal to qty"""
|
||||||
|
|
||||||
for item in self.items + self.packed_items:
|
if frappe.db.exists("Packing Slip", {"docstatus": 1, "delivery_note": self.name}):
|
||||||
if item.packed_qty and item.packed_qty != item.qty:
|
product_bundle_list = self.get_product_bundle_list()
|
||||||
frappe.throw(
|
for item in self.items + self.packed_items:
|
||||||
_("Row {0}: Packed Qty must be equal to {1} Qty.").format(item.idx, frappe.bold(item.doctype))
|
if (
|
||||||
)
|
item.item_code not in product_bundle_list
|
||||||
|
and flt(item.packed_qty)
|
||||||
|
and flt(item.packed_qty) != flt(item.qty)
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_("Row {0}: Packed Qty must be equal to {1} Qty.").format(
|
||||||
|
item.idx, frappe.bold(item.doctype)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def update_pick_list_status(self):
|
def update_pick_list_status(self):
|
||||||
from erpnext.stock.doctype.pick_list.pick_list import update_pick_list_status
|
from erpnext.stock.doctype.pick_list.pick_list import update_pick_list_status
|
||||||
@ -391,19 +399,22 @@ class DeliveryNote(SellingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def has_unpacked_items(self):
|
def has_unpacked_items(self):
|
||||||
for item in self.items:
|
product_bundle_list = self.get_product_bundle_list()
|
||||||
if (
|
|
||||||
not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
|
|
||||||
and item.packed_qty < item.qty
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
|
|
||||||
for item in self.packed_items:
|
for item in self.items + self.packed_items:
|
||||||
if item.packed_qty < item.qty:
|
if item.item_code not in product_bundle_list and flt(item.packed_qty) < flt(item.qty):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_product_bundle_list(self):
|
||||||
|
items_list = [item.item_code for item in self.items]
|
||||||
|
return frappe.db.get_all(
|
||||||
|
"Product Bundle",
|
||||||
|
filters={"new_item_code": ["in", items_list]},
|
||||||
|
pluck="name",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def update_billed_amount_based_on_so(so_detail, update_modified=True):
|
def update_billed_amount_based_on_so(so_detail, update_modified=True):
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Sum
|
||||||
@ -724,7 +735,7 @@ def make_packing_slip(source_name, target_doc=None):
|
|||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
"condition": lambda item: (
|
"condition": lambda item: (
|
||||||
not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
|
not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
|
||||||
and item.packed_qty < item.qty
|
and flt(item.packed_qty) < flt(item.qty)
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
"Packed Item": {
|
"Packed Item": {
|
||||||
@ -738,7 +749,7 @@ def make_packing_slip(source_name, target_doc=None):
|
|||||||
"name": "pi_detail",
|
"name": "pi_detail",
|
||||||
},
|
},
|
||||||
"postprocess": update_item,
|
"postprocess": update_item,
|
||||||
"condition": lambda item: (item.packed_qty < item.qty),
|
"condition": lambda item: (flt(item.packed_qty) < flt(item.qty)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
target_doc,
|
target_doc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user