Skip to Content
Menu
This question has been flagged
4 Replies
9370 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 

Avatar
Discard
Best Answer
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
Avatar
Discard
Best Answer
  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.


Avatar
Discard
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
3
Sep 24
9991
2
Feb 24
600
1
Jul 23
1004
2
Jun 23
1395
1
May 23
11454