Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

add custom function to _get_report_value

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
functionpythonvaluesreporting
2 Risposte
10923 Visualizzazioni
Avatar
BOUDEKAK MOHAMED

Amm using odoo 12 and have a custom python function that have one parametre and i want to call it in my report using _get_report_value,  here is my model 



from odoo import  models,api

class ReportInvoiceWithoutPayment(models.AbstractModel):
_name = 'report.account.report_invoice'
_description = 'Account report without payment lines'

def chiffreen(self, num):

muz = (' ', 'Onze', 'Douze', 'Treize',
'Quatorze', 'Quinze', 'Seize', 'Dix-Sept', 'Dix-Huit', 'Dix-Neuf')

to_19_fr = ('Zéro', 'Un', 'Deux', 'Trois', 'Quatre', 'Cinq', 'Six',
'Sept', 'Huit', 'Neuf', 'Dix', 'Onze', 'Douze', 'Treize',
'Quatorze', 'Quinze', 'Seize', 'Dix-Sept', 'Dix-Huit', 'Dix-Neuf')
tens_fr = (
'Vingt', 'Trente', 'Quarante', 'Cinquante', 'Soixante', 'Soixante-Dix', 'Quatre-Vingt', 'Quatre-Vingt Dix')
denom_fr = ('',
'Mille', 'Million(s)', 'Milliards', 'Billions', 'Quadrillions',
'Quintillion', 'Sextillion', 'Septillion', 'Octillion', 'Nonillion',
'Décillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion',
'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Icosillion', 'Vigintillion')

def _convert_nn_fr(val):
""" convertion des valeurs < 100 en Français
"""
if val < 20:
return to_19_fr[val]
for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens_fr)):
if dval + 10 > val:
if val % 10:
if (val > 70 and val <= 79):
dcap = 'Soixante'
return dcap + '-' + muz[val % 10]

if (val > 90 and val <= 99):
dcap = 'Quatre-vingt'
return dcap + '-' + muz[val % 10]
else:
return dcap + '-' + to_19_fr[val % 10]

return dcap

def _convert_nnn_fr(val):
""" convert a value < 1000 to french

special cased because it is the level that kicks
off the < 100 special case. The rest are more general. This also allows you to
get strings in the form of 'forty-five hundred' if called directly.
"""
word = ''
(mod, rem) = (val % 100, val // 100)
b = val // 100
if rem > 0:
if b == 1:
word = 'Cent'
else:
word = to_19_fr[rem] + ' Cent'
if mod > 0:
word += ' '
if mod > 0:
word += _convert_nn_fr(mod)
return word

def french_number(val):
if val < 100:
return _convert_nn_fr(val)
if val < 1000:
return _convert_nnn_fr(val)
for (didx, dval) in ((v - 1, 1000 ** v) for v in range(len(denom_fr))):
if dval > val:
mod = 1000 ** didx
l = val // mod
r = val - (l * mod)
if (l == 1) and (denom_fr[didx] == 'Mille'):
ret = denom_fr[didx]
else:
ret = _convert_nnn_fr(l) + ' ' + denom_fr[didx]
if r > 0:
ret = ret + ' ' + french_number(r)
return ret

def amount_to_text_fr(number):
import math
number = '%.2f' % number
units_name = ' '
list = str(number).split('.')
muzamil = (french_number(abs(int(list[0]))))
start_word = muzamil
end_word = ''
# french_number(int(list[1]))
cents_number = int(list[1])
cents_name = (cents_number > 1) and ' Francs' or ' Franc'
final_result = start_word + ' ' + units_name + ' ' + end_word + ' ' + cents_name
return final_result

def IntOuDouble(num):
double = True if type(num) == float else False
if double == True:
number = str(num)
premier = number.split('.')[0]
deuxieme = number.split('.')[1]
# print(premier)
# print(deuxieme)
premier = amount_to_text_fr(int(premier))
deuxieme = amount_to_text_fr(int(deuxieme))
premier = premier[:len(premier) - 6]
deuxieme = deuxieme[:len(deuxieme) - 6] + 'Dinare Algerien'
# print(premier)
# print(deuxieme)
if deuxieme == 'Zéro Dinare Algerien':
res = premier + 'Dinare Algerien'
else:
res = premier + 'virgule ' + deuxieme
resultat = ''
for rec in res.split():
resultat = resultat + ' ' + rec
res = resultat
return res
else:
return amount_to_text_fr(num)

return IntOuDouble(num)

@api.model
def _get_report_values(self, docids, data=None):
docs=self.env['account.invoice'].browse(docids)
return {
'doc_ids': docids,
'doc_model': 'account.invoice',
'docs':docs ,
'chiffreen':self.chiffreen(docs.amount_total),
'report_type': data.get('report_type') if data else '',

}
1
Avatar
Abbandona
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Risposta migliore
Hi,
If you want to call a python function with parameters, you can try this way.
return {
'doc_ids': docids,
'doc_model': 'account.invoice',
'docs':docs ,
'chiffreen':self.chiffreen,
'report_type': data.get('report_type') if data else '', }
then the function call from the template.
<t t-set="chiffreen"
t-value="chiffreen(docs.amount_total)"/>
now you will get the return value of the function in chiffreen. you can use the variable in your reports.
regards,
5
Avatar
Abbandona
Avatar
BOUDEKAK MOHAMED
Autore Risposta migliore

Thank you very much, great help thanks

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
How to call a function defined in python in a mako file?
function python reporting mako openerp7
Avatar
Avatar
3
ago 15
6636
OpenERP fields.function() explanation
function python xml
Avatar
1
dic 22
45919
Generate report from Python by given user and data range
python reporting odooV8
Avatar
Avatar
1
mag 20
7048
Call a function on print menu option instead of qweb template Risolto
function reporting odoo12.0
Avatar
Avatar
Avatar
3
dic 19
8217
Selection "report value" can not be set in accounting reports
accounting values reporting
Avatar
0
feb 17
3187
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now