Skip to content
Permalink
Browse files

[REF] product_configurator

  • Loading branch information...
Feyensv committed May 14, 2019
1 parent c07dc6e commit 99188b591db8cb5162c4e42bb2e138409877572b
Showing with 390 additions and 461 deletions.
  1. +5 −12 addons/event_sale/static/src/js/event_configurator_test_ui.js
  2. +88 −32 addons/event_sale/static/src/js/event_configurator_widget.js
  3. +0 −124 addons/event_sale/static/src/js/event_configurator_widget_mixin.js
  4. +0 −9 addons/event_sale/static/src/scss/event_configurator_widget.scss
  5. +1 −1 addons/event_sale/static/tests/event_configurator.test.js
  6. +0 −4 addons/event_sale/views/assets.xml
  7. +0 −1 addons/event_sale/views/sale_order_views.xml
  8. +0 −1 addons/event_sale_product_configurator/__init__.py
  9. +0 −19 addons/event_sale_product_configurator/__manifest__.py
  10. +0 −27 addons/event_sale_product_configurator/static/src/js/event_configurator_test_ui.js
  11. +0 −43 addons/event_sale_product_configurator/static/src/js/product_configurator_widget.js
  12. +0 −9 addons/event_sale_product_configurator/views/assets.xml
  13. +1 −0 addons/sale/models/sale.py
  14. +194 −0 addons/sale/static/src/js/p_configurator_widget.js
  15. +11 −1 addons/sale/static/src/scss/product_configurator.scss
  16. +1 −0 addons/sale/views/assets.xml
  17. +15 −0 addons/sale/views/sale_views.xml
  18. +0 −1 addons/sale_product_configurator/models/sale_order_line.py
  19. +64 −145 addons/sale_product_configurator/static/src/js/product_configurator_widget.js
  20. +0 −9 addons/sale_product_configurator/static/src/scss/product_configurator_widget.scss
  21. +0 −3 addons/sale_product_configurator/views/assets.xml
  22. +10 −20 addons/sale_product_configurator/views/sale_views.xml
