-1

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.
enter image description here

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

beriliox
  • 267
  • 6
  • 18
  • Possible duplicate of [Python: Attribute Error - 'NoneType' object has no attribute 'something'](http://stackoverflow.com/questions/8949252/python-attribute-error-nonetype-object-has-no-attribute-something) – tripleee Mar 04 '16 at 11:28
  • doesn't seems a duplicate to me: we don't know which problem the other post was referring to – Alessandro Ruffolo Mar 04 '16 at 11:33

1 Answers1

2

you don't need the for rec in self loop because you are into create. you don't have any access to the object field through self, which is empty at the moment. You need to use only vals. you need to change the method decorators:

@api.model
@api.returns('self', lambda value:value.id)
def create(self, vals):

I really think you should have a read at Odoo basics, this is not the first problem you have that you could avoided reading them deeply... Also, have a look at account_invoice.py into account module which shows plenty of v8 api

Juriy
  • 565
  • 1
  • 5
  • 17
Alessandro Ruffolo
  • 1,575
  • 1
  • 16
  • 34