diff --git a/addons/account/static/src/js/section_and_note_fields_backend.js b/addons/account/static/src/js/section_and_note_fields_backend.js index 26328cc045b..1f232ac0db8 100644 --- a/addons/account/static/src/js/section_and_note_fields_backend.js +++ b/addons/account/static/src/js/section_and_note_fields_backend.js @@ -6,9 +6,6 @@ odoo.define('account.section_and_note_backend', function (require) { // [UPDATED] now also allows configuring products on sale order. "use strict"; -var pyUtils = require('web.py_utils'); -var core = require('web.core'); -var _t = core._t; var FieldChar = require('web.basic_fields').FieldChar; var FieldOne2Many = require('web.relational_fields').FieldOne2Many; var fieldRegistry = require('web.field_registry'); @@ -72,121 +69,6 @@ var SectionAndNoteListRenderer = ListRenderer.extend({ return this._super.apply(this, arguments).then(function () { self.$('> table').addClass('o_section_and_note_list_view'); }); - }, - /** - * Add support for product configurator - * - * @override - * @private - */ - _onAddRecord: function (ev) { - // we don't want the browser to navigate to a the # url - ev.preventDefault(); - - // we don't want the click to cause other effects, such as unselecting - // the row that we are creating, because it counts as a click on a tr - ev.stopPropagation(); - - // but we do want to unselect current row - var self = this; - this.unselectRow().then(function () { - var context = ev.currentTarget.dataset.context; - - var pricelistId = self._getPricelistId(); - if (context && pyUtils.py_eval(context).open_product_configurator){ - self._rpc({ - model: 'ir.model.data', - method: 'xmlid_to_res_id', - kwargs: {xmlid: 'sale.sale_product_configurator_view_form'}, - }).then(function (res_id) { - self.do_action({ - name: _t('Configure a product'), - type: 'ir.actions.act_window', - res_model: 'sale.product.configurator', - views: [[res_id, 'form']], - target: 'new', - context: { - 'default_pricelist_id': pricelistId - } - }, { - on_close: function (products) { - if (products && products !== 'special'){ - self.trigger_up('add_record', { - context: self._productsToRecords(products), - forceEditable: "bottom" , - allowWarning: true, - onSuccess: function (){ - self.unselectRow(); - } - }); - } - } - }); - }); - } else { - self.trigger_up('add_record', {context: context && [context]}); // TODO write a test, the deferred was not considered - } - }); - }, - - /** - * Will try to get the pricelist_id value from the parent sale_order form - * - * @private - * @returns {integer} pricelist_id's id - */ - _getPricelistId: function () { - var saleOrderForm = this.getParent() && this.getParent().getParent(); - var stateData = saleOrderForm && saleOrderForm.state && saleOrderForm.state.data; - var pricelist_id = stateData.pricelist_id && stateData.pricelist_id.data && stateData.pricelist_id.data.id; - - return pricelist_id; - }, - - /** - * Will map the products to appropriate record objects that are - * ready for the default_get - * - * @private - * @param {Array} products The products to transform into records - */ - _productsToRecords: function (products) { - var records = []; - _.each(products, function (product){ - var record = { - default_product_id: product.product_id, - default_product_uom_qty: product.quantity - }; - - if (product.no_variant_attribute_values) { - var default_product_no_variant_attribute_values = []; - _.each(product.no_variant_attribute_values, function (attribute_value) { - default_product_no_variant_attribute_values.push( - [4, parseInt(attribute_value.value)] - ); - }); - record['default_product_no_variant_attribute_value_ids'] - = default_product_no_variant_attribute_values; - } - - if (product.product_custom_attribute_values) { - var default_custom_attribute_values = []; - _.each(product.product_custom_attribute_values, function (attribute_value) { - default_custom_attribute_values.push( - [0, 0, { - attribute_value_id: attribute_value.attribute_value_id, - custom_value: attribute_value.custom_value - }] - ); - }); - record['default_product_custom_attribute_value_ids'] - = default_custom_attribute_values; - } - - records.push(record); - }); - - return records; } }); diff --git a/addons/event_sale/static/src/js/event_configurator_test_ui.js b/addons/event_sale/static/src/js/event_configurator_test_ui.js index 9be91f9c170..2a748e7b865 100644 --- a/addons/event_sale/static/src/js/event_configurator_test_ui.js +++ b/addons/event_sale/static/src/js/event_configurator_test_ui.js @@ -27,7 +27,8 @@ tour.register('event_configurator_tour', { var keyDownEvent = jQuery.Event("keydown"); keyDownEvent.which = 42; $input.trigger(keyDownEvent); - } + }, + id: 'product_selection_step' }, { trigger: 'ul.ui-autocomplete a:contains("EVENT")', run: 'click' diff --git a/addons/event_sale/static/src/js/event_configurator_widget.js b/addons/event_sale/static/src/js/event_configurator_widget.js index f03a8366daa..5324a1fc16b 100644 --- a/addons/event_sale/static/src/js/event_configurator_widget.js +++ b/addons/event_sale/static/src/js/event_configurator_widget.js @@ -2,8 +2,7 @@ odoo.define('event.configurator', function (require) { var relationalFields = require('web.relational_fields'); var FieldsRegistry = require('web.field_registry'); -var core = require('web.core'); -var _t = core._t; +var EventConfiguratorWidgetMixin = require('event_sale.EventConfiguratorWidgetMixin'); /** * The event configurator widget is a simple FieldMany2One that adds the capability @@ -15,38 +14,21 @@ var _t = core._t; * * !!! It should only be used on a product_id field !!! */ -var EventConfiguratorWidget = relationalFields.FieldMany2One.extend({ - events: _.extend({}, relationalFields.FieldMany2One.prototype.events, { - 'click .o_event_sale_js_event_configurator_edit': '_onEditEventConfiguration' - }), +var EventConfiguratorWidget = relationalFields.FieldMany2One.extend(EventConfiguratorWidgetMixin, { + events: _.extend({}, + relationalFields.FieldMany2One.prototype.events, + EventConfiguratorWidgetMixin.events + ), /** - * This method will check if the current product set on the SO line is a configurable event. - * -> If so, we add a 'Edit Configuration' button next to the dropdown. - * + * @see _addEventConfigurationEditButton for more info * @override */ start: function () { - var prom = this._super.apply(this, arguments); - - var $inputDropdown = this.$('.o_input_dropdown'); - - if (this.recordData.event_ok && - $inputDropdown.length !== 0 && - this.$('.o_event_sale_js_event_configurator_edit').length === 0) { - var $editConfigurationButton = $('