From 4d91d008c200c918bd693df5cdda92b8cbbca643 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 21 Oct 2019 09:13:52 +0000 Subject: [PATCH] [FIX] point_of_sale: pricelist_id in available_pricelist_ids When Pricelist is activated in the General Settings, pricelist_id field is now available in the form view even if the use_pricelist is False. This means that pricelist_id field should be independent from available_pricelist_ids when use_pricelist is False. The value of available_pricelist_ids becomes a restriction to pricelist_id when use_pricelist if True. closes odoo/odoo#39454 X-original-commit: 98b778de85668d87f2cd2dfc687c2b4c28474b0a Signed-off-by: pimodoo --- addons/point_of_sale/models/pos_config.py | 21 ++++++++++++++++--- addons/point_of_sale/static/src/js/models.js | 8 ++++++- .../point_of_sale/views/pos_config_view.xml | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 66b3c96ffa5..deb2ef81e57 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -171,6 +171,12 @@ class PosConfig(models.Model): help="The pricelist used if no customer is selected or if the customer has no Sale Pricelist configured.") available_pricelist_ids = fields.Many2many('product.pricelist', string='Available Pricelists', default=_default_pricelist, help="Make several pricelists available in the Point of Sale. You can also apply a pricelist to specific customers from their contact form (in Sales tab). To be valid, this pricelist must be listed here as an available pricelist. Otherwise the default pricelist will apply.") + allowed_pricelist_ids = fields.Many2many( + 'product.pricelist', + string='Allowed Pricelists', + compute='_compute_allowed_pricelist_ids', + help='This is a technical field used for the domain of pricelist_id.', + ) company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', string='Barcode Nomenclature', help='Defines what kind of barcodes are available and how they are assigned to products, customers and cashiers.', @@ -209,6 +215,14 @@ class PosConfig(models.Model): current_user_id = fields.Many2one('res.users', string='Current Session Responsible', compute='_compute_current_session_user') other_devices = fields.Boolean(string="Other Devices", help="Connect devices to your PoS without an IoT Box.") + @api.depends('use_pricelist', 'available_pricelist_ids') + def _compute_allowed_pricelist_ids(self): + for config in self: + if config.use_pricelist: + config.allowed_pricelist_ids = config.available_pricelist_ids.ids + else: + config.allowed_pricelist_ids = self.env['product.pricelist'].search([]).ids + @api.depends('company_id') def _compute_company_has_template(self): for config in self: @@ -308,10 +322,11 @@ class PosConfig(models.Model): if self.env['pos.payment.method'].search_count([('id', 'in', self.payment_method_ids.ids), ('company_id', '!=', self.company_id.id)]): raise ValidationError(_("The method payments and the point of sale must belong to the same company.")) - @api.constrains('pricelist_id', 'available_pricelist_ids', 'journal_id', 'invoice_journal_id', 'payment_method_ids') + @api.constrains('pricelist_id', 'use_pricelist', 'available_pricelist_ids', 'journal_id', 'invoice_journal_id', 'payment_method_ids') def _check_currencies(self): - if self.pricelist_id not in self.available_pricelist_ids: - raise ValidationError(_("The default pricelist must be included in the available pricelists.")) + for config in self: + if config.use_pricelist and config.pricelist_id not in config.available_pricelist_ids: + raise ValidationError(_("The default pricelist must be included in the available pricelists.")) if any(self.available_pricelist_ids.mapped(lambda pricelist: pricelist.currency_id != self.currency_id)): raise ValidationError(_("All available pricelists must be in the same currency as the company or" " as the Sales Journal set on this point of sale if you use" diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 38d08099050..5136a6352a2 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -325,7 +325,13 @@ exports.PosModel = Backbone.Model.extend({ },{ model: 'product.pricelist', fields: ['name', 'display_name', 'discount_policy'], - domain: function(self) { return [['id', 'in', self.config.available_pricelist_ids]]; }, + domain: function(self) { + if (self.config.use_pricelist) { + return [['id', 'in', self.config.available_pricelist_ids]]; + } else { + return [['id', '=', self.config.pricelist_id[0]]]; + } + }, loaded: function(self, pricelists){ _.map(pricelists, function (pricelist) { pricelist.items = []; }); self.default_pricelist = _.findWhere(pricelists, {id: self.config.pricelist_id[0]}); diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml index 6b23c2dbd2d..13a90f3893b 100644 --- a/addons/point_of_sale/views/pos_config_view.xml +++ b/addons/point_of_sale/views/pos_config_view.xml @@ -35,6 +35,7 @@ +