title: AttributeError: 'NoneType' object has no attribute 'id'
body: <p>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.<br>
  <a href="https://i.stack.imgur.com/D2MHB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D2MHB.png" alt="enter image description here"></a></p>
  
  <pre><code>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
  </code></pre>
  
  <p>But when I press the Save button, Odoo shows me the following error:
  <strong>AttributeError: 'NoneType' object has no attribute 'id'</strong></p>
  
  <p>Why is this happening? What can I do?
  Any help is appreciated. Thanks</p>