Skip to content

Commit

Permalink
feat: purchase order check added
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishBarvaliya committed Aug 30, 2024
1 parent a5fe844 commit eb1395e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 39 deletions.
5 changes: 3 additions & 2 deletions d2h/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
2 changes: 2 additions & 0 deletions d2h/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
98 changes: 61 additions & 37 deletions d2h/public/js/purchase_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
}
},
Expand Down

0 comments on commit eb1395e

Please sign in to comment.