Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

add custom function to _get_report_value

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
functionpythonvaluesreporting
2 Réponses
10922 Vues
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
Ignorer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Meilleure réponse
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
Ignorer
Avatar
BOUDEKAK MOHAMED
Auteur Meilleure réponse

Thank you very much, great help thanks

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
How to call a function defined in python in a mako file?
function python reporting mako openerp7
Avatar
Avatar
3
août 15
6636
OpenERP fields.function() explanation
function python xml
Avatar
1
déc. 22
45919
Generate report from Python by given user and data range
python reporting odooV8
Avatar
Avatar
1
mai 20
7048
Call a function on print menu option instead of qweb template Résolu
function reporting odoo12.0
Avatar
Avatar
Avatar
3
déc. 19
8217
Selection "report value" can not be set in accounting reports
accounting values reporting
Avatar
0
févr. 17
3187
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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