Skip to content

Commit

Permalink
feat: purchase order fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishBarvaliya committed Aug 14, 2024
1 parent a38e045 commit 2b8e399
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 7 additions & 3 deletions d2h/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion d2h/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions d2h/public/js/purchase_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ 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,
pending: item.qty - received_qty,
});
}
});
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);
Expand Down

0 comments on commit 2b8e399

Please sign in to comment.