Odoo Help

7
0
Avatar

Baiju KS

--Baiju KS--
3347
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 10/6/16, 7:06 AM

Hi,


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:-

_constraints
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

_sql_constraints
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.

0
Hengky
On 10/6/16, 5:17 AM

Can you explain more detail what do you want to achieved (you problem) ?

i think you can do it  without JS

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 10/6/16, 3:17 AM
Seen: 1225 times
Last updated: 3/4/17, 5:19 AM