Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
i would like to create a module which depends on sale. I created a field
If you want to check something at the time of database write you can inherit write method :-
def write(self, cr, uid, ids, vals, context=None):
# --> your checking code here
return super(class, self).write(cr, uid, ids, vals, context=context)
write method get invoked every time we edit and save.
Or if you want to set a limitation or restriction for a field you can use _constraints or _sql_constraints:-
Using _constraints you can define Python constraints: here is syntax and example:-
list of (constraint_function, message, fields)
def _check_company_id(self, cr, uid, ids, context=None):
for statement in self.browse(cr, uid, ids, context=context):
if statement.company_id.id != statement.period_id.company_id.id:
return False return True
_constraints = [ (_check_company_id, 'The journal and period chosen have to belong to the same company.', ['journal_id','period_id']), ]
using _sql_constraints, you can define SQL constraints to execute when generating the backing table. here is syntax and example
list of (name, sql_definition, message)
_sql_constraints = [
('number_uniq', 'unique(number, company_id, journal_id, type)',
'Invoice Number must be unique per Company!'),
Hope this helps.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 10/6/16, 3:17 AM|
|Seen: 264 times|
|Last updated: 11/7/16, 2:07 AM|