Skip to Content
Menu
This question has been flagged

I'm trying to generate a function to return a computed value to a field while I modify another field using the following code:


from openerp import models,fields,api
class exec_modl(models.Model):
 
        _name           =   "exec.modl"
        _rec_name       =   "exec_desc"
 
        exec_code       =   fields.Char('Identificador',required=True,size=3)
        exec_desc       =   fields.Char('Descripción',required=True)
        cour_exec       =   fields.Many2one('cour.modl')
        proc_exec       =   fields.Many2one('enro.modl')
        inte_code       =   fields.Char(compute='_onchange_proc')  #a field for the internal_id I'm generating

       

This is my test function, as a start im just trying to print a static value into the field, my second milestone is get values from another models to conform a real internal_id

        #test function
        @api.onchange('proc_exec')
        def _onchange_proc(self):
            cate    =   "XX"
            cour    =   "XXXX"
            exet    =   "XXX"
            output  =   cate+"-"+cour+"-"+exet
            return output

Any suggestion to achieve this ? I'm a bit confused about the correct use of functions on fields on odoo v9.

Avatar
Discard
Author Best Answer

Problem solved with this:    

for cate var added a related field to cour_exec for retrieve the value of cate on cour_modl model

cour_cate = fields.Many2one(related="cour_exec.cour_cate", string="cate")

And for the function i've used the following code

@api.depends('proc_exec','cour_exec','cour_cate')
def _onchange_proc(self):
     cate    =    str(self.cour_cate)
     cour   =    str(self.cour_exec)
     exet    =    str(self.proc_exec)
     self.inte_code    =    cate+"-"+cour+"-"+exet

    

Disclaimer: I've replaced this function with other functionalities and i dont have this code runing but I post it as a idea for someone who need some guidelines to achive something similar, code can contain some errors.

Avatar
Discard
Best Answer

hello,

try this function:

        @api.depends('proc_exec')
        def _onchange_proc(self):
            cate    =   "XX"
            cour    =   "XXXX"
            exet    =   "XXX"
            output  =   cate+"-"+cour+"-"+exet
            self.inte_code = output
Avatar
Discard
Best Answer

Hi,

In your function you should try:

#test function
        @api.onchange('proc_exec')
        def _onchange_proc(self):
            cate    =   "XX"
            cour    =   "XXXX"
            exet    =   "XXX"
            #output  =   cate+"-"+cour+"-"+exet
# self.inte_code = output or
            return {'value':{
'inte_code': output
  }}




Avatar
Discard
Related Posts Replies Views Activity
3
Oct 22
19461
1
May 20
3511
1
Mar 15
3226
2
Dec 22
5272
2
Jul 22
3066