c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #03460
[Bug 584846] Re: inherits doesn't allow overwriting fields in child class
Hello Omar,
Would you mind trying with the latest trunk, and if your use case still
does not work, could you provide an actual example of the inheriting
code you are trying to use? (not just a description)
It would also be interesting to know why you need to do this style of
inheritance, instead of using simpler _inherit (without s) to implement
what you want. In this case the chaining of _inherits seems to be
overkill and makes the database structure quite complicated, doesn't it?
Thanks!
** Summary changed:
- [5.0] inherits don't allow overwrite fields in child class
+ inherits doesn't allow overwriting fields in child class
** Changed in: openobject-server
Importance: Undecided => Low
** Changed in: openobject-server
Status: New => Incomplete
--
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: Incomplete
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.