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

override create method with multiple returns in OpenERP ver 7 [Closed]

By
priyankahdp
on 4/29/13, 5:39 AM 4,201 views

The Question has been closed

by
priyankahdp
on 04/29/2013 07:56:47

I need to do two activities in my activity method. one is need to return value for total_workers field.but need to return ID also because its necessary requirement in OpenERP when we override that method. then have to return 2 things.please advice me how to implement this in my form. with one return value this is worked for both things.but need to return both.

def create(self, cr, uid, values, context=None):
    name = 'CheckRoll No = ' + str(values['checkroll_no']) + ' & Gang No = ' + str(values['gang_no'])
    values.update({'name': name})
    total_tea_workers = 0
    offer_id = super(bpl_work_offer, self).create(cr, uid, values, context=context)
    tea_worker_obj = self.browse(cr, uid, offer_id, context=context) or []
    tea_worker_ids = self.pool.get('bpl.selected.tea.workers.line').search(cr, uid, [('tea_line_worker_id', '=', tea_worker_obj.id)])
    for tea_worker in self.pool.get('bpl.selected.tea.workers.line').browse(cr, uid, tea_worker_ids):
        if tea_worker.is_selected:
            total_tea_workers += 1
    return {'value': {'total_workers': total_tea_workers}}
    return offer_id

screen

EDITED

I sort it out in this way.hope this will help for others :-)

i wrote a function for my field

def _compute_workers(self, cr, uid, ids, fieldname, arg, context=None):
    total_workers = total_tea_workers = total_rubber_workers = total_sundry_workers = total_other_workers = 0
    res = dict.fromkeys(ids, False) 
    for this in self.browse(cr, uid, ids, context=context):
        tea_worker_ids = self.pool.get('bpl.selected.tea.workers.line').search(cr, uid, [('tea_line_worker_id', '=', this.id)])
        for tea_worker in self.pool.get('bpl.selected.tea.workers.line').browse(cr, uid, tea_worker_ids):
            if tea_worker.is_selected:
                total_tea_workers += 1                
        rubber_worker_ids = self.pool.get('bpl.selected.rubber.workers.line').search(cr, uid, [('rubber_line_worker_id', '=', this.id)])
        for rubber_worker in self.pool.get('bpl.selected.rubber.workers.line').browse(cr, uid, rubber_worker_ids):
            if rubber_worker.is_selected:
                total_rubber_workers += 1                
        sundry_worker_ids = self.pool.get('bpl.selected.sundry.workers.line').search(cr, uid, [('sundry_line_worker_id', '=', this.id)])
        for sundry_worker in self.pool.get('bpl.selected.sundry.workers.line').browse(cr, uid, sundry_worker_ids):
            if sundry_worker.is_selected:
                total_sundry_workers += 1                
        other_worker_ids = self.pool.get('bpl.selected.other.workers.line').search(cr, uid, [('other_line_worker_id', '=', this.id)])
        for other_worker in self.pool.get('bpl.selected.other.workers.line').browse(cr, uid, other_worker_ids):
            if other_worker.is_selected:
                total_other_workers += 1
    total_workers = total_tea_workers + total_rubber_workers + total_sundry_workers + total_other_workers                                                                             
    res[this.id] = total_workers 
    return res

i changed my integer field to functional field

'total_workers': fields.function(_compute_workers, type="integer", string="Total Workers"),

1

saad

--saad--
1008
| 5 4 8
Casablanca, Morocco
--saad--
saad
On 4/29/13, 6:19 AM

You don't have to return values. As values is a dictionnary, you can set the total_workers field like that:

def create(self, cr, uid, values, context=None):
    name = 'CheckRoll No = ' + str(values['checkroll_no']) + ' & Gang No = ' + str(values['gang_no'])
    values.update({'name': name})
    total_tea_workers = 0
    offer_id = super(bpl_work_offer, self).create(cr, uid, values, context=context)
    tea_worker_obj = self.browse(cr, uid, offer_id, context=context) or []
    tea_worker_ids = self.pool.get('bpl.selected.tea.workers.line').search(cr, uid, [('tea_line_worker_id', '=', tea_worker_obj.id)])
    for tea_worker in self.pool.get('bpl.selected.tea.workers.line').browse(cr, uid, tea_worker_ids):
        if tea_worker.is_selected:
            total_tea_workers += 1
    values['total_workers'] = total_tea_workers
    return offer_id

but still not showz in my field/its remain as zero

post updated with screen image

priyankahdp
on 4/29/13, 6:32 AM

The 'total_workers' shouldn't be a readonly field.

saad
on 4/29/13, 6:37 AM

dear S@@D, its not a readonly field at the moment

priyankahdp
on 4/29/13, 6:45 AM

Can you do a print for 'values' just before the method return and paste the result here ?

saad
on 4/29/13, 7:49 AM

S@@D I got a option and succeeded it with funcational fields.post updated :-) Thanks 4 ur advices

priyankahdp
on 4/29/13, 7:55 AM

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 4/29/13, 5:39 AM
Seen: 4201 times
Last updated: 3/16/15, 8:10 AM