@@ -18,17 +18,10 @@ tour.register('event_configurator_tour', {
}, {
trigger: "a:contains('Add a product')"
}, {
trigger: 'div[name="product_id"] input',
run: function (){
var $input = $('div[name="product_id"] input');
$input.click();
$input.val('EVENT');
// fake keydown to trigger search
var keyDownEvent = jQuery.Event("keydown");
keyDownEvent.which = 42;
$input.trigger(keyDownEvent);
},
id: 'product_selection_step'
trigger: 'div[name="product_id"] input, div[name="product_template_id"] input',
run: function (actions){
actions.text('EVENT');
}
}, {
trigger: 'ul.ui-autocomplete a:contains("EVENT")',
run: 'click'
@@ -66,7 +59,7 @@ tour.register('event_configurator_tour', {
trigger: 'td:contains("EVENT")',
run: 'click'
}, {
trigger: '.o_event_sale_js_event_configurator_edit'
trigger: '.o_edit_product_configuration'
}, {
trigger: 'div[name="event_ticket_id"] input',
run: 'click'
@@ -1,59 +1,115 @@
odoo.define('event.configurator', function (require) {

var relationalFields = require('web.relational_fields');
var FieldsRegistry = require('web.field_registry');
var EventConfiguratorWidgetMixin = require('event_sale.EventConfiguratorWidgetMixin');
odoo.define('event_sale.product_configurator', function (require) {
var ProductConfiguratorWidget = require('sale.product_configurator');

/**
* The event configurator widget is a simple FieldMany2One that adds the capability
* to configure a product_id with event information using the event configurator wizard.
* Extension of the ProductConfiguratorWidget to support event product configuration.
* It opens when an event product_product is set.
*
* The event information include:
* - event_id
* - event_ticket_id
*
* !!! It should only be used on a product_id field !!!
*/
var EventConfiguratorWidget = relationalFields.FieldMany2One.extend(EventConfiguratorWidgetMixin, {
events: _.extend({},
relationalFields.FieldMany2One.prototype.events,
EventConfiguratorWidgetMixin.events
),
ProductConfiguratorWidget.include({
_isConfigurableProduct: function () {
return this._super.apply(this) ||
this.recordData.event_ok;
},

_onProductChange: function (ev) {
var self = this;
var productId = ev.data.changes.product_id.id;
self._checkForEvent(productId, ev.data.dataPointID);
},

/**
* @see _addEventConfigurationEditButton for more info
* @override
* This method will check if the productId needs configuration or not:
*
* @param {integer} productId
* @param {string} dataPointID
*/
start: function () {
_checkForEvent: function (productId, dataPointID) {
var self = this;
return this._super.apply(this, arguments).then(function () {
self._addEventConfigurationEditButton();
});
if (productId){
this._rpc({
model: 'product.product',
method: 'read',
args: [productId, ['event_ok']],
}).then(function (result) {
if (result && result[0].event_ok){
self._openEventConfigurator({
default_product_id: productId
},
dataPointID
);
}
});
}
},

/**
* This method is overridden to check if the product_id needs configuration or not:
*
* @override
* @param {OdooEvent} event
* Opens the event configurator in 'edit' mode.
*
* @private
*/
_onFieldChanged: function (event) {
var self = this;
_onEditProductConfiguration: function () {
if (this.recordData.event_ok) {
var defaultValues = {
default_product_id: this.recordData.product_id.data.id
};

if (this.recordData.event_id) {
defaultValues['default_event_id'] = this.recordData.event_id.data.id;
}

if (this.recordData.event_ticket_id) {
defaultValues['default_event_ticket_id'] = this.recordData.event_ticket_id.data.id;
}

this._super.apply(this, arguments);
if (!event.data.changes.product_id){
return;
this._openEventConfigurator(defaultValues, this.dataPointID);
} else {
this._super.apply(this);
}
},

var productId = event.data.changes.product_id.id;
self._checkForEvent(productId, event.data.dataPointID);
/**
* Opens the event configurator to allow configuring the SO line with events information.
*
* When the window is closed, configured values are used to trigger a 'field_changed'
* event to modify the current SO line.
*
* If the window is closed without providing the required values 'event_id' and
* 'event_ticket_id', the product_id field is cleaned.
*
* @param {Object} data various "default_" values
* @param {string} dataPointId
*
* @private
*/
_openEventConfigurator: function (data, dataPointId) {
var self = this;
this.do_action('event_sale.event_configurator_action', {
additional_context: data,
on_close: function (result) {
if (result && result !== 'special'){
self.trigger_up('field_changed', {
dataPointID: dataPointId,
changes: result.eventConfiguration
});
} else {
if (!self.recordData.event_id || !self.recordData.event_ticket_id) {
self.trigger_up('field_changed', {
dataPointID: dataPointId,
changes: {product_id: {operation: 'DELETE_ALL'}}
});
}
}
}
});
}
});

FieldsRegistry.add('event_configurator', EventConfiguratorWidget);

return EventConfiguratorWidget;
return ProductConfiguratorWidget;

});

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -14,7 +14,7 @@ odoo.define('event.configurator.tests', function (require) {
'<create string="Add a section" context="{\'default_display_type\': \'line_section\'}"/>' +
'<create string="Add a note" context="{\'default_display_type\': \'line_note\'}"/>' +
'</control>' +
'<field name="product_id" widget="event_configurator" />' +
'<field name="product_id" widget="product_configurator" />' +
'</tree>' +
'</field>' +
'</sheet>' +
@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend" name="event_sale assets backend">
<xpath expr="link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/event_sale/static/src/scss/event_configurator_widget.scss"/>
</xpath>
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/event_sale/static/src/js/event_configurator_controller.js"></script>
<script type="text/javascript" src="/event_sale/static/src/js/event_configurator_view.js"></script>
<script type="text/javascript" src="/event_sale/static/src/js/event_configurator_widget_mixin.js"></script>
<script type="text/javascript" src="/event_sale/static/src/js/event_configurator_widget.js"></script>
<script type="text/javascript" src="/event_sale/static/src/js/event_configurator_test_ui.js"></script>
</xpath>
@@ -31,7 +31,6 @@
<field name="event_ok" invisible="1"/>
</xpath>
<xpath expr="//field[@name='order_line']//tree//field[@name='product_id']" position="attributes">
<attribute name="widget">event_configurator</attribute>
<attribute name="options">{'no_open': True}</attribute>
</xpath>
<xpath expr="//field[@name='order_line']//tree//field[@name='product_id']" position="after">

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 99188b5

Please sign in to comment.
You can’t perform that action at this time.