From 7be9f2ea3e9d3cf78f595e15bb8e412eaf8883b9 Mon Sep 17 00:00:00 2001 From: Ashish Baravaliya Date: Wed, 31 Jul 2024 22:52:46 -0400 Subject: [PATCH] feat: good in trasit changes --- d2h/api.py | 18 ---------- d2h/fixtures/custom_field.json | 55 +++++++++++++++++++++++++++++ d2h/public/js/purchase_order.js | 62 ++++++++++++++++++--------------- d2h/www/__init__.py | 0 4 files changed, 89 insertions(+), 46 deletions(-) delete mode 100644 d2h/api.py create mode 100644 d2h/www/__init__.py diff --git a/d2h/api.py b/d2h/api.py deleted file mode 100644 index 3be7bb5..0000000 --- a/d2h/api.py +++ /dev/null @@ -1,18 +0,0 @@ -import frappe -import json - -@frappe.whitelist() -def create_stock_entry(items): - items = json.loads(items) - - doc = frappe.new_doc("Stock Entry") - doc.stock_entry_type = "Material Receipt" - doc.items = [] - for item in items: - new_item = doc.append("items", {}) - new_item.item_code = item["new_item_code"] - new_item.qty = item["new_qty"] - new_item.uom = item["new_uom"] - new_item.t_warehouse = "Goods In Transit - R" - - doc.insert() diff --git a/d2h/fixtures/custom_field.json b/d2h/fixtures/custom_field.json index 29adc2f..2af3a33 100644 --- a/d2h/fixtures/custom_field.json +++ b/d2h/fixtures/custom_field.json @@ -219,6 +219,61 @@ "unique": 0, "width": null }, + { + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "doctype": "Custom Field", + "dt": "Purchase Order Item", + "fetch_from": null, + "fetch_if_empty": 0, + "fieldname": "custom_good_in_transit_qty", + "fieldtype": "Float", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "stock_uom", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Good In Transit Qty", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2024-08-01 08:21:51.582129", + "module": null, + "name": "Purchase Order Item-custom_good_in_transit_qty", + "no_copy": 0, + "non_negative": 0, + "options": null, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 0, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, { "allow_in_quick_entry": 0, "allow_on_submit": 0, diff --git a/d2h/public/js/purchase_order.js b/d2h/public/js/purchase_order.js index 6c99ab6..bfe6b1b 100644 --- a/d2h/public/js/purchase_order.js +++ b/d2h/public/js/purchase_order.js @@ -18,55 +18,61 @@ function show_items_dialog(frm) { label: "Items", cannot_add_rows: true, in_place_edit: true, - get_data: () => { - data = []; - frm.doc.items.forEach((item) => { - data.push({ - new_item_code: item.item_code, - new_uom: item.uom, - new_qty: item.qty, - }); - }); - return data; - }, + data: frm.doc.items.map((item) => { + return { + new_item_code: item.item_code, + new_qty: item.qty - item.good_in_transit_qty, + new_good_in_transit_qty: 0, + }; + }), fields: [ { fieldtype: "Data", fieldname: "new_item_code", label: "Item Code", in_list_view: 1, + columns: 4, read_only: 1, }, { - fieldtype: "Data", - fieldname: "new_uom", - label: "UOM", + fieldtype: "Float", + fieldname: "new_qty", + label: "Pending Qty", in_list_view: 1, + columns: 3, read_only: 1, }, { fieldtype: "Float", - fieldname: "new_qty", - label: "Quantity", + fieldname: "new_good_in_transit_qty", + label: "Good In Transit Qty", + columns: 3, in_list_view: 1, }, ], }, ], - primary_action_label: __("Create"), + primary_action_label: __("Save"), primary_action: function () { - frappe.call({ - method: "d2h.api.create_stock_entry", - args: { - items: JSON.stringify(d.get_values().new_items), - }, - callback: function (r) { - if (!r.exc) { - frappe.msgprint(__("Stock Entry Created")); - d.hide(); + if (d.get_value("new_items").length) { + d.get_value("new_items").map((item) => { + if (item.new_good_in_transit_qty > item.new_qty) { + frappe.throw( + __("Good In Transit Qty cannot be greater than Pending Qty") + ); + } else { + frm.doc.items.map((i) => { + if (i.item_code == item.new_item_code) { + i.good_in_transit_qty += item.new_good_in_transit_qty; + frm.dirty(); + } + }); + frm.refresh_field("items"); } - }, - }); + }); + } + d.hide(); + frm.save(); }, secondary_action_label: __("Close"), secondary_action: function () { diff --git a/d2h/www/__init__.py b/d2h/www/__init__.py new file mode 100644 index 0000000..e69de29