I'm trying to create user group that allow the user which has this group to update price of products in pricelist , and prevent others users whic doesn't have this group .
but when the user which doesn't has the user group update the price the error occurs instead of showing message "You don't have permission to edit price list items."
This is the code of user group:
<record id="group_price_list_editor" model="res.groups">
<field name="name">Price List Editor</field>
<field name="category_id" ref="base.module_category_sales_management"/>
</record>
This the code of python:
from odoo import api, fields, models, _
class ProductPrice(models.Model):
_inherit = 'product.pricelist.item'
@api.model
def create(self, vals):
if self.env.user.has_group('branch.group_price_list_editor'):
return super(ProductPrice, self).create(vals)
else:
raise Warning("You don't have permission to create price list items.")
def write(self, vals):
if self.env.user.has_group('branch.group_price_list_editor'):
return super(ProductPrice, self).write(vals)
else:
raise Warning("You don't have permission to edit price list items.")
This is the error appear:
Traceback (most recent call last): File "/home/odoo/src/user/branch/models/inherited_product.py", line 21, in write raise Warning("You don't have permission to edit price list items.") Warning: You don't have permission to edit price list items. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/odoo/src/odoo/odoo/http.py", line 1583, in _serve_db return service_model.retrying(self._serve_ir_http, self.env) File "/home/odoo/src/odoo/odoo/service/model.py", line 134, in retrying result = func() File "/home/odoo/src/odoo/odoo/http.py", line 1610, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) File "/home/odoo/src/odoo/odoo/http.py", line 1807, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch result = endpoint(**request.params) File "/home/odoo/src/odoo/odoo/http.py", line 696, in route_wrapper result = endpoint(self, *args, **params_ok) File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 42, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/odoo/src/odoo/odoo/api.py", line 461, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/home/odoo/src/odoo/odoo/api.py", line 448, in _call_kw_multi result = method(recs, *args, **kwargs) File "/home/odoo/src/odoo/odoo/models.py", line 3737, in write field.write(self, value) File "/home/odoo/src/odoo/odoo/fields.py", line 4215, in write return self.write_batch([(records, value)]) File "/home/odoo/src/odoo/odoo/fields.py", line 4236, in write_batch return self.write_real(records_commands_list, create) File "/home/odoo/src/odoo/odoo/fields.py", line 4394, in write_real comodel.browse(command[1]).write(command[2]) File "/home/odoo/src/user/branch/models/inherited_product.py", line 23, in write raise Warning("You don't have permission to edit price list items.") Warning: You don't have permission to edit price list items. The above server error caused the following client error: null