Hi Olivier,
 
Our customer needed it  with 5.0, in trunk version I think that it works but I 
didn't test it fully. Our customer manages many variants of products ex: red 
lamp, black lamp, etc. In my inheritance, I did:

class product_product(osv.osv):

    _inherit = "product.product"

    _columns = {
        'procure_method': fields.selection([('make_to_stock','Make to 
Stock'),('make_to_order','Make to Order')], 'Procure Method', required=True),
        'categ_id': fields.many2one('product.category','Category', 
required=True, change_default=True),
        'sale_ok': fields.boolean('Can be sold', help="Determine if the product 
can be visible in the list of product within a selection from a sale order 
line."),
        'purchase_ok': fields.boolean('Can be Purchased', help="Determine if 
the product is visible in the list of products within a selection from a 
purchase order line."),
        'name': fields.char('Name', size=128, required=True, translate=True, 
select=True)
    }

    _defaults = {
        'procure_method': lambda *a: 'make_to_stock'
    }

product_product()

Then, I had to override many fields of product.template because I want
to have them different for my variant. ex:

My lamp template = {
 'name': 'Lamp of Table',
 'categ_id': 'Lamps',
 'sale_ok': True,
 'purchase_ok': False,
 'procure_method': 'make_to_order' #Because I need do production with bom from 
selected mrp.properties in the sale.
} 

My lamp variant = {
 'name': 'Red Lamp of Table',
 'categ_id': 'Variants',
 'sale_ok': False, #You can't sell this variant you should be sell 'Lamp of 
Table' with red property, this, in production will do the red lamp
 'purchase_ok': False,
 'procure_method': 'make_to_stock' #because this lamp isn't produced by order, 
without, it gets from stock.
}

My patch add this possibility and it doesn't interfere in the others
inheritances or normal fields in _columns. I think that it is good
improvement.

Thanks, I hope you understand my example.

** Changed in: openobject-server
       Status: Incomplete => Opinion

-- 
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.



_______________________________________________
Mailing list: https://launchpad.net/~c2c-oerpscenario
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~c2c-oerpscenario
More help   : https://help.launchpad.net/ListHelp

Reply via email to