如何在odoo v8上继承_constraints?

时间:2022-04-15 21:38:57

As for _sql_constraints work :

至于_sql_constraints工作:

def _auto_init(self, cr, context=None):
    self._sql_constraints = [
            ('planned_field_uniq', 'unique(field1,field2,)', 'Already exist'),
    ]
    super(object_name, self)._auto_init(cr, context)

couldn't figure it out for _constraints I tried also the

无法弄明白_constraints我也试过了

@api.constraints('field1','field2')
def _check_duplicate_(self):
    _logger.info('MY CONSTRAINT IS CALLED')
    import pdb;pdb.set_trace()

1 个解决方案

#1


2  

In python you can monkey patch any thing you can try thid technique hope it work

在python中你可以修补你可以尝试的任何东西,希望它的工作

Import the class that you want to alter it's constraints attribute.

导入要更改其约束属性的类。

       from openerp.addons.addon_name....class_name

       class_name._constraints  = new_value

This code is executed before Odoo builds the global Model class from the list of classes. This way when odoo start checking constraints this value will be changed because that value is always retreived from that class.

在Odoo从类列表构建全局Model类之前执行此代码。这样,当odoo开始检查约束时,该值将被更改,因为该值总是从该类中重新获得。

Because it's not sql_constrains this should work, you are changing it in runtime.

因为它不是sql_constrains,所以你应该在运行时更改它。

#1


2  

In python you can monkey patch any thing you can try thid technique hope it work

在python中你可以修补你可以尝试的任何东西,希望它的工作

Import the class that you want to alter it's constraints attribute.

导入要更改其约束属性的类。

       from openerp.addons.addon_name....class_name

       class_name._constraints  = new_value

This code is executed before Odoo builds the global Model class from the list of classes. This way when odoo start checking constraints this value will be changed because that value is always retreived from that class.

在Odoo从类列表构建全局Model类之前执行此代码。这样,当odoo开始检查约束时,该值将被更改,因为该值总是从该类中重新获得。

Because it's not sql_constrains this should work, you are changing it in runtime.

因为它不是sql_constrains,所以你应该在运行时更改它。