summaryrefslogtreecommitdiff
path: root/addons/account/static/src/js/section_and_note_fields_backend.js
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2018-09-27 09:42:17 +0200
committerAurélien Warnon <awa@odoo.com>2018-10-01 13:28:41 +0200
commit27a739385249cff8c8779cb0d7be140e0b89226a (patch)
tree907f082a99fa25a21d6c62cbdd6287df29f0bc96 /addons/account/static/src/js/section_and_note_fields_backend.js
parent48b596d5332df4ebd2900fad46242aa201bc8bac (diff)
[IMP] product,(website_)sale: Product configurator default_get cleanup
Targets commit d3530eb07e24278117ab396ecb86a59deecc312d Purpose ======= [Follow up AL review] Removed the default_get override in the sale_order_line model. - The default values to create records are now specified by pefixing them with "default_" in the JS. That will use the built-in framework method, which is more simple/clean. - The "list_editable_renderer.js" file for the product configurator was removed and its content is now merged within the SectionAndNoteListRenderer. Updated fields: - [sale_order_line in sale/sale.py] "product_no_variant_attribute_values" to "product_no_variant_attribute_value_ids"
Diffstat (limited to 'addons/account/static/src/js/section_and_note_fields_backend.js')
-rw-r--r--addons/account/static/src/js/section_and_note_fields_backend.js102
1 files changed, 102 insertions, 0 deletions
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 bd93de20dc2..bd3cb3e563a 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
@@ -3,7 +3,12 @@ odoo.define('account.section_and_note_backend', function (require) {
// The goal of this file is to contain JS hacks related to allowing
// section and note on sale order and invoice.
+// [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');
@@ -67,6 +72,103 @@ var SectionAndNoteListRenderer = ListRenderer.extend({
this.$el.find('> table').addClass('o_section_and_note_list_view');
return def;
},
+ /**
+ * 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;
+
+ 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'
+ }, {
+ 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 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;
+ }
});
// We create a custom widget because this is the cleanest way to do it: