Odoo Help


How to get a value of a field from a another class OdooV8

Hichem MELIK
on 6/9/16, 5:21 AM 1,675 views


I am currently creating a module that will display calculations in invoices. The problem is that I do not know how to retrieve values. I read a lot of documentation but I still do not understand how can i do it .


from openerp import models, fields, api

class unite_beneficiaire(models.Model):

default_smic=fields.Float(string='Taux horaire du SMIC', default='9.61',default_model='unite.beneficiaire.config.settings')
default_traitementbrutannuel=fields.Float(string='Traitement brut annuel minimum', default='17169.12',default_model='unite.beneficiaire.config.settings')


from openerp import models, api, _, fields

class account_invoice(models.Model):

def _secteur_public(self, cr, uid, ids, context=None):
    _ub = self.pool.get('unite.beneficiaire.config.settings').browse(cr,uid,ids)
    # i want to get the 'default_traitementbrutannuel' and 'ammout_total' value and return :
     # return (ammout_total/default_traitementbrutannuel)

ub=fields.Float(string='Unité bénéficiaire',compute='_secteur_public',readonly=True)

I want to get the 'default_traitementbrutannuel' value of 'unite.beneficiaire.config.settings' class and 'ammout_total' value of the current class and return :


thank you 

On 7/27/16, 7:23 AM
create a field in py file,_secteur_public

ub=fields.Float(string='Unité bénéficiaire',compute='_secteur_public',readonly=True)

def _secteur_public(self):   
     for i in self.env['unite.beneficiaire.config.settings'].search([]):

Prakash Sharma

--Prakash Sharma--
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 6/9/16, 7:55 AM
  1. Not use models.Model of configuration  instead use  models.TransientModel

  2. Define   get_default_fields and set_fields method 

  3. Use ir.values in get_default_fields and set_fields

  4. Now retrieve the data from  self.env['ir.values']

For Using  ir.values you can refer  this  link



def get_default_acquirer(self, fields):

default_acquirer = False

if 'default_acquirer' in fields:

default_acquirer = self.env['ir.values'].get_default('payment.transaction', 'acquirer_id', company_id=self.env.user.company_id.id)

return {

'default_acquirer': default_acquirer



def set_default_acquirer(self):

for wizard in self:

ir_values = self.env['ir.values']

if self.user_has_groups('base.group_configuration'):

ir_values = ir_values.sudo()

ir_values.set_default('payment.transaction', 'acquirer_id', wizard.default_acquirer.id, company_id=self.env.user.company_id.id)

Hope it may help in your case.

Hichem MELIK
On 6/9/16, 10:31 AM

i don't get the step 3 & 4 did you have an example ?

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 6/9/16, 5:21 AM
Seen: 1675 times
Last updated: 7/27/16, 7:23 AM