Odoo Help

Welcome!

This community 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.

0

Replace check method by inheritance

By
Susi
on 7/27/16, 3:40 AM 231 views

in the object  hr.analytic.timesheet there is the _check method 

def _check(self, cr, uid, ids):
        for att in self.browse(cr, uid, ids):
            if att.sheet_id and att.sheet_id.state not in ('draft', 'new'):
                raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet.'))
        return True

and method _check_sheet_state

def _check_sheet_state(self, cr, uid, ids, context=None):

        if context is None:

            context = {}

        for timesheet_line in self.browse(cr, uid, ids, context=context):

            if timesheet_line.sheet_id and timesheet_line.sheet_id.state not in ('draft', 'new'):

                return False

        return True

_constraints = [

(_check_sheet_state, 'You cannot modify an entry in a Confirmed/Done timesheet !', ['state']),


i've create a new module that inherits the hr.analytic.timesheet object and I redefine the _check and _check_sheet_state method by :

def _check(self, cr, uid, ids):

        for att in self.browse(cr, uid, ids):

            if att.sheet_id and att.sheet_id.state not in ('draft', 'new','confirm'):

                raise osv.except_osv(_('Error!'), _('You cannot modify an entry in a confirmed timesheet.'))

        return True

and method _check_sheet_state

def _check_sheet_state(self, cr, uid, ids, context=None):

        if context is None:

            context = {}

        for timesheet_line in self.browse(cr, uid, ids, context=context):

            if timesheet_line.sheet_id and timesheet_line.sheet_id.state not in ('draft', 'new','confirm'):

                return False

        return True

_constraints = [

(_check_sheet_state, 'You cannot modify an entry in a Confirmed/Done timesheet !', ['state']),


if you see i just add value state 'confirm' in method, for when the state confirm the constraint is not showing.


i want use method that i have made but my method doesnt work.


anyone can help me how to code this? Thanks for your Help

0
kirubanidhi
On 7/27/16, 7:11 AM

hai,

Try to Change browse method to read method, for example change from

 self.browse(cr, uid, ids, context=context) to

self.read(cr, uid, ids, ['state'], context=context)

Your Answer

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/27/16, 3:40 AM
Seen: 231 times
Last updated: 7/27/16, 7:11 AM