diff options
| author | Pierre Masereel <pim@odoo.com> | 2019-08-26 07:31:25 +0000 |
|---|---|---|
| committer | Pierre Masereel <pim@odoo.com> | 2019-08-27 09:31:31 +0000 |
| commit | 8fbbf1c696a0ef49d66d278eaed84c6ddbcb77b4 (patch) | |
| tree | 9082fa82d9eababc5463680a3e0bc1fc28b4550a | |
| parent | b8f7b472a62924ddc65f9a19b73c04484a76cf5c (diff) | |
[FIX] point_of_sale: vailable categories in POS
When you are selecting the some available categories of products for a
point of sale config, it won't let you select a start categories
anymore. This is caused by changes made on onchange in rev:f44571f550dfa34ddb1a62bbe03e78a4dadf8eda
that makes the records of One2many with new_ids instead of classical
ids.
The other problem is that if you return a in an ocnchange, the domain
does not apply when you are starting to edit a record.
To fix the behavior, we are comparing the ids, instead of the recordst
makes the records of One2many with new_ids instead of classical ids.
We've also created a computed fields that contains the ids that can be
selected.
TASK-ID: 2057436
| -rw-r--r-- | addons/point_of_sale/models/pos_config.py | 15 | ||||
| -rw-r--r-- | addons/point_of_sale/views/pos_config_view.xml | 3 |
2 files changed, 12 insertions, 6 deletions
diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index e16a66e5c55..78dde92be34 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -137,6 +137,7 @@ class PosConfig(models.Model): help='The point of sale will display this product category by default. If no category is specified, all available products will be shown.') iface_available_categ_ids = fields.Many2many('pos.category', string='Available PoS Product Categories', help='The point of sale will only display products which are within one of the selected category trees. If no category is specified, all available products will be shown') + selectable_categ_ids = fields.Many2many('pos.category', compute='_compute_selectable_categories') iface_display_categ_images = fields.Boolean(string='Display Category Pictures', help="The product categories will be displayed with pictures.") restrict_price_control = fields.Boolean(string='Restrict Price Modifications to Managers', @@ -276,6 +277,14 @@ class PosConfig(models.Model): pos_config.pos_session_duration = 0 pos_config.current_user_id = False + @api.depends('iface_available_categ_ids') + def _compute_selectable_categories(self): + for config in self: + if config.iface_available_categ_ids: + config.selectable_categ_ids = config.iface_available_categ_ids + else: + config.selectable_categ_ids = self.env['pos.category'].search([]) + @api.constrains('cash_control') def _check_session_state(self): open_session = self.env['pos.session'].search([('config_id', '=', self.id), ('state', '!=', 'closed')]) @@ -372,12 +381,8 @@ class PosConfig(models.Model): res = {} if not self.limit_categories: self.iface_available_categ_ids = False - elif not len(self.iface_available_categ_ids): - res = {'domain': {'iface_start_categ_id': [('id', 'in', self.env['pos.category'].search([]).ids)]}} - elif self.iface_start_categ_id not in self.iface_available_categ_ids: + if self.iface_available_categ_ids and self.iface_start_categ_id.id not in self.iface_available_categ_ids.ids: self.iface_start_categ_id = False - if self.iface_available_categ_ids: - res = {'domain': {'iface_start_categ_id': [('id', 'in', self.iface_available_categ_ids.ids)]}} return res @api.onchange('is_header_or_footer') diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml index 824a3397904..a3f209147b4 100644 --- a/addons/point_of_sale/views/pos_config_view.xml +++ b/addons/point_of_sale/views/pos_config_view.xml @@ -32,6 +32,7 @@ <widget name="web_ribbon" text="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/> <field name="active" invisible="1"/> <field name="currency_id" invisible="1"/> + <field name="selectable_categ_ids" invisible="1"/> <field name="is_installed_account_accountant" invisible="1"/> <field name="company_has_template" invisible="1"/> <div class="oe_title" id="title"> @@ -127,7 +128,7 @@ Start selling from a default product category </div> <div class="content-group mt16" attrs="{'invisible': [('start_category', '=', False)]}"> - <field name="iface_start_categ_id"/> + <field name="iface_start_categ_id" domain="[('id','in',selectable_categ_ids)]"/> </div> </div> </div> |
