summaryrefslogtreecommitdiff
path: root/addons/sale_product_matrix/static/src
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_product_matrix/static/src
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sale_product_matrix/static/src')
-rw-r--r--addons/sale_product_matrix/static/src/js/product_matrix_configurator.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/addons/sale_product_matrix/static/src/js/product_matrix_configurator.js b/addons/sale_product_matrix/static/src/js/product_matrix_configurator.js
new file mode 100644
index 00000000..7ea00210
--- /dev/null
+++ b/addons/sale_product_matrix/static/src/js/product_matrix_configurator.js
@@ -0,0 +1,97 @@
+odoo.define('sale_product_matrix.product_configurator', function (require) {
+var ProductConfiguratorWidget = require('sale_product_configurator.product_configurator');
+
+/**
+ * Extension of the ProductConfiguratorWidget to support product configuration
+ * as variant batches to add to the SO..
+ * It opens when a configurable product_template is set
+ * (multiple variants, or custom attributes)
+ * and its configuration mode is matrix.
+ *
+ */
+ProductConfiguratorWidget.include({
+
+ /**
+ * @override
+ */
+ _openConfigurator: function (result, productTemplateId, dataPointId) {
+ var self = this;
+ var mode = result.mode;
+ this._super.apply(this, arguments).then(function (configuratorOpened) {
+ if (!configuratorOpened && mode === 'matrix') {
+ self._openGridConfigurator(productTemplateId, dataPointId);
+ return Promise.resolve(true);
+ }
+ return Promise.resolve(configuratorOpened);
+ });
+ },
+
+ _openGridConfigurator: function (productTemplateId, dataPointId, edit) {
+ var attribs = edit ? this._getPTAVS() : [];
+ this.trigger_up('open_matrix', {
+ product_template_id: productTemplateId,
+ model: 'sale.order',
+ dataPointId: dataPointId,
+ edit: edit,
+ editedCellAttributes: attribs,
+ });
+ },
+
+ _onEditProductConfiguration: function () {
+ if (!this.recordData.is_configurable_product) {
+ // if line should be edited by another configurator
+ // or simply inline.
+ this._super.apply(this, arguments);
+ return;
+ }
+ var self = this;
+ var productTemplateId = this.recordData.product_template_id.data.id;
+ this._rpc({
+ model: 'product.template',
+ method: 'read',
+ args: [productTemplateId, ['product_add_mode']],
+ }).then(function (result) {
+ if (result && result[0].product_add_mode === 'matrix') {
+ self._openGridConfigurator(productTemplateId, self.dataPointID, true);
+ } else {
+ // Call super only if product_add_mode different than matrix
+ // to avoid product configurator opening (which is the default case).
+ self._openProductConfigurator({
+ configuratorMode: 'edit',
+ default_product_template_id: self.recordData.product_template_id.data.id,
+ default_pricelist_id: self._getPricelistId(),
+ default_product_template_attribute_value_ids: self._convertFromMany2Many(
+ self.recordData.product_template_attribute_value_ids
+ ),
+ default_product_no_variant_attribute_value_ids: self._convertFromMany2Many(
+ self.recordData.product_no_variant_attribute_value_ids
+ ),
+ default_product_custom_attribute_value_ids: self._convertFromOne2Many(
+ self.recordData.product_custom_attribute_value_ids
+ ),
+ default_quantity: self.recordData.product_uom_qty
+ },
+ self.dataPointID
+ );
+ }
+ });
+ },
+
+ /**
+ * Returns the list of attribute ids (product.template.attribute.value)
+ * from the current SOLine.
+ */
+ _getPTAVS: function () {
+ var PTAVSIDS = [];
+ _.each(this.recordData.product_no_variant_attribute_value_ids.res_ids, function (id) {
+ PTAVSIDS.push(id);
+ });
+ _.each(this.recordData.product_template_attribute_value_ids.res_ids, function (id) {
+ PTAVSIDS.push(id);
+ });
+ return PTAVSIDS.sort(function (a, b) {return a - b;});
+ }
+
+});
+
+});