Community mailing list archives

community@mail.odoo.com

Re: Modify ORM create method behavior using inheritance [Old API]

by
Yassine TEIMI
- 11/24/2015 17:42:21
Yes, the former user and the employee points to the same partner, that was the issue, It works fine now. Thanks Houssine.

2015-11-24 22:37 GMT+00:00 Houssine BAKKALI <houssine.bakkali@gmail.com>:
just use self.create(cr, uid, vals, context)

maybe that the former user and the employee point to the same partner

2015-11-24 23:22 GMT+01:00 Yassine Teimi <yteimi01@gmail.com>:
I replaced the call by : osv.Model.create(self, cr, uid, vals, context=context) and it worked now the override is clean. 

I still have a problem with partner_id field it doesn't get the correct value (the same as old one) I'm looking for why, because the main purpose of this override is to change the partner_id received value.

2015-11-24 21:56 GMT+00:00 Yassine Teimi <yteimi01@gmail.com>:
Salam Houssine, 

How to use inherits to override craete method, if I use it it's a delegation inheritance, it doesn't allow method inheritance I guess. correct me if I'm wrong.

How can I replace the call to : super(HrEvaluationInterview, self).create(cr, uid, vals, context=context) ?



2015-11-24 21:52 GMT+00:00 Houssine BAKKALI <houssine.bakkali@gmail.com>:
you must use _inherits if you want override the create method. And if you don't want to call the former create method don't call it in your create method.

replace the call to super
super(HrEvaluationInterview, self).create(cr, uid, vals, context=context)

2015-11-24 22:17 GMT+01:00 Yassine Teimi <yteimi01@gmail.com>:
EDIT : The problem is the create method is called twice : With original behavior, and with modifed behavior. 

How to call it once with only modified behavior ? 

2015-11-24 20:29 GMT+00:00 Yassine Teimi <yteimi01@gmail.com>:
I don't want to use delegation inheritance, I just want to change the create method behavior. The new created field 'interviewed_id' is not for that purpose, it's there to receive data from vals dictionnary, because this create method is called by another create method of 'hr_evaluation.evaluation' object. 

Any hints please ?


Le mardi 24 novembre 2015, Daniel Reis <dreis.pt@hotmail.com> a écrit :
I think you want to use _inherits instead of _inherit.

--DR

No dia 24/11/2015, às 20:03, Yassine Teimi <yteimi01@gmail.com> escreveu:

Dears, 

I want to change the following create method behavior (The code part I want to change is in bold)  : 

class hr_evaluation_interview(osv.Model): 
_name = 'hr.evaluation.interview'
_inherit = 'mail.thread'
_rec_name = 'user_to_review_id'
_description = 'Appraisal Interview'

def create(self, cr, uid, vals, context=None):
phase_obj = self.pool.get('hr_evaluation.plan.phase')         survey_id = phase_obj.read(cr, uid, vals.get('phase_id'), fields=['survey_id'], context=context)['survey_id'][0]         if vals.get('user_id'):             user_obj = self.pool.get('res.users')             partner_id = user_obj.read(cr, uid, vals.get('user_id'), fields=['partner_id'], context=context)['partner_id'][0]
else:             partner_id = None         user_input_obj = self.pool.get('survey.user_input')         if not vals.get('deadline'):             vals['deadline'] = (datetime.now() + timedelta(days=28)).strftime(DF)         ret = user_input_obj.create(cr, uid, {'survey_id': survey_id,
'deadline': vals.get('deadline'),
'type': 'link',
'partner_id': partner_id}, context=context)         vals['request_id'] = ret
return super(hr_evaluation_interview, self).create(cr, uid, vals, context=context)
It's the hr_evaluation_interview create method, I want when the interview request is created, the partner_id field receive a different value than it receives now. 

The partner_id receives the user_id (user related to the hr evaluator), I want it to be the evaluated employee (interviewd_id).

So I did the following using inheritance (changed code is in bold) : 

class HrEvaluationInterview(osv.Model): 
    _inherit = 'hr.evaluation.interview'

_columns = {
'interviewd_id': fields.many2one('hr.employee','Employee evaluated'),
}

def create(self, cr, uid, vals, context=None):
phase_obj = self.pool.get('hr_evaluation.plan.phase')
survey_id = phase_obj.read(cr, uid, vals.get('phase_id'), fields=['survey_id'], context=context)['survey_id'][0]
employee_obj = self.pool.get('hr.employee')
us_id = employee_obj.read(cr, uid, vals.get('interviewd_id'), fields=['user_id'], context=context)['user_id'][0] if vals.get('user_id'):
user_obj = self.pool.get('res.users')
partner_id = user_obj.read(cr, uid, us_id, fields=['partner_id'], context=context)['partner_id'][0]

else:
partner_id = None

        user_input_obj = self.pool.get('survey.user_input') if not vals.get('deadline'):
vals['deadline'] = (datetime.now() + timedelta(days=28)).strftime(DF)         ret = user_input_obj.create(cr, uid, {'survey_id': survey_id,
'deadline': vals.get('deadline'),
'type': 'link',
'partner_id': partner_id}, context=context)
vals['request_id'] = ret         return super(HrEvaluationInterview, self).create(cr, uid, vals, context=context)
The problem is that the behavior didn't change, it keeps doing the same things did by the parent method. Maybe it's because the return I'm doing, can you advise me something ? 

Thanks a lot.
--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe



--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18




--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18



--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe




--

Cordialement

Yassine TEIMI

Consultant & Odoo Project Manager
TEL : +212 6-87 71 41 18