Skip to Content
Menu
This question has been flagged
1 Reply
12994 Views

Hello house,

Please am new to Odoo.

I need a method on how a fields value in another model to be updated when a record is created.

For instance, i have these classes

class Antena_Pole(models.Model):
    _name='antena.pole'
    current_signal = fields.Float(string='Current Signal')

class RadioWave(models.Model):
    _name='radio.wave'
   current_wave = fields.Float(string='Wave')

class RadioBand(models.Model):
    _name='radio.band'
     signal = fields.Float(string='Signal')
    antena = fields.Many2one('antena.pole', string='Antena')
    wave = fields.Float(string='Wave')

class Antena_Pole(models.Model):
    _inherit='antena.pole'
    radioband_ids = fields.One2many('radio.band', 'antena', string='Radio Band')

So when a record is created in RadioBand Class, i want the signal value and wave value to be updated in AntenaPole Class and RadioWave Class respectively.

Am using odoo version 10

Thanks in advance





Avatar
Discard

If I want to check some constraints or insert some values before creating, editing or deleting our record than you may use odoo override methods: http://learnopenerp.blogspot.com/2017/11/how-to-override-odoo-functions.html

Best Answer

Hi,

You can either make the fields in the model Radioband class as a many2one field of  radio.wave or you can override the create method of the model radioband and create objects in the other models.

For overriding the create method and making objects in the other models please see this link: https://www.odoo.yenthevg.com/override-create-functions-odoo/


From this inside this create function yoh can call the create methods of other objects by passing values.

@api.model
def create(self, values):
res = super(ReportFinancial, self).create(values)
# creating record in another model
if values.get('wave'):
wave_val = {
'custom_wave': values['wave']
}
self.env['radio.wave'].create(wave_val)
return res

Thanks

Avatar
Discard