Hi everyone,
I'm trying to domain product_id in sale.order.line based on pricelist in sale.order form.
I'm using a dynamic domain for it but it's not working. Here is my code in sale.order:
@api.onchange('pricelist_id')
def onchange_pricelist_id(self):
product_id = self.order_line.product_id
product_ids = []
if self.pricelist_id:
for rec in self.pricelist_id.item_ids:
product_ids.append(rec.id)
return {'domain': {'product_id': [('id', 'in', product_ids)]}}
I'm also trying to use name_get() in product.product:
def name_get(self):
if self._context.get('temp'):
return super(ProductProduct, self).name_get()
product_list = []
pricelist = self.env['product.pricelist'].browse(self._context.get('pricelist'))
if pricelist:
for rec in pricelist.item_ids:
if rec.applied_on == '0_product_variant':
product_list.append(rec.product_id.id)
if product_list:
self = self.browse(product_list)
result = super(ProductProduct, self).name_get()
return result
but it throws :
Error:
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo13/odoo/odoo/loglevels.py", line 92, in ustr
return text_type(value)
File "/opt/odoo13/odoo/odoo/tools/func.py", line 150, in __str__
def __str__(self): return str(self._value)
File "/opt/odoo13/odoo/odoo/tools/func.py", line 137, in _value
value = self._func(*self._args, **self._kwargs)
File "/opt/odoo13/odoo/odoo/tools/func.py", line 167, in __getitem__
def __getitem__(self, key): return self._value[key]
KeyError: 36
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo13/odoo/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo13/odoo/odoo/http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/opt/odoo13/odoo/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/opt/odoo13/odoo/odoo/http.py", line 678, in dispatch
return self._json_response(result)
File "/opt/odoo13/odoo/odoo/http.py", line 607, in _json_response
body = json.dumps(response, default=date_utils.json_default)
File "/usr/lib/python3.7/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/opt/odoo13/odoo/odoo/tools/date_utils.py", line 211, in json_default
return ustr(obj)
File "/opt/odoo13/odoo/odoo/loglevels.py", line 94, in ustr
raise UnicodeError('unable to convert %r' % (value,))
UnicodeError: unable to convert <odoo.tools.func.lazy object at 0x7fbec8aa6900>
Is anyone have solutions for this? Please help me.
Best regards