i have inherited the model' product.template' and added a new page UOM . i created a one2many field of 'product.uom' and added all its field to the page UOM that i have created, so that i could create multiple unit of measure for a single product.
i have also created a function that creates the category_id same as that of product name.
from odoo import models, fields,api
class ProductTemplate(models.Model):
_inherit = "product.template"
product_uom_ids= fields.One2many('product.uom' ,'product_template_id', string='unit of measure')
@api.model
def create(self, vals):
new=self.env['product.uom.categ'].create({'name': vals['name']})
if vals['name']:
for record in vals['product_uom_ids']:
record[2]['category_id']=new.id
return super(ProductTemplate, self).create(vals)
@api.multi
def write(self,values):
if values:
print(values)
print(values['product_uom_ids'][0][1])
list=self.env['product.uom'].search([('id','=',values['product_uom_ids'][0][1])],limit=1)
print(list)
for item in values['product_uom_ids']:
print(list.category_id.name)
for record in values['product_uom_ids']:
if record[1]==False:
record[2]['category_id']=list.category_id.id
return super(ProductTemplate, self).write(values)
class ProductTemplateid(models.Model):
_inherit = "product.uom"
product_template_id=fields.Many2one('product.template')
But when i edit the name of the product and tried to save i'am getting an error.
Traceback (most recent call last): File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 642, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 684, in dispatch result = self._call_function(**self.params) File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 334, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/zinfog/Documents/wrk/odoo/odoo/service/model.py", line 101, in wrapper return f(dbname, *args, **kwargs) File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 327, in checked_call result = self.endpoint(*a, **kw) File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 942, in __call__ return self.method(*args, **kw) File "/home/zinfog/Documents/wrk/odoo/odoo/http.py", line 507, in response_wrap response = f(*args, **kw) File "/home/zinfog/Documents/wrk/odoo/addons/web/controllers/main.py", line 892, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/zinfog/Documents/wrk/odoo/addons/web/controllers/main.py", line 884, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/zinfog/Documents/wrk/odoo/odoo/api.py", line 689, in call_kw return call_kw_multi(method, model, args, kwargs) File "/home/zinfog/Documents/wrk/odoo/odoo/api.py", line 680, in call_kw_multi result = method(recs, *args, **kwargs) File "/home/zinfog/Documents/wrk/odoo/myaddons/product_category/model/category.py", line 23, in write print(values['product_uom_ids'][0][1])
What are you getting when printing values?
print(values)