Inheriting old methods in version 8

When I write a custom module that overrides the current methods, does it need to be written in the same api version?

For example, a module product is written in v7, when I override product methods, does it need to be in v7 or can I do it in v8?

+3


source to share


2 answers


You only need to update the odoo engine code, which itself manages the update / downgrade engine as needed.

from openerp import models, fields, api, _

class product_product(models.Model):
    _inherit= "product.product"
    _description = "Product"

    @api.model
    def create(self, vals):
        ### Add your code here
        return super(product_product, self).create(vals);

    @api.multi
    def write(self, vals):
        ### Add your code here
        return super(product_product, self).write(vals);

      



Likewise, you can override any legacy methods except exchange methods. in onchange methods, you need to provide the definition in the old template.

+1


source


yes, you can override v8 method in v7

from openerp import models, fields, api, _

class product_product(models.Model):
    _inherit= "product.product"
    _description = "Product"

@api.v7
def _product_code(self, cr, uid, ids, name, arg, context=None):
    res = {}
    if context is None:
        context = {}
    for p in self.browse(cr, uid, ids, context=context):
        res[p.id] = self._get_partner_code_name(cr, uid, [], p, context.get('partner_id', None), context=context)['code']
    return res 

      



I am just overriding v7 _product_code method

in my new API product class for Odoo 8.0.

Hope my answer can help you :)

+2


source







All Articles