From 6a44f357f94134b3d1517bfda533e41d4a6fa5c0 Mon Sep 17 00:00:00 2001 From: Neha Fathima Date: Wed, 11 Mar 2026 14:13:17 +0530 Subject: [PATCH] feat: Create Party Specific Item from item doctype --- rmax_custom/api/item.py | 34 ++++++++++ rmax_custom/hooks.py | 1 + .../public/js/create_multiple_supplier.js | 64 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 rmax_custom/api/item.py create mode 100644 rmax_custom/public/js/create_multiple_supplier.js diff --git a/rmax_custom/api/item.py b/rmax_custom/api/item.py new file mode 100644 index 0000000..6bc8805 --- /dev/null +++ b/rmax_custom/api/item.py @@ -0,0 +1,34 @@ +import frappe + + + + + + + + +@frappe.whitelist() +def create_party_specific_items(item, suppliers): + """ + Create Party Specific Item records for multiple suppliers. + creates a new record linking the supplier with + the given item. + """ + suppliers = frappe.parse_json(suppliers) + for s in suppliers: + supplier = s.get("supplier") + if not frappe.db.exists("Party Specific Item", { + "party_type": "Supplier", + "party": supplier, + "based_on": "Item Code", + "based_on_value": item + }): + doc = frappe.new_doc("Party Specific Item") + doc.party_type = "Supplier" + doc.party = supplier + doc.based_on = "Item Code" + doc.based_on_value = item + doc.item = item + doc.insert(ignore_permissions=True) + + return "Done" \ No newline at end of file diff --git a/rmax_custom/hooks.py b/rmax_custom/hooks.py index 714de2a..0b9c027 100644 --- a/rmax_custom/hooks.py +++ b/rmax_custom/hooks.py @@ -31,6 +31,7 @@ "/assets/rmax_custom/js/sales_invoice_pos_total_popup.js", "/assets/rmax_custom/js/sales_invoice_popup.js", "/assets/rmax_custom/js/create_customer.js", + "/assets/rmax_custom/js/create_multiple_supplier.js" ] diff --git a/rmax_custom/public/js/create_multiple_supplier.js b/rmax_custom/public/js/create_multiple_supplier.js new file mode 100644 index 0000000..6a0c233 --- /dev/null +++ b/rmax_custom/public/js/create_multiple_supplier.js @@ -0,0 +1,64 @@ +frappe.ui.form.on("Item", { + refresh(frm) { + if (frm.is_new()) return; + + frm.add_custom_button("Add Multiple Suppliers", function () { + open_multiple_suppliers_dialog(frm); + }); + } +}); + + + +function open_multiple_suppliers_dialog(frm) { + let d = new frappe.ui.Dialog({ + title: "Add Suppliers for this Item", + size: "large", + fields: [ + { + fieldname: "suppliers_table", + fieldtype: "Table", + label: "Suppliers", + in_place_edit: true, + cannot_add_rows: false, + + fields: [ + { + fieldname: "supplier", + fieldtype: "Link", + label: "Supplier", + options: "Supplier", + in_list_view: 1, + reqd: 1 + } + ] + } + ], + primary_action_label: "Create Party Specific Items", + primary_action(values) { + + if (!values.suppliers_table || values.suppliers_table.length === 0) { + frappe.msgprint("Please add suppliers"); + return; + } + + frappe.call({ + method: "rmax_custom.api.item.create_party_specific_items", + args: { + item: frm.doc.name, + suppliers: values.suppliers_table + }, + callback: function () { + + frappe.msgprint("Party Specific Items Created Successfully"); + + d.hide(); + + frm.reload_doc(); + } + }); + } + }); + + d.show(); +} \ No newline at end of file