[5.0] cannot inherit a _constraint

Bug #568431 reported by Christophe CHAUVET
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Invalid
High
Stephane Wirtel (OpenERP)

Bug Description

OpenObject: 5.0
Server revno: 2038
Addons revno: 2711
Client revno: 1069

I just wants to inherit a constraint (_constraint) but the code below doesn't execute.
I think the bug 330427 is to be the same as mine.

--------------8<---------------8<-------------
from osv import osv
from osv import fields

class product_pricelist_version(osv.osv):
    _inherit = 'product.pricelist.version'

    def _check_date(self, cursor, user, ids):
        print 'Inherit OK'
        return True

product_pricelist_version()
--------------8<---------------8<-------------

Distribution: Ubuntu
Version: 9.10 (karmic)
Python 2.6.4

Locale:
  LANG=fr_FR.UTF-8

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

I'm sorry, but it's not a bug. In the definition of a constraint in OpenERP, you give the reference to the method and not a name.

def _check_date(self, cr, uid, ids, context=None):
    pass

_constraints = [
   (_check_date, "message", []),
]

In this case, _check_date is a reference to the _check_date method.

You can use an other way to solve this problem

1. define your method;
In the parent object, you can define a method

def _nested_check_date(self, cr, uid, ids, context=None):
    return True

def _check_date(self, cr, uid, ids, context=None):
    return self._nested_check_date(cr, uid, ids, context=context)

2. in the other object:
you can redefined the _nested_check_date method.

Revision history for this message
Stephane Wirtel (OpenERP) (stephane-openerp) wrote :

Now, we can propose an other approach to define a constraint for the next release.

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Stephane

Ok it's not a bug, but how can i made in my module, because in the product module there is no implementation as you define in comment #1

Regards,

Changed in openobject-server:
status: Invalid → Won't Fix
Changed in openobject-server:
status: Won't Fix → Confirmed
assignee: nobody → Stephane (Open ERP) (stephane-openerp)
Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Stephane

I have fix this issue in addons with your suggestion

Regards,

Changed in openobject-server:
milestone: 5.0.10 → 5.0.12
status: Confirmed → Invalid
Changed in openobject-server:
status: Invalid → Confirmed
Changed in openobject-server:
milestone: 5.0.12 → 6.1
Changed in openobject-server:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.