I need to use the factor field of uom.uom class as a variable field depending upon the product that I choose, however when I tried to implement it in my purchase order class, it shows the following error:
"You cannot change the ratio of this unit of mesure as some products with this UoM have already been moved or are currently reserved."
My code for purchase.order is:
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
@api.depends('order_line')
@api.onchange('order_line')
def _set_factor(self):
_logger.info(self.product_id.category_id.name)
fact = self.env['uom.uom'].search([['name', '=', self.product_id.category_id.name]])
fact.factor=self.product_id.factor1