[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
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user