Hi all,
I have a problem trying to override a fields.related. It's originally defined in product module, product_supplierinfo class:
_columns = {
...
'product_uom': fields.related('product_id', 'uom_po_id', type='many2one', relation='product.uom', string="Supplier Unit of Measure", readonly="1", help="This comes from the product form."),
...
}
I create a module, that depends on product, to put a many2one instead:
class product_supplierinfo(Model):
_inherit = 'product.supplierinfo'
_columns = {
'product_uom': fields.many2one('product.uom', "Supplier Unit of Measure", required=True, help="This comes from the product form."),
}
I add a function to populate the field and call it at installation
def _init_seller_uom(self, cr, uid, ids=None, context=None):
psi_ids = self.search(cr, SUPERUSER_ID, [], context=context)
for psi in self.browse(cr, SUPERUSER_ID, psi_ids, context=context):
uom_id = psi.product_id.uom_po_id.id
self.write(cr, SUPERUSER_ID, psi.id, {'product_uom': uom_id}, context=context)
return psi_ids
At this point, my column is correctly set and I can modify the values as I'd like. Perfect!
Now, the problem comes when I restart my server with --update=all. It seems the system first parses the original class in product module, sees that the field is a not-stored related field, and thus drops the column. I can indeed see that this query is executed:
ALTER TABLE "product_supplierinfo" DROP COLUMN "product_uom" CASCADE
Later in the update, it parses my module and execute this query:
ALTER TABLE "product_supplierinfo" ADD COLUMN "product_uom" int4
At the end of the update, my column is still updatable, but all values are lost!
Is there a solution? Thanks.