soft coded constraints

Registered by Ferdinand

currently constraints are (more or less) hard coded in the modules py.file

we have developed a (quite simple) module which allows to "soft code" constraints on a per object basis without touching the module itself, given a constraint triggers the checks defined here.

The idea is to integrate this module in base and alter the server code to automatically execute the checks defined for the table as if the constraint would have been placed in the _constraint section.

additionally a button exists to execute the checks "manually"

this is very useful to implement special company requirements

class ir_constraint_extension (osv.osv):
    _name = "ir.constraint.extension"

    _columns = \
        { 'condition' : fields.char ('Condition', required=True, size=256)
        , 'filter' : fields.char ('Filter', size=256)
        , 'name' : fields.char ('Error Message', required=True, size=128)
        , 'object' : fields.char ('Object', required=True, size=32)
        , 'table' : fields.char ('Table', required=True, size=32)
        }

    def test_obj (self, cr, uid, rule, obj) : pass # let the heirs do the work

    def test (self, cr, uid, rule) :
        result = []
        c_obj = self.pool.get (rule.table)
        c_ids = c_obj.search (cr, uid, [])
        for obj in c_obj.browse (cr, uid, c_ids) :
            result.extend(self.test_obj(cr, uid, rule, obj))
        return result
    # end def test

    def button_test (self, cr, uid, ids, id) :
        result = []
        for c in self.browse (cr, uid, ids) :
            result.extend(self.test(cr, uid, c))
        if result :
            raise osv.except_osv (_('Rule Error !'), _('\n'.join (result)))
        else :
            raise osv.except_osv (_('Rule successfully tested !'), _('No errors found.'))
    # end def button_test

ir_constraint_extension ()

+ some more code for more sophisticated stuff.

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.