← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 584846] Re: inherits doesn't allow overwriting fields in child class

 

Reviewing patch I see that it is old, this patch only writes in right
place of the inheritance, but, it fails reading the new replaced values,
I reattach my final patch,  the patch that is in the customer.

** Patch added: "orm.diff"
   https://bugs.launchpad.net/openobject-server/+bug/584846/+attachment/1728818/+files/orm.diff

** Patch removed: "orm.diff"
   https://bugs.launchpad.net/openobject-server/+bug/584846/+attachment/1401946/+files/orm.diff

-- 
inherits doesn't allow overwriting fields in child class
https://bugs.launchpad.net/bugs/584846
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.

Status in OpenObject Server: Opinion

Bug description:
Hi,

I want to overwrite procure_method field of product.template to product.product because I use product_variant_multi module to create variants and my variants haven't got the same procure method then I see a bug, when I want to create new variants, the product.product create method in this case has got in vals: {'product_tmpl_id': 2, 'procure_method': 'make_to_stock'} for example. Then in the create method of orm it does: 

if self._inherits[v] not in vals:
    tocreate[v] = {}

Therefore in this case it doesn't set tocreate['product.template'] = {} because product_tmpl_id is defined in vals.

In next lines:

for v in vals.keys():
        if v in self._inherit_fields:
            (table, col, col_detail) = self._inherit_fields[v]
            tocreate[table][v] = vals[v]
            del vals[v]

It goes around vals keys, and it separates the field of product.template and the fields of product.product but product_tmpl_id is defined in vals then tocreate['product.template'] is not defined and it fails, showing an error because it receives in vals 'procucre_method' that it is in _inherit_fields and tries to set it in 'product.template'.

This behavior avoids inherit fields, if I overwrite a field in child class it must set this field not set this in parent class. I do a patch that allows inherit fields:

for v in vals.keys():
        if v in self._inherit_fields and v not in self._columns:
            (table, col, col_detail) = self._inherit_fields[v]
            tocreate[table][v] = vals[v]
            del vals[v]

This patch checks that the field isn't in _columns too, if the field in _columns it doesn't set it to parent class.
I include the diff file.