From eb1395ecc2b2bb03a752ad1f122cd574ed5295af Mon Sep 17 00:00:00 2001 From: Ashish Baravaliya Date: Thu, 29 Aug 2024 23:33:06 -0400 Subject: [PATCH] feat: purchase order check added --- d2h/hooks.py | 5 +- d2h/overrides.py | 2 + d2h/public/js/purchase_order.js | 98 ++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 39 deletions(-) diff --git a/d2h/hooks.py b/d2h/hooks.py index 0317546..690a089 100644 --- a/d2h/hooks.py +++ b/d2h/hooks.py @@ -228,13 +228,14 @@ doc_events = { "Purchase Receipt": { "before_save": "d2h.overrides.purchase_receipt_before_save", - "on_submit": "d2h.overrides.on_submit_purchase_receipt" + "on_submit": "d2h.overrides.on_submit_purchase_receipt", + "on_trash": "d2h.overrides.on_delete_purchase_receipt" }, "Delivery Note": { "before_save": "d2h.overrides.delivery_note_before_save" }, "*": { - "before_print": "d2h.api.before_print", + "before_print": "d2h.api.before_print" } } diff --git a/d2h/overrides.py b/d2h/overrides.py index e951297..8f9704f 100644 --- a/d2h/overrides.py +++ b/d2h/overrides.py @@ -30,3 +30,5 @@ def on_submit_purchase_receipt(doc, method): item_order.custom_good_in_transit_qty = 0 item_order.save() +def on_delete_purchase_receipt(doc, method): + on_submit_purchase_receipt(doc, method) diff --git a/d2h/public/js/purchase_order.js b/d2h/public/js/purchase_order.js index d54ed38..1d449a2 100644 --- a/d2h/public/js/purchase_order.js +++ b/d2h/public/js/purchase_order.js @@ -101,51 +101,75 @@ function show_items_dialog(frm, pending_qty) { }, ], }, + { + fieldtype: "Check", + fieldname: "check_confirm", + label: "Confirm", + reqd: 1, + }, ], primary_action_label: __("Save"), primary_action: function () { - let error = false; - if (d.get_value("new_items").length) { - d.get_value("new_items").map((item) => { - if (item.new_good_in_transit_qty > item.new_qty) { - error = true; - } - }); - if (error) { - frappe.throw( - __("Good In Transit Qty cannot be greater than Pending Qty") - ); - } else { - items_for_purchase_receipt = []; + if (!d.get_value("check_confirm")) { + frappe.throw(__("Please check Confirm")); + } else { + let error = false; + if (d.get_value("new_items").length) { + let zero_error = true; d.get_value("new_items").map((item) => { - frm.doc.items.map((i) => { - if (i.name == item.name && item.new_good_in_transit_qty) { - items_for_purchase_receipt.push({ - name: i.name, - item_code: i.item_code, - item_name: i.item_name, - qty: item.new_good_in_transit_qty, - uom: i.uom, - }); + if (item.new_good_in_transit_qty > 0) { + zero_error = false; + } + }); + if (zero_error) { + frappe.throw( + __("At least one Good In Transit Qty must be greater than 0") + ); + } else { + d.get_value("new_items").map((item) => { + if (item.new_good_in_transit_qty > item.new_qty) { + error = true; } }); - }); + if (error) { + frappe.throw( + __("Good In Transit Qty cannot be greater than Pending Qty") + ); + } else { + items_for_purchase_receipt = []; + d.get_value("new_items").map((item) => { + frm.doc.items.map((i) => { + if (i.name == item.name && item.new_good_in_transit_qty) { + items_for_purchase_receipt.push({ + name: i.name, + item_code: i.item_code, + item_name: i.item_name, + qty: item.new_good_in_transit_qty, + uom: i.uom, + }); + } + }); + }); - if (items_for_purchase_receipt.length > 0) { - frappe.call({ - method: "d2h.api.create_purchase_receipt", - args: { - purchase_order: frm.doc.name, - items: JSON.stringify(items_for_purchase_receipt), - }, - callback: function () { - frm.dirty(); - frappe.msgprint(__("Purchase Receipt has been created.")); - frm.refresh_field("items"); - d.hide(); - }, - }); + if (items_for_purchase_receipt.length > 0) { + frappe.call({ + method: "d2h.api.create_purchase_receipt", + args: { + purchase_order: frm.doc.name, + items: JSON.stringify(items_for_purchase_receipt), + }, + callback: function () { + frm.dirty(); + frappe.msgprint(__("Purchase Receipt has been created.")); + frm.refresh_field("items"); + d.hide(); + }, + }); + } + } } + } else { + frappe.msgprint(__("Please select atleast one item.")); } } },