This question has been flagged
2002 Views

I created a small module

 

class ProducctCottonPrice(models.Model):
_inherit = 'product.template'

cotton_qty = fields.Float(string='PCS in Cotton', digits=0, default=1.0)
@api.one
@api.onchange('cotton_qty')
def _compute_po_id(self):
for p in self:
if p.cotton_qty <= 1.0:
p.uom_po_id = p.uom_id
elif p.cotton_qty > 1:
p.uom_po_id = self.env['product.uom'].search([('factor_inv', '=', p.cotton_qty)] limit=1)

elif p.cotton_qty > 1.0:
p.uom_po_id = self.env['product.uom'].create(
{
'name': Cotton + ' ' + p.cotton_qty,
'category_id': p.uom_id,
'uom_type': bigger,
'factor_inv': p.cotton_qty,
'active': True,
'rounding': 1 / p.cotton_qty,
}
)
but if I have a product.uom_id.factor_inv = p.cotton_qty
It still do not pick the value and through me an error.
attributeerror: 'list' object has no attribute 'get'
Avatar
Discard