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

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

By
Hichem MELIK
on 6/9/16, 5:21 AM 503 views

Hello,

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 .


res_config.py

from openerp import models, fields, api

class unite_beneficiaire(models.Model):
_name='unite.beneficiaire.config.settings'
_inherit='res.config.settings'

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


account_invoice.py

from openerp import models, api, _, fields

class account_invoice(models.Model):
_inherit='account.invoice'

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 :

(ammout_total/default_traitementbrutannuel)


thank you 

1
Janarthanan
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)

@api.multi
def _secteur_public(self):   
     for i in self.env['unite.beneficiaire.config.settings'].search([]):
         val=ammout_total/i.default_traitementbrutannuel
     self.answer=val
1

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--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

https://github.com/odoo/odoo/blob/7682760dcad232829fbb5d4221f66a1ebb9d6c91/addons/website_payment/models/res_config.py

@api.model

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

}

@api.multi

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.


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

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

2 follower(s)

Stats

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