Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions rmax_custom/api/item.py
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions rmax_custom/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

]

Expand Down
64 changes: 64 additions & 0 deletions rmax_custom/public/js/create_multiple_supplier.js
Original file line number Diff line number Diff line change
@@ -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();
}
Loading