[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 <pimodoo@users.noreply.github.com>
This commit is contained in:
Joseph Caburnay
2019-10-28 14:16:15 +00:00
committed by fw-bot
parent 8e3be15025
commit 4d91d008c2
3 changed files with 27 additions and 5 deletions
+18 -3
View File
@@ -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"
+7 -1
View File
@@ -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]});
@@ -35,6 +35,7 @@
<field name="selectable_categ_ids" invisible="1"/>
<field name="is_installed_account_accountant" invisible="1"/>
<field name="company_has_template" invisible="1"/>
<field name="allowed_pricelist_ids" invisible="1"/>
<div class="oe_title" id="title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
@@ -254,7 +255,7 @@
<div class="o_setting_right_pane">
<span class="o_form_label">Default Pricelist</span>
<div class="content-group mt16">
<field name="pricelist_id" domain="[('id', 'in', available_pricelist_ids)]" options="{'no_create': True}"/>
<field name="pricelist_id" domain="[('id', 'in', allowed_pricelist_ids)]" options="{'no_create': True}"/>
</div>
<div>
<button name="%(product.product_pricelist_action2)d" icon="fa-arrow-right" type="action" string="Pricelists" class="btn-link"/>