From ab0a207a591e11c1c8c47cd7fdfd2037f73bec03 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 26 Aug 2019 13:11:23 +0000 Subject: [PATCH] [FIX] point_of_sale: force load discount product When you set up a discount product on your pos config and also some available categories, it is possible that the discount product is not loaded in the point of sale, which lead to an error. Now we are forcing the loading of the discount product to allow using it even if it is not in the allowed categories, as we don't want to create a discount product for each category if we want to use both features. TASK-ID: 2057436 --- addons/pos_discount/static/src/js/discount.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/addons/pos_discount/static/src/js/discount.js b/addons/pos_discount/static/src/js/discount.js index fc41e55bc05..991e738b3e1 100644 --- a/addons/pos_discount/static/src/js/discount.js +++ b/addons/pos_discount/static/src/js/discount.js @@ -3,9 +3,27 @@ odoo.define('pos_discount.pos_discount', function (require) { var core = require('web.core'); var screens = require('point_of_sale.screens'); +var models = require('point_of_sale.models'); var _t = core._t; +var existing_models = models.PosModel.prototype.models; +var product_index = _.findIndex(existing_models, function (model) { + return model.model === "product.product"; +}); +var product_model = existing_models[product_index]; + + +models.load_models([{ + model: product_model.model, + fields: product_model.fields, + order: product_model.order, + domain: function(self) {return [['id', '=', self.config.discount_product_id[0]]];}, + context: product_model.context, + loaded: product_model.loaded, +}]); + + var DiscountButton = screens.ActionButtonWidget.extend({ template: 'DiscountButton', button_click: function(){