Open cundi opened 8 years ago
原文链接:http://odedrabhavesh.blogspot.in/2014/12/how-to-create-constraints-in-openerp.html
This will help you to create a constraints in OpenERP.
_constraint is a pre-define field in OpenERP. It is used for adding a constraint on the object.
_constraint
It takes list of tuple as its argument. The tuple inside the list contains three parameter.
_constraint will fire if the condition returns False on creation and updation of the record and display the message.
Here is an example of integer data-type. It's fire a constraint if length is not positive.
Here is .py side code:
from openerp.osv import fields, osv class res_partner(osv.Model): _inherit = 'res.partner' _columns = { 'length': fields.integer('Length', size=64), } def _check_number(self, cr, uid, ids, context=None): for partner in self.browse(cr, uid, ids, context=context): if partner.length < 0: return False return True _constraints = [ (_check_length, 'Length must be Positive.', ['length']) ]
Here is .xml side code:
<?xml version="1.0"?> <openerp> <data> <!-- res partner form view--> <record id="view_res_partner_extended_form" model="ir.ui.view"> <field name="name">res.partner.extended.form.view</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <field name="email" position="after"> <field name="length"/> </field> </field> </record> </data> </openerp>
I hope you like this article. Share your views to improve content. Happy Learning !!!
原文链接:http://odedrabhavesh.blogspot.in/2014/12/how-to-create-constraints-in-openerp.html
How to create constraints in OpenERP?
This will help you to create a constraints in OpenERP.
_constraint
is a pre-define field in OpenERP. It is used for adding a constraint on the object.It takes list of tuple as its argument. The tuple inside the list contains three parameter.
_constraint
will fire if the condition returns False on creation and updation of the record and display the message.Here is an example of integer data-type. It's fire a constraint if length is not positive.
Here is .py side code:
Here is .xml side code:
I hope you like this article. Share your views to improve content. Happy Learning !!!