diff --git a/d2h/api.py b/d2h/api.py index c8c34ca..294bd3a 100644 --- a/d2h/api.py +++ b/d2h/api.py @@ -40,10 +40,12 @@ def before_print(_, __, ___): def short_close_purchase_order(purchase_order): purchase_order = frappe.get_doc("Purchase Order", purchase_order) for item in purchase_order.items: - item.custom_short_close_qty = item.qty - item.custom_good_in_transit_qty + if item.qty > item.received_qty: + item.custom_short_close_qty = item.qty - item.received_qty - purchase_order.status = "Completed" purchase_order.save(ignore_permissions=True) + frappe.msgprint(f"Purchase Order {purchase_order.name} has been short closed.") + @frappe.whitelist() def create_purchase_receipt(purchase_order, items): @@ -63,6 +65,8 @@ def create_purchase_receipt(purchase_order, items): new_item.qty = item["qty"] new_item.uom = item["uom"] new_item.purchase_order = purchase_order.name + new_item.purchase_order_item = item["name"] + new_item.scheduled_date = purchase_order.schedule_date purchase_receipt.insert(ignore_permissions=True) @@ -83,6 +87,6 @@ def get_purchase_order_good_in_transit(purchase_order): "purchase_order": purchase_order, "docstatus": 1 }, - fields=["name", "item_code", "item_name", "qty"] + fields=["name", "item_code", "item_name", "qty", "purchase_order_item"] ) return purchase_receipts \ No newline at end of file diff --git a/d2h/overrides.py b/d2h/overrides.py index a39e16c..6950020 100644 --- a/d2h/overrides.py +++ b/d2h/overrides.py @@ -24,7 +24,7 @@ def on_submit_purchase_receipt(doc, method): "item_code": item.item_code, "parent": item.purchase_order }) - if(item_order.custom_good_in_transit_qty < item.qty): + if(item_order.custom_good_in_transit_qty > item.qty): item_order.custom_good_in_transit_qty -= item.qty else: item_order.custom_good_in_transit_qty = 0 diff --git a/d2h/public/js/purchase_order.js b/d2h/public/js/purchase_order.js index 413fbf3..e29103c 100644 --- a/d2h/public/js/purchase_order.js +++ b/d2h/public/js/purchase_order.js @@ -11,11 +11,10 @@ frappe.ui.form.on("Purchase Order", { frm.doc.items.map((item) => { received_qty = 0; r.message.map((i) => { - if (i.item_code == item.item_code) { + if (i.purchase_order_item == item.name) { received_qty += i.qty; } }); - console.log(received_qty, item.qty); if (received_qty < item.qty) { pending_qty.push({ name: item.name, @@ -23,7 +22,6 @@ frappe.ui.form.on("Purchase Order", { }); } }); - console.log(frm.doc.items, r.message); if (pending_qty.length > 0) { frm.add_custom_button(__("Good In Transit"), function () { show_items_dialog(frm, pending_qty);