chore: Code Cleanup
- Validate capacity < stock level only on new rule - Mention stock uom while validating capacity in new rule - Separate function to format and display unassigned items - Format ORM args
This commit is contained in:
parent
2fbaa5dc58
commit
2ed80656aa
@ -38,10 +38,13 @@ class PutawayRule(Document):
|
||||
title=_("Invalid Warehouse"))
|
||||
|
||||
def validate_capacity(self):
|
||||
stock_uom = frappe.db.get_value("Item", self.item_code, "stock_uom")
|
||||
balance_qty = get_stock_balance(self.item_code, self.warehouse, nowdate())
|
||||
if flt(self.stock_capacity) < flt(balance_qty):
|
||||
frappe.throw(_("Warehouse Capacity for Item '{0}' must be greater than the existing stock level of {1} qty.")
|
||||
.format(self.item_code, frappe.bold(balance_qty)), title=_("Insufficient Capacity"))
|
||||
|
||||
if flt(self.stock_capacity) < flt(balance_qty) and self.get('__islocal'):
|
||||
frappe.throw(_("Warehouse Capacity for Item '{0}' must be greater than the existing stock level of {1} {2}.")
|
||||
.format(self.item_code, frappe.bold(balance_qty), stock_uom),
|
||||
title=_("Insufficient Capacity"))
|
||||
|
||||
if not self.capacity:
|
||||
frappe.throw(_("Capacity must be greater than 0"), title=_("Invalid"))
|
||||
@ -49,10 +52,10 @@ class PutawayRule(Document):
|
||||
def set_stock_capacity(self):
|
||||
self.stock_capacity = (flt(self.conversion_factor) or 1) * flt(self.capacity)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_ordered_putaway_rules(item_code, company):
|
||||
"""Returns an ordered list of putaway rules to apply on an item."""
|
||||
rules = frappe.get_all("Putaway Rule", fields=["name", "item_code", "stock_capacity", "priority", "warehouse"],
|
||||
rules = frappe.get_all("Putaway Rule",
|
||||
fields=["name", "item_code", "stock_capacity", "priority", "warehouse"],
|
||||
filters={"item_code": item_code, "company": company, "disable": 0},
|
||||
order_by="priority asc, capacity desc")
|
||||
|
||||
@ -145,27 +148,29 @@ def apply_putaway_rule(items, company):
|
||||
items_not_accomodated.append([item.item_code, pending_qty])
|
||||
|
||||
if items_not_accomodated:
|
||||
msg = _("The following Items, having Putaway Rules, could not be accomodated:") + "<br><br>"
|
||||
formatted_item_rows = ""
|
||||
|
||||
for entry in items_not_accomodated:
|
||||
item_link = frappe.utils.get_link_to_form("Item", entry[0])
|
||||
formatted_item_rows += """
|
||||
<td>{0}</td>
|
||||
<td>{1}</td>
|
||||
</tr>""".format(item_link, frappe.bold(entry[1]))
|
||||
|
||||
msg += """
|
||||
<table class="table">
|
||||
<thead>
|
||||
<td>{0}</td>
|
||||
<td>{1}</td>
|
||||
</thead>
|
||||
{2}
|
||||
</table>
|
||||
""".format(_("Item"), _("Unassigned Qty"), formatted_item_rows)
|
||||
|
||||
frappe.msgprint(msg, title=_("Insufficient Capacity"), is_minimizable=True, wide=True)
|
||||
format_unassigned_items_error(items_not_accomodated)
|
||||
|
||||
return updated_table if updated_table else items
|
||||
# TODO: check pricing rule, item tax impact
|
||||
|
||||
def format_unassigned_items_error(items_not_accomodated):
|
||||
msg = _("The following Items, having Putaway Rules, could not be accomodated:") + "<br><br>"
|
||||
formatted_item_rows = ""
|
||||
|
||||
for entry in items_not_accomodated:
|
||||
item_link = frappe.utils.get_link_to_form("Item", entry[0])
|
||||
formatted_item_rows += """
|
||||
<td>{0}</td>
|
||||
<td>{1}</td>
|
||||
</tr>""".format(item_link, frappe.bold(entry[1]))
|
||||
|
||||
msg += """
|
||||
<table class="table">
|
||||
<thead>
|
||||
<td>{0}</td>
|
||||
<td>{1}</td>
|
||||
</thead>
|
||||
{2}
|
||||
</table>
|
||||
""".format(_("Item"), _("Unassigned Qty"), formatted_item_rows)
|
||||
|
||||
frappe.msgprint(msg, title=_("Insufficient Capacity"), is_minimizable=True, wide=True)
|
Loading…
x
Reference in New Issue
Block a user