From 7f2a54d95bba8f686e4fc3c439a8f37c170b3688 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:03:36 +0100 Subject: [PATCH 1/3] refactor: usage of in_list (cherry picked from commit d238751e6ba0666b4098f1db9be38e9bd8163770) # Conflicts: # erpnext/accounts/doctype/payment_entry/payment_entry.js # erpnext/buying/doctype/purchase_order/purchase_order.js # erpnext/public/js/controllers/accounts.js # erpnext/public/js/controllers/buying.js # erpnext/public/js/controllers/transaction.js # erpnext/public/js/utils/sales_common.js # erpnext/templates/form_grid/item_grid.html --- .../doctype/journal_entry/journal_entry.js | 6 +- .../doctype/payment_entry/payment_entry.js | 50 ++ .../payment_request/payment_request.js | 2 +- erpnext/assets/doctype/asset/asset.js | 6 +- .../doctype/purchase_order/purchase_order.js | 15 + erpnext/manufacturing/doctype/bom/bom.js | 2 +- .../production_plan/production_plan.js | 2 +- .../doctype/work_order/work_order.js | 4 +- erpnext/public/js/communication.js | 2 +- erpnext/public/js/controllers/accounts.js | 53 ++ erpnext/public/js/controllers/buying.js | 399 ++++++++++++++ .../public/js/controllers/taxes_and_totals.js | 22 +- erpnext/public/js/controllers/transaction.js | 61 ++- erpnext/public/js/payment/payments.js | 2 +- erpnext/public/js/sms_manager.js | 4 +- erpnext/public/js/utils/party.js | 4 +- erpnext/public/js/utils/sales_common.js | 510 ++++++++++++++++++ .../import_supplier_invoice.js | 2 +- .../point_of_sale/pos_past_order_summary.js | 2 +- .../closing_stock_balance.js | 2 +- .../delivery_trip/delivery_trip_list.js | 4 +- erpnext/templates/form_grid/item_grid.html | 5 + 22 files changed, 1120 insertions(+), 39 deletions(-) create mode 100644 erpnext/public/js/utils/sales_common.js diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index a2f5455f2f7..5bbdd84d3f4 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -171,7 +171,7 @@ frappe.ui.form.on("Journal Entry", { !(frm.doc.accounts || []).length || ((frm.doc.accounts || []).length === 1 && !frm.doc.accounts[0].account) ) { - if (in_list(["Bank Entry", "Cash Entry"], frm.doc.voucher_type)) { + if (["Bank Entry", "Cash Entry"].includes(frm.doc.voucher_type)) { return frappe.call({ type: "GET", method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account", @@ -283,7 +283,7 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro filters: [[jvd.reference_type, "docstatus", "=", 1]], }; - if (in_list(["Sales Invoice", "Purchase Invoice"], jvd.reference_type)) { + if (["Sales Invoice", "Purchase Invoice"].includes(jvd.reference_type)) { out.filters.push([jvd.reference_type, "outstanding_amount", "!=", 0]); // Filter by cost center if (jvd.cost_center) { @@ -295,7 +295,7 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro out.filters.push([jvd.reference_type, party_account_field, "=", jvd.account]); } - if (in_list(["Sales Order", "Purchase Order"], jvd.reference_type)) { + if (["Sales Order", "Purchase Order"].includes(jvd.reference_type)) { // party_type and party mandatory frappe.model.validate_missing(jvd, "party_type"); frappe.model.validate_missing(jvd, "party"); diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 309141fe4c2..8ad31e1e791 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -21,8 +21,14 @@ frappe.ui.form.on('Payment Entry', { frm.set_query("paid_from", function() { frm.events.validate_company(frm); +<<<<<<< HEAD var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ? ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; +======= + var account_types = ["Pay", "Internal Transfer"].includes(frm.doc.payment_type) + ? ["Bank", "Cash"] + : [frappe.boot.party_account_types[frm.doc.party_type]]; +>>>>>>> d238751e6b (refactor: usage of in_list) return { filters: { "account_type": ["in", account_types], @@ -75,8 +81,14 @@ frappe.ui.form.on('Payment Entry', { frm.set_query("paid_to", function() { frm.events.validate_company(frm); +<<<<<<< HEAD var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ? ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; +======= + var account_types = ["Receive", "Internal Transfer"].includes(frm.doc.payment_type) + ? ["Bank", "Cash"] + : [frappe.boot.party_account_types[frm.doc.party_type]]; +>>>>>>> d238751e6b (refactor: usage of in_list) return { filters: { "account_type": ["in", account_types], @@ -121,7 +133,14 @@ frappe.ui.form.on('Payment Entry', { frm.set_query('payment_term', 'references', function(frm, cdt, cdn) { const child = locals[cdt][cdn]; +<<<<<<< HEAD if (in_list(['Purchase Invoice', 'Sales Invoice'], child.reference_doctype) && child.reference_name) { +======= + if ( + ["Purchase Invoice", "Sales Invoice"].includes(child.reference_doctype) && + child.reference_name + ) { +>>>>>>> d238751e6b (refactor: usage of in_list) return { query: "erpnext.controllers.queries.get_payment_terms_for_references", filters: { @@ -484,8 +503,13 @@ frappe.ui.form.on('Payment Entry', { if (frm.doc.paid_from_account_currency == company_currency) { frm.set_value("source_exchange_rate", 1); +<<<<<<< HEAD } else if (frm.doc.paid_from){ if (in_list(["Internal Transfer", "Pay"], frm.doc.payment_type)) { +======= + } else if (frm.doc.paid_from) { + if (["Internal Transfer", "Pay"].includes(frm.doc.payment_type)) { +>>>>>>> d238751e6b (refactor: usage of in_list) let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; frappe.call({ method: "erpnext.setup.utils.get_exchange_rate", @@ -852,11 +876,19 @@ frappe.ui.form.on('Payment Entry', { total_negative_outstanding : remaining_outstanding; } +<<<<<<< HEAD var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding; } else if (in_list(["Customer", "Supplier"], frm.doc.party_type)) { total_negative_outstanding = flt(total_negative_outstanding, precision("outstanding_amount")) if(paid_amount > total_negative_outstanding) { if(total_negative_outstanding == 0) { +======= + var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding; + } else if (["Customer", "Supplier"].includes(frm.doc.party_type)) { + total_negative_outstanding = flt(total_negative_outstanding, precision("outstanding_amount")); + if (paid_amount > total_negative_outstanding) { + if (total_negative_outstanding == 0) { +>>>>>>> d238751e6b (refactor: usage of in_list) frappe.msgprint( __("Cannot {0} {1} {2} without any negative outstanding invoice", [frm.doc.payment_type, (frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type]) @@ -987,16 +1019,28 @@ frappe.ui.form.on('Payment Entry', { return; } +<<<<<<< HEAD if(frm.doc.party_type=="Customer" && !in_list(["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"], row.reference_doctype) +======= + if ( + frm.doc.party_type == "Customer" && + !["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"].includes(row.reference_doctype) +>>>>>>> d238751e6b (refactor: usage of in_list) ) { frappe.model.set_value(row.doctype, row.name, "reference_doctype", null); frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Sales Order, Sales Invoice, Journal Entry or Dunning", [row.idx])); return false; } +<<<<<<< HEAD if(frm.doc.party_type=="Supplier" && !in_list(["Purchase Order", "Purchase Invoice", "Journal Entry"], row.reference_doctype) +======= + if ( + frm.doc.party_type == "Supplier" && + !["Purchase Order", "Purchase Invoice", "Journal Entry"].includes(row.reference_doctype) +>>>>>>> d238751e6b (refactor: usage of in_list) ) { frappe.model.set_value(row.doctype, row.name, "against_voucher_type", null); frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx])); @@ -1078,9 +1122,15 @@ frappe.ui.form.on('Payment Entry', { } }, +<<<<<<< HEAD bank_account: function(frm) { const field = frm.doc.payment_type == "Pay" ? "paid_from":"paid_to"; if (frm.doc.bank_account && in_list(['Pay', 'Receive'], frm.doc.payment_type)) { +======= + bank_account: function (frm) { + const field = frm.doc.payment_type == "Pay" ? "paid_from" : "paid_to"; + if (frm.doc.bank_account && ["Pay", "Receive"].includes(frm.doc.payment_type)) { +>>>>>>> d238751e6b (refactor: usage of in_list) frappe.call({ method: "erpnext.accounts.doctype.bank_account.bank_account.get_bank_account_details", args: { diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index e5a6040c735..e45aa512fe8 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.js +++ b/erpnext/accounts/doctype/payment_request/payment_request.js @@ -28,7 +28,7 @@ frappe.ui.form.on("Payment Request", "refresh", function (frm) { if ( frm.doc.payment_request_type == "Inward" && frm.doc.payment_channel !== "Phone" && - !in_list(["Initiated", "Paid"], frm.doc.status) && + !["Initiated", "Paid"].includes(frm.doc.status) && !frm.doc.__islocal && frm.doc.docstatus == 1 ) { diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index 49c0b24e4cb..b6afe11e4ff 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -78,7 +78,7 @@ frappe.ui.form.on("Asset", { frm.events.make_schedules_editable(frm); if (frm.doc.docstatus == 1) { - if (in_list(["Submitted", "Partially Depreciated", "Fully Depreciated"], frm.doc.status)) { + if (["Submitted", "Partially Depreciated", "Fully Depreciated"].includes(frm.doc.status)) { frm.add_custom_button( __("Transfer Asset"), function () { @@ -280,7 +280,7 @@ frappe.ui.form.on("Asset", { if (v.journal_entry) { asset_values.push(asset_value); } else { - if (in_list(["Scrapped", "Sold"], frm.doc.status)) { + if (["Scrapped", "Sold"].includes(frm.doc.status)) { asset_values.push(null); } else { asset_values.push(asset_value); @@ -312,7 +312,7 @@ frappe.ui.form.on("Asset", { }); } - if (in_list(["Scrapped", "Sold"], frm.doc.status)) { + if (["Scrapped", "Sold"].includes(frm.doc.status)) { x_intervals.push(frappe.format(frm.doc.disposal_date, { fieldtype: "Date" })); asset_values.push(0); } diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 52a0f4ac2a2..a1a06489957 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -180,11 +180,22 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e this.frm.fields_dict.items_section.wrapper.removeClass("hide-border"); } +<<<<<<< HEAD if(!in_list(["Closed", "Delivered"], doc.status)) { if(this.frm.doc.status !== 'Closed' && flt(this.frm.doc.per_received) < 100 && flt(this.frm.doc.per_billed) < 100) { // Don't add Update Items button if the PO is following the new subcontracting flow. if (!(this.frm.doc.is_subcontracted && !this.frm.doc.is_old_subcontracting_flow)) { this.frm.add_custom_button(__('Update Items'), () => { +======= + if (!["Closed", "Delivered"].includes(doc.status)) { + if ( + this.frm.doc.status !== "Closed" && + flt(this.frm.doc.per_received, 2) < 100 && + flt(this.frm.doc.per_billed, 2) < 100 + ) { + if (!this.frm.doc.__onload || this.frm.doc.__onload.can_update_items) { + this.frm.add_custom_button(__("Update Items"), () => { +>>>>>>> d238751e6b (refactor: usage of in_list) erpnext.utils.update_child_items({ frm: this.frm, child_docname: "items", @@ -211,7 +222,11 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e this.frm.page.set_inner_btn_group_as_primary(__("Status")); } +<<<<<<< HEAD } else if(in_list(["Closed", "Delivered"], doc.status)) { +======= + } else if (["Closed", "Delivered"].includes(doc.status)) { +>>>>>>> d238751e6b (refactor: usage of in_list) if (this.frm.has_perm("submit")) { this.frm.add_custom_button(__('Re-open'), () => this.unclose_purchase_order(), __("Status")); } diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index b7ab6ef3872..bf8cb05d8ce 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -400,7 +400,7 @@ frappe.ui.form.on("BOM", { }, rm_cost_as_per(frm) { - if (in_list(["Valuation Rate", "Last Purchase Rate"], frm.doc.rm_cost_as_per)) { + if (["Valuation Rate", "Last Purchase Rate"].includes(frm.doc.rm_cost_as_per)) { frm.set_value("plc_conversion_rate", 1.0); } }, diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 54d1414c814..6db901c71a4 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -129,7 +129,7 @@ frappe.ui.form.on("Production Plan", { if ( frm.doc.mr_items && frm.doc.mr_items.length && - !in_list(["Material Requested", "Closed"], frm.doc.status) + !["Material Requested", "Closed"].includes(frm.doc.status) ) { frm.add_custom_button( __("Material Request"), diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 5e386035514..ea86d0a939c 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -194,7 +194,7 @@ frappe.ui.form.on("Work Order", { }, add_custom_button_to_return_components: function (frm) { - if (frm.doc.docstatus === 1 && in_list(["Closed", "Completed"], frm.doc.status)) { + if (frm.doc.docstatus === 1 && ["Closed", "Completed"].includes(frm.doc.status)) { let non_consumed_items = frm.doc.required_items.filter((d) => { return flt(d.consumed_qty) < flt(d.transferred_qty - d.returned_qty); }); @@ -594,7 +594,7 @@ erpnext.work_order = { ); } - if (doc.docstatus === 1 && !in_list(["Closed", "Completed"], doc.status)) { + if (doc.docstatus === 1 && !["Closed", "Completed"].includes(doc.status)) { if (doc.status != "Stopped" && doc.status != "Completed") { frm.add_custom_button( __("Stop"), diff --git a/erpnext/public/js/communication.js b/erpnext/public/js/communication.js index d9187f8b678..c8905e14af2 100644 --- a/erpnext/public/js/communication.js +++ b/erpnext/public/js/communication.js @@ -20,7 +20,7 @@ frappe.ui.form.on("Communication", { ); } - if (!in_list(["Lead", "Opportunity"], frm.doc.reference_doctype)) { + if (!["Lead", "Opportunity"].includes(frm.doc.reference_doctype)) { frm.add_custom_button( __("Lead"), () => { diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index 72845b20742..83003418266 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -5,6 +5,7 @@ frappe.provide("erpnext.taxes"); frappe.provide("erpnext.taxes.flags"); +<<<<<<< HEAD frappe.ui.form.on(cur_frm.doctype, { setup: function(frm) { // set conditional display for rate column in taxes @@ -12,6 +13,58 @@ frappe.ui.form.on(cur_frm.doctype, { if(in_list(['Sales Taxes and Charges', 'Purchase Taxes and Charges'], grid_row.doc.doctype)) { erpnext.taxes.set_conditional_mandatory_rate_or_amount(grid_row); } +======= +erpnext.accounts.taxes = { + setup_tax_validations: function(doctype) { + let me = this; + frappe.ui.form.on(doctype, { + setup: function(frm) { + // set conditional display for rate column in taxes + $(frm.wrapper).on('grid-row-render', function(e, grid_row) { + if(['Sales Taxes and Charges', 'Purchase Taxes and Charges'].includes(grid_row.doc.doctype)) { + me.set_conditional_mandatory_rate_or_amount(grid_row); + } + }); + }, + onload: function(frm) { + if(frm.get_field("taxes")) { + frm.set_query("account_head", "taxes", function(doc) { + if(frm.cscript.tax_table == "Sales Taxes and Charges") { + var account_type = ["Tax", "Chargeable", "Expense Account"]; + } else { + var account_type = ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation"]; + } + + return { + query: "erpnext.controllers.queries.tax_account_query", + filters: { + "account_type": account_type, + "company": doc.company, + } + } + }); + frm.set_query("cost_center", "taxes", function(doc) { + return { + filters: { + "company": doc.company, + "is_group": 0 + } + }; + }); + } + }, + validate: function(frm) { + // neither is absolutely mandatory + if(frm.get_docfield("taxes")) { + frm.get_docfield("taxes", "rate").reqd = 0; + frm.get_docfield("taxes", "tax_amount").reqd = 0; + } + + }, + taxes_on_form_rendered: function(frm) { + me.set_conditional_mandatory_rate_or_amount(frm.open_grid_row()); + }, +>>>>>>> d238751e6b (refactor: usage of in_list) }); }, onload: function(frm) { diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index b0e08cc6f26..ab2a476a1d4 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -9,9 +9,408 @@ cur_frm.cscript.tax_table = "Purchase Taxes and Charges"; cur_frm.email_field = "contact_email"; +<<<<<<< HEAD erpnext.buying.BuyingController = class BuyingController extends erpnext.TransactionController { setup() { super.setup(); +======= + if (this.frm.doc.__islocal + && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) { + + var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total"); + var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total); + this.frm.set_value("disable_rounded_total", disable); + } + + + // no idea where me is coming from + if(this.frm.get_field('shipping_address')) { + this.frm.set_query("shipping_address", () => { + if(this.frm.doc.customer) { + return { + query: 'frappe.contacts.doctype.address.address.address_query', + filters: { link_doctype: 'Customer', link_name: this.frm.doc.customer } + }; + } else + return erpnext.queries.company_address_query(this.frm.doc) + }); + } + } + + setup_queries(doc, cdt, cdn) { + var me = this; + + if(this.frm.fields_dict.buying_price_list) { + this.frm.set_query("buying_price_list", function() { + return{ + filters: { 'buying': 1 } + } + }); + } + + if(this.frm.fields_dict.tc_name) { + this.frm.set_query("tc_name", function() { + return{ + filters: { 'buying': 1 } + } + }); + } + + me.frm.set_query('supplier', erpnext.queries.supplier); + me.frm.set_query('contact_person', erpnext.queries.contact_query); + me.frm.set_query('supplier_address', erpnext.queries.address_query); + + me.frm.set_query('billing_address', erpnext.queries.company_address_query); + erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype); + + this.frm.set_query("item_code", "items", function() { + if (me.frm.doc.is_subcontracted) { + var filters = {'supplier': me.frm.doc.supplier}; + if (me.frm.doc.is_old_subcontracting_flow) { + filters["is_sub_contracted_item"] = 1; + } + else { + filters["is_stock_item"] = 0; + } + + return{ + query: "erpnext.controllers.queries.item_query", + filters: filters + } + } + else { + return{ + query: "erpnext.controllers.queries.item_query", + filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1, 'has_variants': 0} + } + } + }); + + + this.frm.set_query("manufacturer", "items", function(doc, cdt, cdn) { + const row = locals[cdt][cdn]; + return { + query: "erpnext.controllers.queries.item_manufacturer_query", + filters:{ 'item_code': row.item_code } + } + }); + + if(this.frm.fields_dict["items"].grid.get_field('item_code')) { + this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) { + return me.set_query_for_item_tax_template(doc, cdt, cdn) + }); + } + } + + refresh(doc) { + frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'}; + + this.frm.toggle_display("supplier_name", + (this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier)); + + if(this.frm.doc.docstatus==0 && + (this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) { + this.set_from_product_bundle(); + } + + this.toggle_subcontracting_fields(); + super.refresh(); + } + + toggle_subcontracting_fields() { + if (['Purchase Receipt', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { + this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', + 'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM'); + + this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1); + this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1); + } + } + + supplier() { + var me = this; + erpnext.utils.get_party_details(this.frm, null, null, function(){ + me.apply_price_list(); + }); + } + + supplier_address() { + erpnext.utils.get_address_display(this.frm); + erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address"); + } + + buying_price_list() { + this.apply_price_list(); + } + + discount_percentage(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + item.discount_amount = 0.0; + this.price_list_rate(doc, cdt, cdn); + } + + discount_amount(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + item.discount_percentage = 0.0; + this.price_list_rate(doc, cdt, cdn); + } + + qty(doc, cdt, cdn) { + if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) { + this.calculate_received_qty(doc, cdt, cdn) + } + super.qty(doc, cdt, cdn); + } + + rejected_qty(doc, cdt, cdn) { + this.calculate_received_qty(doc, cdt, cdn) + } + + calculate_received_qty(doc, cdt, cdn){ + var item = frappe.get_doc(cdt, cdn); + frappe.model.round_floats_in(item, ["qty", "rejected_qty"]); + + if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return } + + let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item)); + let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty); + + frappe.model.set_value(cdt, cdn, "received_qty", received_qty); + frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty); + } + + batch_no(doc, cdt, cdn) { + super.batch_no(doc, cdt, cdn); + } + + validate_negative_quantity(cdt, cdn, item, fieldnames){ + if(!item || !fieldnames) { return } + + var is_negative_qty = false; + for(var i = 0; i{0} is invalid", [row.manufacturer_part_no]), + title: __("Invalid Part Number") + } + frappe.throw(msg); + } + } + ); + } + } + + add_serial_batch_bundle(doc, cdt, cdn) { + let item = locals[cdt][cdn]; + let me = this; + let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; + + frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) + .then((r) => { + if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { + item.has_serial_no = r.message.has_serial_no; + item.has_batch_no = r.message.has_batch_no; + item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; + item.is_rejected = false; + + frappe.require(path, function() { + new erpnext.SerialBatchPackageSelector( + me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; + } + + let update_values = { + "serial_and_batch_bundle": r.name, + "use_serial_batch_fields": 0, + "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) + } + + if (r.warehouse) { + update_values["warehouse"] = r.warehouse; + } + + frappe.model.set_value(item.doctype, item.name, update_values); + } + } + ); + }); + } + }); + } + + add_serial_batch_for_rejected_qty(doc, cdt, cdn) { + let item = locals[cdt][cdn]; + let me = this; + let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; + + frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) + .then((r) => { + if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { + item.has_serial_no = r.message.has_serial_no; + item.has_batch_no = r.message.has_batch_no; + item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; + item.is_rejected = true; + + frappe.require(path, function() { + new erpnext.SerialBatchPackageSelector( + me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; + } + + let update_values = { + "serial_and_batch_bundle": r.name, + "use_serial_batch_fields": 0, + "rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) + } + + if (r.warehouse) { + update_values["rejected_warehouse"] = r.warehouse; + } + + frappe.model.set_value(item.doctype, item.name, update_values); + } + } + ); + }); + } + }); + } + }; +>>>>>>> d238751e6b (refactor: usage of in_list) } onload(doc, cdt, cdn) { diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 186c342a75e..670cf35bb11 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -9,7 +9,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { apply_pricing_rule_on_item(item) { let effective_item_rate = item.price_list_rate; let item_rate = item.rate; - if (in_list(["Sales Order", "Quotation"], item.parenttype) && item.blanket_order_rate) { + if (["Sales Order", "Quotation"].includes(item.parenttype) && item.blanket_order_rate) { effective_item_rate = item.blanket_order_rate; } if (item.margin_type == "Percentage") { @@ -52,7 +52,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { // Advance calculation applicable to Sales/Purchase Invoice if ( - in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype) + ["Sales Invoice", "POS Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype) && this.frm.doc.docstatus < 2 && !this.frm.doc.is_return ) { @@ -60,7 +60,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } if ( - in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) + ["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype) && this.frm.doc.is_pos && this.frm.doc.is_return ) { @@ -69,7 +69,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { } // Sales person's commission - if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) { + if (["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].includes(this.frm.doc.doctype)) { this.calculate_commission(); this.calculate_contribution(); } @@ -547,7 +547,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { ? this.frm.doc["taxes"][tax_count - 1].total + flt(this.frm.doc.rounding_adjustment) : this.frm.doc.net_total); - if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"], this.frm.doc.doctype)) { + if(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) { this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ? flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total; } else { @@ -555,7 +555,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0; if(tax_count) { $.each(this.frm.doc["taxes"] || [], function(i, tax) { - if (in_list(["Valuation and Total", "Total"], tax.category)) { + if (["Valuation and Total", "Total"].includes(tax.category)) { if(tax.add_deduct_tax == "Add") { me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount_after_discount_amount); } else { @@ -702,7 +702,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { var actual_taxes_dict = {}; $.each(this.frm.doc["taxes"] || [], function(i, tax) { - if (in_list(["Actual", "On Item Quantity"], tax.charge_type)) { + if (["Actual", "On Item Quantity"].includes(tax.charge_type)) { var tax_amount = (tax.category == "Valuation") ? 0.0 : tax.tax_amount; tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0; actual_taxes_dict[tax.idx] = tax_amount; @@ -747,7 +747,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { // NOTE: // paid_amount and write_off_amount is only for POS/Loyalty Point Redemption Invoice // total_advance is only for non POS Invoice - if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) && this.frm.doc.is_return){ + if(["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype) && this.frm.doc.is_return){ this.calculate_paid_amount(); } @@ -755,7 +755,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]); - if(in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype)) { + if(["Sales Invoice", "POS Invoice", "Purchase Invoice"].includes(this.frm.doc.doctype)) { let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total; let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total; @@ -778,7 +778,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { this.frm.refresh_field("base_paid_amount"); } - if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype)) { + if(["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype)) { let total_amount_for_payment = (this.frm.doc.redeem_loyalty_points && this.frm.doc.loyalty_amount) ? flt(total_amount_to_pay - this.frm.doc.loyalty_amount, precision("base_grand_total")) : total_amount_to_pay; @@ -882,7 +882,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { calculate_change_amount(){ this.frm.doc.change_amount = 0.0; this.frm.doc.base_change_amount = 0.0; - if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) + if(["Sales Invoice", "POS Invoice"].includes(this.frm.doc.doctype) && this.frm.doc.paid_amount > this.frm.doc.grand_total && !this.frm.doc.is_return) { var payment_types = $.map(this.frm.doc.payments, function(d) { return d.type; }); diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 66ac9582b2d..2d836ad1e2f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -260,7 +260,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } setup_quality_inspection() { +<<<<<<< HEAD if(!in_list(["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)) { +======= + if(!["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"].includes(this.frm.doc.doctype)) { +>>>>>>> d238751e6b (refactor: usage of in_list) return; } @@ -272,7 +276,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.frm.page.set_inner_btn_group_as_primary(__('Create')); } +<<<<<<< HEAD const inspection_type = in_list(["Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype) +======= + const inspection_type = ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"].includes(this.frm.doc.doctype) +>>>>>>> d238751e6b (refactor: usage of in_list) ? "Incoming" : "Outgoing"; let quality_inspection_field = this.frm.get_docfield("items", "quality_inspection"); @@ -304,7 +312,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe make_payment_request() { let me = this; - const payment_request_type = (in_list(['Sales Order', 'Sales Invoice'], this.frm.doc.doctype)) + const payment_request_type = (['Sales Order', 'Sales Invoice'].includes(this.frm.doc.doctype)) ? "Inward" : "Outward"; frappe.call({ @@ -417,7 +425,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe setup_sms() { var me = this; let blacklist = ['Purchase Invoice', 'BOM']; - if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped", "Closed"], this.frm.doc.status) + if(this.frm.doc.docstatus===1 && !["Lost", "Stopped", "Closed"].includes(this.frm.doc.status) && !blacklist.includes(this.frm.doctype)) { this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); }); } @@ -691,6 +699,24 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } +<<<<<<< HEAD +======= + on_submit() { + if (["Purchase Invoice", "Sales Invoice"].includes(this.frm.doc.doctype) + && !this.frm.doc.update_stock) { + return; + } + + this.refresh_serial_batch_bundle_field(); + } + + refresh_serial_batch_bundle_field() { + frappe.route_hooks.after_submit = (frm_obj) => { + frm_obj.reload_doc(); + } + } + +>>>>>>> d238751e6b (refactor: usage of in_list) update_qty(cdt, cdn) { var valid_serial_nos = []; var serialnos = []; @@ -780,7 +806,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } var set_party_account = function(set_pricing) { - if (in_list(["Sales Invoice", "Purchase Invoice"], me.frm.doc.doctype)) { + if (["Sales Invoice", "Purchase Invoice"].includes(me.frm.doc.doctype)) { if(me.frm.doc.doctype=="Sales Invoice") { var party_type = "Customer"; var party_account_field = 'debit_to'; @@ -815,7 +841,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } if (frappe.meta.get_docfield(this.frm.doctype, "shipping_address") && - in_list(['Purchase Order', 'Purchase Receipt', 'Purchase Invoice'], this.frm.doctype)) { + ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice'].includes(this.frm.doctype)) { erpnext.utils.get_shipping_address(this.frm, function() { set_party_account(set_pricing); }); @@ -1482,7 +1508,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe "doctype": me.frm.doc.doctype, "name": me.frm.doc.name, "is_return": cint(me.frm.doc.is_return), - "update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0, + "update_stock": ['Sales Invoice', 'Purchase Invoice'].includes(me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0, "conversion_factor": me.frm.doc.conversion_factor, "pos_profile": me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : '', "coupon_code": me.frm.doc.coupon_code @@ -2126,7 +2152,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe get_method_for_payment() { var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry"; if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){ - if(in_list(['Sales Invoice', 'Purchase Invoice'], cur_frm.doc.doctype)){ + if(['Sales Invoice', 'Purchase Invoice'].includes( cur_frm.doc.doctype)){ method = "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_invoice"; }else { method= "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_order"; @@ -2351,6 +2377,7 @@ erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_ } frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { +<<<<<<< HEAD new erpnext.SerialNoBatchSelector({ frm: frm, item: d, @@ -2361,6 +2388,28 @@ erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_ callback: callback, on_close: on_close }, show_dialog); +======= + if (["Sales Invoice", "Delivery Note"].includes(frm.doc.doctype)) { + item_row.type_of_transaction = frm.doc.is_return ? "Inward" : "Outward"; + } else { + item_row.type_of_transaction = frm.doc.is_return ? "Outward" : "Inward"; + } + + new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { + if (r) { + let update_values = { + "serial_and_batch_bundle": r.name, + "qty": Math.abs(r.total_qty) + } + + if (r.warehouse) { + update_values[warehouse_field] = r.warehouse; + } + + frappe.model.set_value(item_row.doctype, item_row.name, update_values); + } + }); +>>>>>>> d238751e6b (refactor: usage of in_list) }); } diff --git a/erpnext/public/js/payment/payments.js b/erpnext/public/js/payment/payments.js index 0e584205396..c91bb046a52 100644 --- a/erpnext/public/js/payment/payments.js +++ b/erpnext/public/js/payment/payments.js @@ -218,7 +218,7 @@ erpnext.payments = class payments extends erpnext.stock.StockController { update_paid_amount(update_write_off) { var me = this; - if (in_list(["change_amount", "write_off_amount"], this.idx)) { + if (["change_amount", "write_off_amount"].includes(this.idx)) { var value = me.selected_mode.val(); if (me.idx == "change_amount") { me.change_amount(value); diff --git a/erpnext/public/js/sms_manager.js b/erpnext/public/js/sms_manager.js index d3147bb4600..63833da5af3 100644 --- a/erpnext/public/js/sms_manager.js +++ b/erpnext/public/js/sms_manager.js @@ -28,11 +28,11 @@ erpnext.SMSManager = function SMSManager(doc) { "Purchase Receipt": "Items has been received against purchase receipt: " + doc.name, }; - if (in_list(["Sales Order", "Delivery Note", "Sales Invoice"], doc.doctype)) + if (["Sales Order", "Delivery Note", "Sales Invoice"].includes(doc.doctype)) this.show(doc.contact_person, "Customer", doc.customer, "", default_msg[doc.doctype]); else if (doc.doctype === "Quotation") this.show(doc.contact_person, "Customer", doc.party_name, "", default_msg[doc.doctype]); - else if (in_list(["Purchase Order", "Purchase Receipt"], doc.doctype)) + else if (["Purchase Order", "Purchase Receipt"].includes(doc.doctype)) this.show(doc.contact_person, "Supplier", doc.supplier, "", default_msg[doc.doctype]); else if (doc.doctype == "Lead") this.show("", "", "", doc.mobile_no, default_msg[doc.doctype]); else if (doc.doctype == "Opportunity") diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js index 801376b2ed7..623941755d1 100644 --- a/erpnext/public/js/utils/party.js +++ b/erpnext/public/js/utils/party.js @@ -14,10 +14,10 @@ erpnext.utils.get_party_details = function (frm, method, args, callback) { if (!args) { if ( (frm.doctype != "Purchase Order" && frm.doc.customer) || - (frm.doc.party_name && in_list(["Quotation", "Opportunity"], frm.doc.doctype)) + (frm.doc.party_name && ["Quotation", "Opportunity"].includes(frm.doc.doctype)) ) { let party_type = "Customer"; - if (frm.doc.quotation_to && in_list(["Lead", "Prospect"], frm.doc.quotation_to)) { + if (frm.doc.quotation_to && ["Lead", "Prospect"].includes(frm.doc.quotation_to)) { party_type = frm.doc.quotation_to; } diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js new file mode 100644 index 00000000000..00df1c5c191 --- /dev/null +++ b/erpnext/public/js/utils/sales_common.js @@ -0,0 +1,510 @@ +// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +frappe.provide("erpnext.selling"); + +erpnext.sales_common = { + setup_selling_controller: function () { + erpnext.selling.SellingController = class SellingController extends erpnext.TransactionController { + setup() { + super.setup(); + this.toggle_enable_for_stock_uom("allow_to_edit_stock_uom_qty_for_sales"); + this.frm.email_field = "contact_email"; + } + + onload() { + super.onload(); + this.setup_queries(); + this.frm.set_query("shipping_rule", function () { + return { + filters: { + shipping_rule_type: "Selling", + }, + }; + }); + + this.frm.set_query("project", function (doc) { + return { + query: "erpnext.controllers.queries.get_project_name", + filters: { + customer: doc.customer, + }, + }; + }); + } + + setup_queries() { + var me = this; + + $.each( + [ + ["customer", "customer"], + ["lead", "lead"], + ], + function (i, opts) { + if (me.frm.fields_dict[opts[0]]) me.frm.set_query(opts[0], erpnext.queries[opts[1]]); + } + ); + + me.frm.set_query("contact_person", erpnext.queries.contact_query); + me.frm.set_query("customer_address", erpnext.queries.address_query); + me.frm.set_query("shipping_address_name", erpnext.queries.address_query); + me.frm.set_query("dispatch_address_name", erpnext.queries.dispatch_address_query); + + erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype); + + if (this.frm.fields_dict.selling_price_list) { + this.frm.set_query("selling_price_list", function () { + return { filters: { selling: 1 } }; + }); + } + + if (this.frm.fields_dict.tc_name) { + this.frm.set_query("tc_name", function () { + return { filters: { selling: 1 } }; + }); + } + + if (!this.frm.fields_dict["items"]) { + return; + } + + if (this.frm.fields_dict["items"].grid.get_field("item_code")) { + this.frm.set_query("item_code", "items", function () { + return { + query: "erpnext.controllers.queries.item_query", + filters: { is_sales_item: 1, customer: me.frm.doc.customer, has_variants: 0 }, + }; + }); + } + + if ( + this.frm.fields_dict["packed_items"] && + this.frm.fields_dict["packed_items"].grid.get_field("batch_no") + ) { + this.frm.set_query("batch_no", "packed_items", function (doc, cdt, cdn) { + return me.set_query_for_batch(doc, cdt, cdn); + }); + } + + if (this.frm.fields_dict["items"].grid.get_field("item_code")) { + this.frm.set_query("item_tax_template", "items", function (doc, cdt, cdn) { + return me.set_query_for_item_tax_template(doc, cdt, cdn); + }); + } + } + + refresh() { + super.refresh(); + + frappe.dynamic_link = { doc: this.frm.doc, fieldname: "customer", doctype: "Customer" }; + + this.frm.toggle_display( + "customer_name", + this.frm.doc.customer_name && this.frm.doc.customer_name !== this.frm.doc.customer + ); + + this.toggle_editable_price_list_rate(); + } + + customer() { + var me = this; + erpnext.utils.get_party_details(this.frm, null, null, function () { + me.apply_price_list(); + }); + } + + customer_address() { + erpnext.utils.get_address_display(this.frm, "customer_address"); + erpnext.utils.set_taxes_from_address( + this.frm, + "customer_address", + "customer_address", + "shipping_address_name" + ); + } + + shipping_address_name() { + erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address"); + erpnext.utils.set_taxes_from_address( + this.frm, + "shipping_address_name", + "customer_address", + "shipping_address_name" + ); + } + + dispatch_address_name() { + erpnext.utils.get_address_display(this.frm, "dispatch_address_name", "dispatch_address"); + } + + sales_partner() { + this.apply_pricing_rule(); + } + + campaign() { + this.apply_pricing_rule(); + } + + selling_price_list() { + this.apply_price_list(); + this.set_dynamic_labels(); + } + + discount_percentage(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + item.discount_amount = 0.0; + this.apply_discount_on_item(doc, cdt, cdn, "discount_percentage"); + } + + discount_amount(doc, cdt, cdn) { + if (doc.name === cdn) { + return; + } + + var item = frappe.get_doc(cdt, cdn); + item.discount_percentage = 0.0; + this.apply_discount_on_item(doc, cdt, cdn, "discount_amount"); + } + + commission_rate() { + this.calculate_commission(); + } + + total_commission() { + frappe.model.round_floats_in(this.frm.doc, [ + "amount_eligible_for_commission", + "total_commission", + ]); + + const { amount_eligible_for_commission } = this.frm.doc; + if (!amount_eligible_for_commission) return; + + this.frm.set_value( + "commission_rate", + flt((this.frm.doc.total_commission * 100.0) / amount_eligible_for_commission) + ); + } + + allocated_percentage(doc, cdt, cdn) { + var sales_person = frappe.get_doc(cdt, cdn); + if (sales_person.allocated_percentage) { + sales_person.allocated_percentage = flt( + sales_person.allocated_percentage, + precision("allocated_percentage", sales_person) + ); + + sales_person.allocated_amount = flt( + (this.frm.doc.amount_eligible_for_commission * sales_person.allocated_percentage) / + 100.0, + precision("allocated_amount", sales_person) + ); + refresh_field(["allocated_amount"], sales_person); + + this.calculate_incentive(sales_person); + refresh_field( + ["allocated_percentage", "allocated_amount", "commission_rate", "incentives"], + sales_person.name, + sales_person.parentfield + ); + } + } + + sales_person(doc, cdt, cdn) { + var row = frappe.get_doc(cdt, cdn); + this.calculate_incentive(row); + refresh_field("incentives", row.name, row.parentfield); + } + + warehouse(doc, cdt, cdn) { + if (doc.docstatus === 0 && doc.is_return && !doc.return_against) { + frappe.model.set_value(cdt, cdn, "incoming_rate", 0.0); + } + } + + toggle_editable_price_list_rate() { + var df = frappe.meta.get_docfield( + this.frm.doc.doctype + " Item", + "price_list_rate", + this.frm.doc.name + ); + var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate")); + + if (df && editable_price_list_rate) { + const parent_field = frappe.meta.get_parentfield( + this.frm.doc.doctype, + this.frm.doc.doctype + " Item" + ); + if (!this.frm.fields_dict[parent_field]) return; + + this.frm.fields_dict[parent_field].grid.update_docfield_property( + "price_list_rate", + "read_only", + 0 + ); + } + } + + calculate_commission() { + if (!this.frm.fields_dict.commission_rate || this.frm.doc.docstatus === 1) return; + + if (this.frm.doc.commission_rate > 100) { + this.frm.set_value("commission_rate", 100); + frappe.throw( + `${__( + frappe.meta.get_label(this.frm.doc.doctype, "commission_rate", this.frm.doc.name) + )} ${__("cannot be greater than 100")}` + ); + } + + this.frm.doc.amount_eligible_for_commission = this.frm.doc.items.reduce( + (sum, item) => (item.grant_commission ? sum + item.base_net_amount : sum), + 0 + ); + + this.frm.doc.total_commission = flt( + (this.frm.doc.amount_eligible_for_commission * this.frm.doc.commission_rate) / 100.0, + precision("total_commission") + ); + + refresh_field(["amount_eligible_for_commission", "total_commission"]); + } + + calculate_contribution() { + var me = this; + $.each(this.frm.doc.doctype.sales_team || [], function (i, sales_person) { + frappe.model.round_floats_in(sales_person); + if (!sales_person.allocated_percentage) return; + + sales_person.allocated_amount = flt( + (me.frm.doc.amount_eligible_for_commission * sales_person.allocated_percentage) / + 100.0, + precision("allocated_amount", sales_person) + ); + }); + } + + calculate_incentive(row) { + if (row.allocated_amount) { + row.incentives = flt( + (row.allocated_amount * row.commission_rate) / 100.0, + precision("incentives", row) + ); + } + } + + set_dynamic_labels() { + super.set_dynamic_labels(); + this.set_product_bundle_help(this.frm.doc); + } + + set_product_bundle_help(doc) { + if (!this.frm.fields_dict.packing_list) return; + if ((doc.packed_items || []).length) { + $(this.frm.fields_dict.packing_list.row.wrapper).toggle(true); + + if (["Delivery Note", "Sales Invoice"].includes(doc.doctype)) { + var help_msg = + "
" + + __( + "For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table." + ) + + "
"; + frappe.meta.get_docfield(doc.doctype, "product_bundle_help", doc.name).options = + help_msg; + } + } else { + $(this.frm.fields_dict.packing_list.row.wrapper).toggle(false); + if (["Delivery Note", "Sales Invoice"].includes(doc.doctype)) { + frappe.meta.get_docfield(doc.doctype, "product_bundle_help", doc.name).options = ""; + } + } + refresh_field("product_bundle_help"); + } + + company_address() { + var me = this; + if (this.frm.doc.company_address) { + frappe.call({ + method: "frappe.contacts.doctype.address.address.get_address_display", + args: { address_dict: this.frm.doc.company_address }, + callback: function (r) { + if (r.message) { + me.frm.set_value("company_address_display", r.message); + } + }, + }); + } else { + this.frm.set_value("company_address_display", ""); + } + } + + conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) { + super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate); + } + + qty(doc, cdt, cdn) { + super.qty(doc, cdt, cdn); + } + + pick_serial_and_batch(doc, cdt, cdn) { + let item = locals[cdt][cdn]; + let me = this; + let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; + + frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]).then((r) => { + if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { + item.has_serial_no = r.message.has_serial_no; + item.has_batch_no = r.message.has_batch_no; + item.type_of_transaction = item.qty > 0 ? "Outward" : "Inward"; + + item.title = item.has_serial_no ? __("Select Serial No") : __("Select Batch No"); + + if (item.has_serial_no && item.has_batch_no) { + item.title = __("Select Serial and Batch"); + } + + frappe.require(path, function () { + new erpnext.SerialBatchPackageSelector(me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; + } + + frappe.model.set_value(item.doctype, item.name, { + serial_and_batch_bundle: r.name, + use_serial_batch_fields: 0, + qty: + qty / + flt( + item.conversion_factor || 1, + precision("conversion_factor", item) + ), + }); + } + }); + }); + } + }); + } + + update_auto_repeat_reference(doc) { + if (doc.auto_repeat) { + frappe.call({ + method: "frappe.automation.doctype.auto_repeat.auto_repeat.update_reference", + args: { + docname: doc.auto_repeat, + reference: doc.name, + }, + callback: function (r) { + if (r.message == "success") { + frappe.show_alert({ + message: __("Auto repeat document updated"), + indicator: "green", + }); + } else { + frappe.show_alert({ + message: __("An error occurred during the update process"), + indicator: "red", + }); + } + }, + }); + } + } + + project() { + let me = this; + if (["Delivery Note", "Sales Invoice", "Sales Order"].includes(this.frm.doc.doctype)) { + if (this.frm.doc.project) { + frappe.call({ + method: "erpnext.projects.doctype.project.project.get_cost_center_name", + args: { project: this.frm.doc.project }, + callback: function (r, rt) { + if (!r.exc) { + $.each(me.frm.doc["items"] || [], function (i, row) { + if (r.message) { + frappe.model.set_value( + row.doctype, + row.name, + "cost_center", + r.message + ); + frappe.msgprint( + __( + "Cost Center For Item with Item Code {0} has been Changed to {1}", + [row.item_name, r.message] + ) + ); + } + }); + } + }, + }); + } + } + } + + coupon_code() { + this.frm.set_value("discount_amount", 0); + this.frm.set_value("additional_discount_percentage", 0); + } + }; + }, +}; + +erpnext.pre_sales = { + set_as_lost: function (doctype) { + frappe.ui.form.on(doctype, { + set_as_lost_dialog: function (frm) { + var dialog = new frappe.ui.Dialog({ + title: __("Set as Lost"), + fields: [ + { + fieldtype: "Table MultiSelect", + label: __("Lost Reasons"), + fieldname: "lost_reason", + options: + frm.doctype === "Opportunity" + ? "Opportunity Lost Reason Detail" + : "Quotation Lost Reason Detail", + reqd: 1, + }, + { + fieldtype: "Table MultiSelect", + label: __("Competitors"), + fieldname: "competitors", + options: "Competitor Detail", + }, + { + fieldtype: "Small Text", + label: __("Detailed Reason"), + fieldname: "detailed_reason", + }, + ], + primary_action: function () { + let values = dialog.get_values(); + + frm.call({ + doc: frm.doc, + method: "declare_enquiry_lost", + args: { + lost_reasons_list: values.lost_reason, + competitors: values.competitors ? values.competitors : [], + detailed_reason: values.detailed_reason, + }, + callback: function (r) { + dialog.hide(); + frm.reload_doc(); + }, + }); + }, + primary_action_label: __("Declare Lost"), + }); + + dialog.show(); + }, + }); + }, +}; diff --git a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js index 5fbb5cb7e01..7aa8012f0b6 100644 --- a/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js +++ b/erpnext/regional/doctype/import_supplier_invoice/import_supplier_invoice.js @@ -34,7 +34,7 @@ frappe.ui.form.on("Import Supplier Invoice", { }, toggle_read_only_fields: function (frm) { - if (in_list(["File Import Completed", "Processing File Data"], frm.doc.status)) { + if (["File Import Completed", "Processing File Data"].includes(frm.doc.status)) { cur_frm.set_read_only(); cur_frm.refresh_fields(); frm.set_df_property("import_invoices", "hidden", 1); diff --git a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js index 53fedbf56cf..a408417c119 100644 --- a/erpnext/selling/page/point_of_sale/pos_past_order_summary.js +++ b/erpnext/selling/page/point_of_sale/pos_past_order_summary.js @@ -73,7 +73,7 @@ erpnext.PointOfSale.PastOrderSummary = class { const { status } = doc; let indicator_color = ""; - in_list(["Paid", "Consolidated"], status) && (indicator_color = "green"); + ["Paid", "Consolidated"].includes(status) && (indicator_color = "green"); status === "Draft" && (indicator_color = "red"); status === "Return" && (indicator_color = "grey"); diff --git a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js index 0f0221fa562..aec752aec77 100644 --- a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js +++ b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.js @@ -8,7 +8,7 @@ frappe.ui.form.on("Closing Stock Balance", { }, generate_closing_balance(frm) { - if (in_list(["Queued", "Failed"], frm.doc.status)) { + if (["Queued", "Failed"].includes(frm.doc.status)) { frm.add_custom_button(__("Generate Closing Stock Balance"), () => { frm.call({ method: "enqueue_job", diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js b/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js index 230107caadb..65a1be33224 100644 --- a/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js +++ b/erpnext/stock/doctype/delivery_trip/delivery_trip_list.js @@ -1,9 +1,9 @@ frappe.listview_settings["Delivery Trip"] = { add_fields: ["status"], get_indicator: function (doc) { - if (in_list(["Cancelled", "Draft"], doc.status)) { + if (["Cancelled", "Draft"].includes(doc.status)) { return [__(doc.status), "red", "status,=," + doc.status]; - } else if (in_list(["In Transit", "Scheduled"], doc.status)) { + } else if (["In Transit", "Scheduled"].includes(doc.status)) { return [__(doc.status), "orange", "status,=," + doc.status]; } else if (doc.status === "Completed") { return [__(doc.status), "green", "status,=," + doc.status]; diff --git a/erpnext/templates/form_grid/item_grid.html b/erpnext/templates/form_grid/item_grid.html index c596890aa32..e78b42d6619 100644 --- a/erpnext/templates/form_grid/item_grid.html +++ b/erpnext/templates/form_grid/item_grid.html @@ -17,8 +17,13 @@ title = "Warehouse", actual_qty = (frm.doc.doctype==="Sales Order" ? doc.projected_qty : doc.actual_qty); +<<<<<<< HEAD if(flt(frm.doc.per_delivered) < 100 && in_list(["Sales Order Item", "Delivery Note Item"], doc.doctype)) { +======= + if(flt(frm.doc.per_delivered, 2) < 100 + && ["Sales Order Item", "Delivery Note Item"].includes(doc.doctype)) { +>>>>>>> d238751e6b (refactor: usage of in_list) if(actual_qty != undefined) { if(actual_qty >= doc.qty) { var color = "green"; From 3b2044dcd768ad290907a524d8b021a468f35164 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:46:14 +0100 Subject: [PATCH 2/3] chore: resolve conflicts --- .../doctype/payment_entry/payment_entry.js | 60 +-- .../doctype/sales_invoice/sales_invoice.js | 2 +- .../doctype/purchase_order/purchase_order.js | 19 +- erpnext/public/js/account_tree_grid.js | 2 +- erpnext/public/js/controllers/accounts.js | 55 +-- erpnext/public/js/controllers/buying.js | 401 +----------------- erpnext/public/js/controllers/transaction.js | 53 +-- erpnext/selling/sales_common.js | 12 +- .../stock/doctype/stock_entry/stock_entry.js | 2 +- erpnext/templates/form_grid/item_grid.html | 5 - 10 files changed, 20 insertions(+), 591 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 8ad31e1e791..33478a54e39 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -21,14 +21,8 @@ frappe.ui.form.on('Payment Entry', { frm.set_query("paid_from", function() { frm.events.validate_company(frm); -<<<<<<< HEAD - var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ? + var account_types = ["Pay", "Internal Transfer"].includes(frm.doc.payment_type) ? ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; -======= - var account_types = ["Pay", "Internal Transfer"].includes(frm.doc.payment_type) - ? ["Bank", "Cash"] - : [frappe.boot.party_account_types[frm.doc.party_type]]; ->>>>>>> d238751e6b (refactor: usage of in_list) return { filters: { "account_type": ["in", account_types], @@ -81,14 +75,8 @@ frappe.ui.form.on('Payment Entry', { frm.set_query("paid_to", function() { frm.events.validate_company(frm); -<<<<<<< HEAD - var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ? + var account_types = ["Receive", "Internal Transfer"].includes(frm.doc.payment_type) ? ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; -======= - var account_types = ["Receive", "Internal Transfer"].includes(frm.doc.payment_type) - ? ["Bank", "Cash"] - : [frappe.boot.party_account_types[frm.doc.party_type]]; ->>>>>>> d238751e6b (refactor: usage of in_list) return { filters: { "account_type": ["in", account_types], @@ -133,14 +121,7 @@ frappe.ui.form.on('Payment Entry', { frm.set_query('payment_term', 'references', function(frm, cdt, cdn) { const child = locals[cdt][cdn]; -<<<<<<< HEAD - if (in_list(['Purchase Invoice', 'Sales Invoice'], child.reference_doctype) && child.reference_name) { -======= - if ( - ["Purchase Invoice", "Sales Invoice"].includes(child.reference_doctype) && - child.reference_name - ) { ->>>>>>> d238751e6b (refactor: usage of in_list) + if (['Purchase Invoice', 'Sales Invoice'].includes(child.reference_doctype) && child.reference_name) { return { query: "erpnext.controllers.queries.get_payment_terms_for_references", filters: { @@ -503,13 +484,8 @@ frappe.ui.form.on('Payment Entry', { if (frm.doc.paid_from_account_currency == company_currency) { frm.set_value("source_exchange_rate", 1); -<<<<<<< HEAD } else if (frm.doc.paid_from){ - if (in_list(["Internal Transfer", "Pay"], frm.doc.payment_type)) { -======= - } else if (frm.doc.paid_from) { if (["Internal Transfer", "Pay"].includes(frm.doc.payment_type)) { ->>>>>>> d238751e6b (refactor: usage of in_list) let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; frappe.call({ method: "erpnext.setup.utils.get_exchange_rate", @@ -876,19 +852,11 @@ frappe.ui.form.on('Payment Entry', { total_negative_outstanding : remaining_outstanding; } -<<<<<<< HEAD var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding; - } else if (in_list(["Customer", "Supplier"], frm.doc.party_type)) { + } else if (["Customer", "Supplier"].includes(frm.doc.party_type)) { total_negative_outstanding = flt(total_negative_outstanding, precision("outstanding_amount")) if(paid_amount > total_negative_outstanding) { if(total_negative_outstanding == 0) { -======= - var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding; - } else if (["Customer", "Supplier"].includes(frm.doc.party_type)) { - total_negative_outstanding = flt(total_negative_outstanding, precision("outstanding_amount")); - if (paid_amount > total_negative_outstanding) { - if (total_negative_outstanding == 0) { ->>>>>>> d238751e6b (refactor: usage of in_list) frappe.msgprint( __("Cannot {0} {1} {2} without any negative outstanding invoice", [frm.doc.payment_type, (frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type]) @@ -1019,28 +987,16 @@ frappe.ui.form.on('Payment Entry', { return; } -<<<<<<< HEAD if(frm.doc.party_type=="Customer" && - !in_list(["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"], row.reference_doctype) -======= - if ( - frm.doc.party_type == "Customer" && !["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"].includes(row.reference_doctype) ->>>>>>> d238751e6b (refactor: usage of in_list) ) { frappe.model.set_value(row.doctype, row.name, "reference_doctype", null); frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Sales Order, Sales Invoice, Journal Entry or Dunning", [row.idx])); return false; } -<<<<<<< HEAD if(frm.doc.party_type=="Supplier" && - !in_list(["Purchase Order", "Purchase Invoice", "Journal Entry"], row.reference_doctype) -======= - if ( - frm.doc.party_type == "Supplier" && !["Purchase Order", "Purchase Invoice", "Journal Entry"].includes(row.reference_doctype) ->>>>>>> d238751e6b (refactor: usage of in_list) ) { frappe.model.set_value(row.doctype, row.name, "against_voucher_type", null); frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx])); @@ -1122,15 +1078,9 @@ frappe.ui.form.on('Payment Entry', { } }, -<<<<<<< HEAD bank_account: function(frm) { const field = frm.doc.payment_type == "Pay" ? "paid_from":"paid_to"; - if (frm.doc.bank_account && in_list(['Pay', 'Receive'], frm.doc.payment_type)) { -======= - bank_account: function (frm) { - const field = frm.doc.payment_type == "Pay" ? "paid_from" : "paid_to"; - if (frm.doc.bank_account && ["Pay", "Receive"].includes(frm.doc.payment_type)) { ->>>>>>> d238751e6b (refactor: usage of in_list) + if (frm.doc.bank_account && ['Pay', 'Receive'].includes(frm.doc.payment_type)) { frappe.call({ method: "erpnext.accounts.doctype.bank_account.bank_account.get_bank_account_details", args: { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index b2672424af9..ad857840147 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -200,7 +200,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e if(cur_frm.meta._default_print_format) { cur_frm.meta.default_print_format = cur_frm.meta._default_print_format; cur_frm.meta._default_print_format = null; - } else if(in_list([cur_frm.pos_print_format, cur_frm.return_print_format], cur_frm.meta.default_print_format)) { + } else if([cur_frm.pos_print_format, cur_frm.return_print_format].includes(cur_frm.meta.default_print_format)) { cur_frm.meta.default_print_format = null; cur_frm.meta._default_print_format = null; } diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index a1a06489957..2a96035f4b5 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -180,22 +180,11 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e this.frm.fields_dict.items_section.wrapper.removeClass("hide-border"); } -<<<<<<< HEAD - if(!in_list(["Closed", "Delivered"], doc.status)) { + if(!["Closed", "Delivered"].includes(doc.status)) { if(this.frm.doc.status !== 'Closed' && flt(this.frm.doc.per_received) < 100 && flt(this.frm.doc.per_billed) < 100) { // Don't add Update Items button if the PO is following the new subcontracting flow. if (!(this.frm.doc.is_subcontracted && !this.frm.doc.is_old_subcontracting_flow)) { this.frm.add_custom_button(__('Update Items'), () => { -======= - if (!["Closed", "Delivered"].includes(doc.status)) { - if ( - this.frm.doc.status !== "Closed" && - flt(this.frm.doc.per_received, 2) < 100 && - flt(this.frm.doc.per_billed, 2) < 100 - ) { - if (!this.frm.doc.__onload || this.frm.doc.__onload.can_update_items) { - this.frm.add_custom_button(__("Update Items"), () => { ->>>>>>> d238751e6b (refactor: usage of in_list) erpnext.utils.update_child_items({ frm: this.frm, child_docname: "items", @@ -222,11 +211,7 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e this.frm.page.set_inner_btn_group_as_primary(__("Status")); } -<<<<<<< HEAD - } else if(in_list(["Closed", "Delivered"], doc.status)) { -======= - } else if (["Closed", "Delivered"].includes(doc.status)) { ->>>>>>> d238751e6b (refactor: usage of in_list) + } else if(["Closed", "Delivered"].includes(doc.status)) { if (this.frm.has_perm("submit")) { this.frm.add_custom_button(__('Re-open'), () => this.unclose_purchase_order(), __("Status")); } diff --git a/erpnext/public/js/account_tree_grid.js b/erpnext/public/js/account_tree_grid.js index 6b4cdf1177a..1d4596ba1a4 100644 --- a/erpnext/public/js/account_tree_grid.js +++ b/erpnext/public/js/account_tree_grid.js @@ -240,7 +240,7 @@ erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridRep flt(account.closing_dr) - flt(account.closing_cr); me.set_debit_or_credit(parent_account, "closing", bal); - } else if (in_list(["debit", "credit"], col.field)) { + } else if (["debit", "credit"].includes(col.field)) { parent_account[col.field] = flt(parent_account[col.field]) + flt(account[col.field]); } diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index 83003418266..1ba941ab6f7 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -5,66 +5,13 @@ frappe.provide("erpnext.taxes"); frappe.provide("erpnext.taxes.flags"); -<<<<<<< HEAD frappe.ui.form.on(cur_frm.doctype, { setup: function(frm) { // set conditional display for rate column in taxes $(frm.wrapper).on('grid-row-render', function(e, grid_row) { - if(in_list(['Sales Taxes and Charges', 'Purchase Taxes and Charges'], grid_row.doc.doctype)) { + if(['Sales Taxes and Charges', 'Purchase Taxes and Charges'].includes(grid_row.doc.doctype)) { erpnext.taxes.set_conditional_mandatory_rate_or_amount(grid_row); } -======= -erpnext.accounts.taxes = { - setup_tax_validations: function(doctype) { - let me = this; - frappe.ui.form.on(doctype, { - setup: function(frm) { - // set conditional display for rate column in taxes - $(frm.wrapper).on('grid-row-render', function(e, grid_row) { - if(['Sales Taxes and Charges', 'Purchase Taxes and Charges'].includes(grid_row.doc.doctype)) { - me.set_conditional_mandatory_rate_or_amount(grid_row); - } - }); - }, - onload: function(frm) { - if(frm.get_field("taxes")) { - frm.set_query("account_head", "taxes", function(doc) { - if(frm.cscript.tax_table == "Sales Taxes and Charges") { - var account_type = ["Tax", "Chargeable", "Expense Account"]; - } else { - var account_type = ["Tax", "Chargeable", "Income Account", "Expenses Included In Valuation"]; - } - - return { - query: "erpnext.controllers.queries.tax_account_query", - filters: { - "account_type": account_type, - "company": doc.company, - } - } - }); - frm.set_query("cost_center", "taxes", function(doc) { - return { - filters: { - "company": doc.company, - "is_group": 0 - } - }; - }); - } - }, - validate: function(frm) { - // neither is absolutely mandatory - if(frm.get_docfield("taxes")) { - frm.get_docfield("taxes", "rate").reqd = 0; - frm.get_docfield("taxes", "tax_amount").reqd = 0; - } - - }, - taxes_on_form_rendered: function(frm) { - me.set_conditional_mandatory_rate_or_amount(frm.open_grid_row()); - }, ->>>>>>> d238751e6b (refactor: usage of in_list) }); }, onload: function(frm) { diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index ab2a476a1d4..aa7dfbd90d6 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -9,408 +9,9 @@ cur_frm.cscript.tax_table = "Purchase Taxes and Charges"; cur_frm.email_field = "contact_email"; -<<<<<<< HEAD erpnext.buying.BuyingController = class BuyingController extends erpnext.TransactionController { setup() { super.setup(); -======= - if (this.frm.doc.__islocal - && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) { - - var df = frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total"); - var disable = cint(df.default) || cint(frappe.sys_defaults.disable_rounded_total); - this.frm.set_value("disable_rounded_total", disable); - } - - - // no idea where me is coming from - if(this.frm.get_field('shipping_address')) { - this.frm.set_query("shipping_address", () => { - if(this.frm.doc.customer) { - return { - query: 'frappe.contacts.doctype.address.address.address_query', - filters: { link_doctype: 'Customer', link_name: this.frm.doc.customer } - }; - } else - return erpnext.queries.company_address_query(this.frm.doc) - }); - } - } - - setup_queries(doc, cdt, cdn) { - var me = this; - - if(this.frm.fields_dict.buying_price_list) { - this.frm.set_query("buying_price_list", function() { - return{ - filters: { 'buying': 1 } - } - }); - } - - if(this.frm.fields_dict.tc_name) { - this.frm.set_query("tc_name", function() { - return{ - filters: { 'buying': 1 } - } - }); - } - - me.frm.set_query('supplier', erpnext.queries.supplier); - me.frm.set_query('contact_person', erpnext.queries.contact_query); - me.frm.set_query('supplier_address', erpnext.queries.address_query); - - me.frm.set_query('billing_address', erpnext.queries.company_address_query); - erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype); - - this.frm.set_query("item_code", "items", function() { - if (me.frm.doc.is_subcontracted) { - var filters = {'supplier': me.frm.doc.supplier}; - if (me.frm.doc.is_old_subcontracting_flow) { - filters["is_sub_contracted_item"] = 1; - } - else { - filters["is_stock_item"] = 0; - } - - return{ - query: "erpnext.controllers.queries.item_query", - filters: filters - } - } - else { - return{ - query: "erpnext.controllers.queries.item_query", - filters: { 'supplier': me.frm.doc.supplier, 'is_purchase_item': 1, 'has_variants': 0} - } - } - }); - - - this.frm.set_query("manufacturer", "items", function(doc, cdt, cdn) { - const row = locals[cdt][cdn]; - return { - query: "erpnext.controllers.queries.item_manufacturer_query", - filters:{ 'item_code': row.item_code } - } - }); - - if(this.frm.fields_dict["items"].grid.get_field('item_code')) { - this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) { - return me.set_query_for_item_tax_template(doc, cdt, cdn) - }); - } - } - - refresh(doc) { - frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'}; - - this.frm.toggle_display("supplier_name", - (this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier)); - - if(this.frm.doc.docstatus==0 && - (this.frm.doctype==="Purchase Order" || this.frm.doctype==="Material Request")) { - this.set_from_product_bundle(); - } - - this.toggle_subcontracting_fields(); - super.refresh(); - } - - toggle_subcontracting_fields() { - if (['Purchase Receipt', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { - this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', - 'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM'); - - this.frm.set_df_property('supplied_items', 'cannot_add_rows', 1); - this.frm.set_df_property('supplied_items', 'cannot_delete_rows', 1); - } - } - - supplier() { - var me = this; - erpnext.utils.get_party_details(this.frm, null, null, function(){ - me.apply_price_list(); - }); - } - - supplier_address() { - erpnext.utils.get_address_display(this.frm); - erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address"); - } - - buying_price_list() { - this.apply_price_list(); - } - - discount_percentage(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - item.discount_amount = 0.0; - this.price_list_rate(doc, cdt, cdn); - } - - discount_amount(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - item.discount_percentage = 0.0; - this.price_list_rate(doc, cdt, cdn); - } - - qty(doc, cdt, cdn) { - if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) { - this.calculate_received_qty(doc, cdt, cdn) - } - super.qty(doc, cdt, cdn); - } - - rejected_qty(doc, cdt, cdn) { - this.calculate_received_qty(doc, cdt, cdn) - } - - calculate_received_qty(doc, cdt, cdn){ - var item = frappe.get_doc(cdt, cdn); - frappe.model.round_floats_in(item, ["qty", "rejected_qty"]); - - if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return } - - let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item)); - let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty); - - frappe.model.set_value(cdt, cdn, "received_qty", received_qty); - frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty); - } - - batch_no(doc, cdt, cdn) { - super.batch_no(doc, cdt, cdn); - } - - validate_negative_quantity(cdt, cdn, item, fieldnames){ - if(!item || !fieldnames) { return } - - var is_negative_qty = false; - for(var i = 0; i{0} is invalid", [row.manufacturer_part_no]), - title: __("Invalid Part Number") - } - frappe.throw(msg); - } - } - ); - } - } - - add_serial_batch_bundle(doc, cdt, cdn) { - let item = locals[cdt][cdn]; - let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; - - frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) - .then((r) => { - if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { - item.has_serial_no = r.message.has_serial_no; - item.has_batch_no = r.message.has_batch_no; - item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; - item.is_rejected = false; - - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - let update_values = { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - } - - if (r.warehouse) { - update_values["warehouse"] = r.warehouse; - } - - frappe.model.set_value(item.doctype, item.name, update_values); - } - } - ); - }); - } - }); - } - - add_serial_batch_for_rejected_qty(doc, cdt, cdn) { - let item = locals[cdt][cdn]; - let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; - - frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) - .then((r) => { - if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { - item.has_serial_no = r.message.has_serial_no; - item.has_batch_no = r.message.has_batch_no; - item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; - item.is_rejected = true; - - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - let update_values = { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - } - - if (r.warehouse) { - update_values["rejected_warehouse"] = r.warehouse; - } - - frappe.model.set_value(item.doctype, item.name, update_values); - } - } - ); - }); - } - }); - } - }; ->>>>>>> d238751e6b (refactor: usage of in_list) } onload(doc, cdt, cdn) { @@ -535,7 +136,7 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac } toggle_subcontracting_fields() { - if (in_list(['Purchase Receipt', 'Purchase Invoice'], this.frm.doc.doctype)) { + if (['Purchase Receipt', 'Purchase Invoice'].includes(this.frm.doc.doctype)) { this.frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', 'read_only', this.frm.doc.__onload && this.frm.doc.__onload.backflush_based_on === 'BOM'); diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 2d836ad1e2f..e3e25499b84 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -260,11 +260,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } setup_quality_inspection() { -<<<<<<< HEAD - if(!in_list(["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)) { -======= - if(!["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"].includes(this.frm.doc.doctype)) { ->>>>>>> d238751e6b (refactor: usage of in_list) + if(!["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"].includes(this.frm.doc.doctype)) { return; } @@ -276,11 +272,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.frm.page.set_inner_btn_group_as_primary(__('Create')); } -<<<<<<< HEAD - const inspection_type = in_list(["Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype) -======= - const inspection_type = ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"].includes(this.frm.doc.doctype) ->>>>>>> d238751e6b (refactor: usage of in_list) + const inspection_type = ["Purchase Receipt", "Purchase Invoice"].includes(this.frm.doc.doctype) ? "Incoming" : "Outgoing"; let quality_inspection_field = this.frm.get_docfield("items", "quality_inspection"); @@ -699,24 +691,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } -<<<<<<< HEAD -======= - on_submit() { - if (["Purchase Invoice", "Sales Invoice"].includes(this.frm.doc.doctype) - && !this.frm.doc.update_stock) { - return; - } - - this.refresh_serial_batch_bundle_field(); - } - - refresh_serial_batch_bundle_field() { - frappe.route_hooks.after_submit = (frm_obj) => { - frm_obj.reload_doc(); - } - } - ->>>>>>> d238751e6b (refactor: usage of in_list) update_qty(cdt, cdn) { var valid_serial_nos = []; var serialnos = []; @@ -2377,7 +2351,6 @@ erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_ } frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { -<<<<<<< HEAD new erpnext.SerialNoBatchSelector({ frm: frm, item: d, @@ -2388,28 +2361,6 @@ erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_ callback: callback, on_close: on_close }, show_dialog); -======= - if (["Sales Invoice", "Delivery Note"].includes(frm.doc.doctype)) { - item_row.type_of_transaction = frm.doc.is_return ? "Inward" : "Outward"; - } else { - item_row.type_of_transaction = frm.doc.is_return ? "Outward" : "Inward"; - } - - new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { - if (r) { - let update_values = { - "serial_and_batch_bundle": r.name, - "qty": Math.abs(r.total_qty) - } - - if (r.warehouse) { - update_values[warehouse_field] = r.warehouse; - } - - frappe.model.set_value(item_row.doctype, item_row.name, update_values); - } - }); ->>>>>>> d238751e6b (refactor: usage of in_list) }); } diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index b2a64a5d461..ad2f1e5f282 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -219,7 +219,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran serial_no: item.serial_no || "", }, callback:function(r){ - if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + if (['Delivery Note', 'Sales Invoice'].includes(doc.doctype)) { if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; if (has_batch_no) { me.set_batch_number(cdt, cdn); @@ -332,7 +332,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran if ((doc.packed_items || []).length) { $(cur_frm.fields_dict.packing_list.row.wrapper).toggle(true); - if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + if (['Delivery Note', 'Sales Invoice'].includes(doc.doctype)) { var help_msg = "
" + __("For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table.")+ "
"; @@ -340,7 +340,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran } } else { $(cur_frm.fields_dict.packing_list.row.wrapper).toggle(false); - if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + if (['Delivery Note', 'Sales Invoice'].includes(doc.doctype)) { frappe.meta.get_docfield(doc.doctype, 'product_bundle_help', doc.name).options = ''; } } @@ -367,7 +367,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) { super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate); if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) && - in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + ['Delivery Note', 'Sales Invoice'].includes(doc.doctype)) { if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; this.set_batch_number(cdt, cdn); } @@ -376,7 +376,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran qty(doc, cdt, cdn) { super.qty(doc, cdt, cdn); - if(in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + if(['Delivery Note', 'Sales Invoice'].includes(doc.doctype)) { if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; this.set_batch_number(cdt, cdn); } @@ -440,7 +440,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran }; frappe.ui.form.on(cur_frm.doctype,"project", function(frm) { - if(in_list(["Delivery Note", "Sales Invoice"], frm.doc.doctype)) { + if(["Delivery Note", "Sales Invoice"].includes(frm.doc.doctype)) { if(frm.doc.project) { frappe.call({ method:'erpnext.projects.doctype.project.project.get_cost_center_name' , diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index b6459ba1e28..d58361b2d3b 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -77,7 +77,7 @@ frappe.ui.form.on('Stock Entry', { if(!item.item_code) { frappe.throw(__("Please enter Item Code to get Batch Number")); } else { - if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Send to Subcontractor"], doc.purpose)) { + if (["Material Transfer for Manufacture", "Manufacture", "Repack", "Send to Subcontractor"].includes(doc.purpose)) { var filters = { 'item_code': item.item_code, 'posting_date': frm.doc.posting_date || frappe.datetime.nowdate() diff --git a/erpnext/templates/form_grid/item_grid.html b/erpnext/templates/form_grid/item_grid.html index e78b42d6619..449edd14e15 100644 --- a/erpnext/templates/form_grid/item_grid.html +++ b/erpnext/templates/form_grid/item_grid.html @@ -17,13 +17,8 @@ title = "Warehouse", actual_qty = (frm.doc.doctype==="Sales Order" ? doc.projected_qty : doc.actual_qty); -<<<<<<< HEAD if(flt(frm.doc.per_delivered) < 100 - && in_list(["Sales Order Item", "Delivery Note Item"], doc.doctype)) { -======= - if(flt(frm.doc.per_delivered, 2) < 100 && ["Sales Order Item", "Delivery Note Item"].includes(doc.doctype)) { ->>>>>>> d238751e6b (refactor: usage of in_list) if(actual_qty != undefined) { if(actual_qty >= doc.qty) { var color = "green"; From d0a0a35d72f5cb809c793853fa7d125135a85e44 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:53:20 +0100 Subject: [PATCH 3/3] chore: remove accidentally added file --- erpnext/public/js/utils/sales_common.js | 510 ------------------------ 1 file changed, 510 deletions(-) delete mode 100644 erpnext/public/js/utils/sales_common.js diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js deleted file mode 100644 index 00df1c5c191..00000000000 --- a/erpnext/public/js/utils/sales_common.js +++ /dev/null @@ -1,510 +0,0 @@ -// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -frappe.provide("erpnext.selling"); - -erpnext.sales_common = { - setup_selling_controller: function () { - erpnext.selling.SellingController = class SellingController extends erpnext.TransactionController { - setup() { - super.setup(); - this.toggle_enable_for_stock_uom("allow_to_edit_stock_uom_qty_for_sales"); - this.frm.email_field = "contact_email"; - } - - onload() { - super.onload(); - this.setup_queries(); - this.frm.set_query("shipping_rule", function () { - return { - filters: { - shipping_rule_type: "Selling", - }, - }; - }); - - this.frm.set_query("project", function (doc) { - return { - query: "erpnext.controllers.queries.get_project_name", - filters: { - customer: doc.customer, - }, - }; - }); - } - - setup_queries() { - var me = this; - - $.each( - [ - ["customer", "customer"], - ["lead", "lead"], - ], - function (i, opts) { - if (me.frm.fields_dict[opts[0]]) me.frm.set_query(opts[0], erpnext.queries[opts[1]]); - } - ); - - me.frm.set_query("contact_person", erpnext.queries.contact_query); - me.frm.set_query("customer_address", erpnext.queries.address_query); - me.frm.set_query("shipping_address_name", erpnext.queries.address_query); - me.frm.set_query("dispatch_address_name", erpnext.queries.dispatch_address_query); - - erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype); - - if (this.frm.fields_dict.selling_price_list) { - this.frm.set_query("selling_price_list", function () { - return { filters: { selling: 1 } }; - }); - } - - if (this.frm.fields_dict.tc_name) { - this.frm.set_query("tc_name", function () { - return { filters: { selling: 1 } }; - }); - } - - if (!this.frm.fields_dict["items"]) { - return; - } - - if (this.frm.fields_dict["items"].grid.get_field("item_code")) { - this.frm.set_query("item_code", "items", function () { - return { - query: "erpnext.controllers.queries.item_query", - filters: { is_sales_item: 1, customer: me.frm.doc.customer, has_variants: 0 }, - }; - }); - } - - if ( - this.frm.fields_dict["packed_items"] && - this.frm.fields_dict["packed_items"].grid.get_field("batch_no") - ) { - this.frm.set_query("batch_no", "packed_items", function (doc, cdt, cdn) { - return me.set_query_for_batch(doc, cdt, cdn); - }); - } - - if (this.frm.fields_dict["items"].grid.get_field("item_code")) { - this.frm.set_query("item_tax_template", "items", function (doc, cdt, cdn) { - return me.set_query_for_item_tax_template(doc, cdt, cdn); - }); - } - } - - refresh() { - super.refresh(); - - frappe.dynamic_link = { doc: this.frm.doc, fieldname: "customer", doctype: "Customer" }; - - this.frm.toggle_display( - "customer_name", - this.frm.doc.customer_name && this.frm.doc.customer_name !== this.frm.doc.customer - ); - - this.toggle_editable_price_list_rate(); - } - - customer() { - var me = this; - erpnext.utils.get_party_details(this.frm, null, null, function () { - me.apply_price_list(); - }); - } - - customer_address() { - erpnext.utils.get_address_display(this.frm, "customer_address"); - erpnext.utils.set_taxes_from_address( - this.frm, - "customer_address", - "customer_address", - "shipping_address_name" - ); - } - - shipping_address_name() { - erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address"); - erpnext.utils.set_taxes_from_address( - this.frm, - "shipping_address_name", - "customer_address", - "shipping_address_name" - ); - } - - dispatch_address_name() { - erpnext.utils.get_address_display(this.frm, "dispatch_address_name", "dispatch_address"); - } - - sales_partner() { - this.apply_pricing_rule(); - } - - campaign() { - this.apply_pricing_rule(); - } - - selling_price_list() { - this.apply_price_list(); - this.set_dynamic_labels(); - } - - discount_percentage(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - item.discount_amount = 0.0; - this.apply_discount_on_item(doc, cdt, cdn, "discount_percentage"); - } - - discount_amount(doc, cdt, cdn) { - if (doc.name === cdn) { - return; - } - - var item = frappe.get_doc(cdt, cdn); - item.discount_percentage = 0.0; - this.apply_discount_on_item(doc, cdt, cdn, "discount_amount"); - } - - commission_rate() { - this.calculate_commission(); - } - - total_commission() { - frappe.model.round_floats_in(this.frm.doc, [ - "amount_eligible_for_commission", - "total_commission", - ]); - - const { amount_eligible_for_commission } = this.frm.doc; - if (!amount_eligible_for_commission) return; - - this.frm.set_value( - "commission_rate", - flt((this.frm.doc.total_commission * 100.0) / amount_eligible_for_commission) - ); - } - - allocated_percentage(doc, cdt, cdn) { - var sales_person = frappe.get_doc(cdt, cdn); - if (sales_person.allocated_percentage) { - sales_person.allocated_percentage = flt( - sales_person.allocated_percentage, - precision("allocated_percentage", sales_person) - ); - - sales_person.allocated_amount = flt( - (this.frm.doc.amount_eligible_for_commission * sales_person.allocated_percentage) / - 100.0, - precision("allocated_amount", sales_person) - ); - refresh_field(["allocated_amount"], sales_person); - - this.calculate_incentive(sales_person); - refresh_field( - ["allocated_percentage", "allocated_amount", "commission_rate", "incentives"], - sales_person.name, - sales_person.parentfield - ); - } - } - - sales_person(doc, cdt, cdn) { - var row = frappe.get_doc(cdt, cdn); - this.calculate_incentive(row); - refresh_field("incentives", row.name, row.parentfield); - } - - warehouse(doc, cdt, cdn) { - if (doc.docstatus === 0 && doc.is_return && !doc.return_against) { - frappe.model.set_value(cdt, cdn, "incoming_rate", 0.0); - } - } - - toggle_editable_price_list_rate() { - var df = frappe.meta.get_docfield( - this.frm.doc.doctype + " Item", - "price_list_rate", - this.frm.doc.name - ); - var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate")); - - if (df && editable_price_list_rate) { - const parent_field = frappe.meta.get_parentfield( - this.frm.doc.doctype, - this.frm.doc.doctype + " Item" - ); - if (!this.frm.fields_dict[parent_field]) return; - - this.frm.fields_dict[parent_field].grid.update_docfield_property( - "price_list_rate", - "read_only", - 0 - ); - } - } - - calculate_commission() { - if (!this.frm.fields_dict.commission_rate || this.frm.doc.docstatus === 1) return; - - if (this.frm.doc.commission_rate > 100) { - this.frm.set_value("commission_rate", 100); - frappe.throw( - `${__( - frappe.meta.get_label(this.frm.doc.doctype, "commission_rate", this.frm.doc.name) - )} ${__("cannot be greater than 100")}` - ); - } - - this.frm.doc.amount_eligible_for_commission = this.frm.doc.items.reduce( - (sum, item) => (item.grant_commission ? sum + item.base_net_amount : sum), - 0 - ); - - this.frm.doc.total_commission = flt( - (this.frm.doc.amount_eligible_for_commission * this.frm.doc.commission_rate) / 100.0, - precision("total_commission") - ); - - refresh_field(["amount_eligible_for_commission", "total_commission"]); - } - - calculate_contribution() { - var me = this; - $.each(this.frm.doc.doctype.sales_team || [], function (i, sales_person) { - frappe.model.round_floats_in(sales_person); - if (!sales_person.allocated_percentage) return; - - sales_person.allocated_amount = flt( - (me.frm.doc.amount_eligible_for_commission * sales_person.allocated_percentage) / - 100.0, - precision("allocated_amount", sales_person) - ); - }); - } - - calculate_incentive(row) { - if (row.allocated_amount) { - row.incentives = flt( - (row.allocated_amount * row.commission_rate) / 100.0, - precision("incentives", row) - ); - } - } - - set_dynamic_labels() { - super.set_dynamic_labels(); - this.set_product_bundle_help(this.frm.doc); - } - - set_product_bundle_help(doc) { - if (!this.frm.fields_dict.packing_list) return; - if ((doc.packed_items || []).length) { - $(this.frm.fields_dict.packing_list.row.wrapper).toggle(true); - - if (["Delivery Note", "Sales Invoice"].includes(doc.doctype)) { - var help_msg = - "
" + - __( - "For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table." - ) + - "
"; - frappe.meta.get_docfield(doc.doctype, "product_bundle_help", doc.name).options = - help_msg; - } - } else { - $(this.frm.fields_dict.packing_list.row.wrapper).toggle(false); - if (["Delivery Note", "Sales Invoice"].includes(doc.doctype)) { - frappe.meta.get_docfield(doc.doctype, "product_bundle_help", doc.name).options = ""; - } - } - refresh_field("product_bundle_help"); - } - - company_address() { - var me = this; - if (this.frm.doc.company_address) { - frappe.call({ - method: "frappe.contacts.doctype.address.address.get_address_display", - args: { address_dict: this.frm.doc.company_address }, - callback: function (r) { - if (r.message) { - me.frm.set_value("company_address_display", r.message); - } - }, - }); - } else { - this.frm.set_value("company_address_display", ""); - } - } - - conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) { - super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate); - } - - qty(doc, cdt, cdn) { - super.qty(doc, cdt, cdn); - } - - pick_serial_and_batch(doc, cdt, cdn) { - let item = locals[cdt][cdn]; - let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; - - frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]).then((r) => { - if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { - item.has_serial_no = r.message.has_serial_no; - item.has_batch_no = r.message.has_batch_no; - item.type_of_transaction = item.qty > 0 ? "Outward" : "Inward"; - - item.title = item.has_serial_no ? __("Select Serial No") : __("Select Batch No"); - - if (item.has_serial_no && item.has_batch_no) { - item.title = __("Select Serial and Batch"); - } - - frappe.require(path, function () { - new erpnext.SerialBatchPackageSelector(me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - frappe.model.set_value(item.doctype, item.name, { - serial_and_batch_bundle: r.name, - use_serial_batch_fields: 0, - qty: - qty / - flt( - item.conversion_factor || 1, - precision("conversion_factor", item) - ), - }); - } - }); - }); - } - }); - } - - update_auto_repeat_reference(doc) { - if (doc.auto_repeat) { - frappe.call({ - method: "frappe.automation.doctype.auto_repeat.auto_repeat.update_reference", - args: { - docname: doc.auto_repeat, - reference: doc.name, - }, - callback: function (r) { - if (r.message == "success") { - frappe.show_alert({ - message: __("Auto repeat document updated"), - indicator: "green", - }); - } else { - frappe.show_alert({ - message: __("An error occurred during the update process"), - indicator: "red", - }); - } - }, - }); - } - } - - project() { - let me = this; - if (["Delivery Note", "Sales Invoice", "Sales Order"].includes(this.frm.doc.doctype)) { - if (this.frm.doc.project) { - frappe.call({ - method: "erpnext.projects.doctype.project.project.get_cost_center_name", - args: { project: this.frm.doc.project }, - callback: function (r, rt) { - if (!r.exc) { - $.each(me.frm.doc["items"] || [], function (i, row) { - if (r.message) { - frappe.model.set_value( - row.doctype, - row.name, - "cost_center", - r.message - ); - frappe.msgprint( - __( - "Cost Center For Item with Item Code {0} has been Changed to {1}", - [row.item_name, r.message] - ) - ); - } - }); - } - }, - }); - } - } - } - - coupon_code() { - this.frm.set_value("discount_amount", 0); - this.frm.set_value("additional_discount_percentage", 0); - } - }; - }, -}; - -erpnext.pre_sales = { - set_as_lost: function (doctype) { - frappe.ui.form.on(doctype, { - set_as_lost_dialog: function (frm) { - var dialog = new frappe.ui.Dialog({ - title: __("Set as Lost"), - fields: [ - { - fieldtype: "Table MultiSelect", - label: __("Lost Reasons"), - fieldname: "lost_reason", - options: - frm.doctype === "Opportunity" - ? "Opportunity Lost Reason Detail" - : "Quotation Lost Reason Detail", - reqd: 1, - }, - { - fieldtype: "Table MultiSelect", - label: __("Competitors"), - fieldname: "competitors", - options: "Competitor Detail", - }, - { - fieldtype: "Small Text", - label: __("Detailed Reason"), - fieldname: "detailed_reason", - }, - ], - primary_action: function () { - let values = dialog.get_values(); - - frm.call({ - doc: frm.doc, - method: "declare_enquiry_lost", - args: { - lost_reasons_list: values.lost_reason, - competitors: values.competitors ? values.competitors : [], - detailed_reason: values.detailed_reason, - }, - callback: function (r) { - dialog.hide(); - frm.reload_doc(); - }, - }); - }, - primary_action_label: __("Declare Lost"), - }); - - dialog.show(); - }, - }); - }, -};