From b2c962bac79784ca7779de80505a9cf8c7a2cae1 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Tue, 5 Mar 2024 18:40:52 +0100 Subject: [PATCH] feat: Option to make a quotation from the item bookings list --- erpnext/public/js/utils/sales_common.js | 15 ++++++++ erpnext/translations/fr.csv | 2 + .../doctype/item_booking/item_booking.py | 8 +++- .../doctype/item_booking/item_booking_list.js | 37 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index 4b3415b9d1b..be622306315 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -99,6 +99,8 @@ erpnext.sales_common = { (this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer)); this.toggle_editable_price_list_rate(); + + this.display_booking_details(); } customer() { @@ -536,6 +538,19 @@ erpnext.sales_common = { const item = frappe.get_doc(cdt, cdn) frappe.model.set_value(cdt, cdn, "unit_cost_price", item.base_unit_cost_price + item.additional_costs_amount); } + + display_booking_details() { + this.frm.doc.items.map(item => { + if (item.item_booking) { + frappe.model.with_doc("Item Booking", item.item_booking, () => { + const doc = frappe.get_doc("Item Booking", item.item_booking) + this.frm.add_custom_button(__('{0} {1} ({2})', [doc.item_name, frappe.datetime.obj_to_user(doc.starts_on), doc.name]), () => { + frappe.set_route("Form", "Item Booking", doc.name) + }, __("Linked Bookings")) + }) + } + }) + } }; } } diff --git a/erpnext/translations/fr.csv b/erpnext/translations/fr.csv index d9211880d4c..5c358fa20a9 100644 --- a/erpnext/translations/fr.csv +++ b/erpnext/translations/fr.csv @@ -6195,6 +6195,7 @@ Link with Customer,Lien avec le client, Link with Supplier,Lien avec le fournisseur, Link,Lien, Linked Account,Compte lié, +Linked Bookings,Réservations associées, Linked Document Type,Type de document lié, Linked Document,Document lié, Linked Documents,Documents liés, @@ -6442,6 +6443,7 @@ Make Serial No / Batch from Work Order,Faire le numéro de série / lot de l'ord Make Stock Entry,Créer une écriture de stock, Make Work Order for Sub Assembly Items,Faire un ordre de travail pour des articles de sous-assemblage, Make a new entry and reconcile it,Faire une nouvelle entrée et la rapprocher, +Make a quotation,Créer un devis, Make a subscription,Créer un abonnement, Make all attachments private,Rendre toutes les pièces jointes privées, Make payment entry,Créer une écriture de paiement, diff --git a/erpnext/venue/doctype/item_booking/item_booking.py b/erpnext/venue/doctype/item_booking/item_booking.py index af34159dfef..e3a1151b732 100644 --- a/erpnext/venue/doctype/item_booking/item_booking.py +++ b/erpnext/venue/doctype/item_booking/item_booking.py @@ -1530,7 +1530,13 @@ def make_quotation(source_name, target_doc=None): doclist = get_mapped_doc( "Item Booking", source_name, - {"Item Booking": {"doctype": "Quotation", "field_map": {"party_type": "quotation_to"}}}, + { + "Item Booking": { + "doctype": "Quotation", + "field_map": {"party_type": "quotation_to"}, + "field_no_map": ["status"], + } + }, target_doc, set_missing_values, ) diff --git a/erpnext/venue/doctype/item_booking/item_booking_list.js b/erpnext/venue/doctype/item_booking/item_booking_list.js index c168b705bac..86bd6309692 100644 --- a/erpnext/venue/doctype/item_booking/item_booking_list.js +++ b/erpnext/venue/doctype/item_booking/item_booking_list.js @@ -20,5 +20,42 @@ frappe.listview_settings['Item Booking'] = { } }; } + + const create_quotation = () => { + const selected_docs = list_view.get_checked_items(); + const docnames = list_view.get_checked_items(true); + + if (selected_docs.length > 0) { + for (let doc of selected_docs) { + if (doc.docstatus == 2) { + frappe.throw(__("Cannot create a quotation from Cancelled documents.")); + } + } + + frappe.new_doc("Quotation") + .then(() => { + cur_frm.set_value("items", []); + + frappe.call({ + type: "POST", + method: "frappe.model.mapper.map_docs", + args: { + "method": "erpnext.venue.doctype.item_booking.item_booking.make_quotation", + "source_names": docnames, + "target_doc": cur_frm.doc + }, + callback: function (r) { + if (!r.exc) { + frappe.model.sync(r.message); + cur_frm.dirty(); + cur_frm.refresh(); + } + } + }); + }) + } + }; + + list_view.page.add_action_item(__("Make a quotation"), create_quotation, false); } }; \ No newline at end of file -- GitLab