I have this function that should do is to save in a field ( ' niu ' ) a sequence when the form is saved. This form is in the sale.order.line model.
niu = fields.Char(string="NIU", readonly=True)
@api.model
def create(self, vals):
for rec in self:
if rec.product_id.product_tmpl_id.type == 'product' and not rec.niu:
if vals.get('niu') == ' ':
vals[u'niu'] = self.env['ir.sequence'].next_by_code('sale.order.line')
result = super(SaleOrder, self).create(vals)
return result
But when I press the Save button, Odoo shows me the following error: AttributeError: 'NoneType' object has no attribute 'id'
Why is this happening? What can I do? Any help is appreciated. Thanks