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

How to avoid unicode transformation of my data passed to a report parser?

S'inscrire

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

Cette question a été signalée
dateqwebformatunicode
2 Réponses
6820 Vues
Avatar
Pascal Tremblay

Hello all,


I send many date fields to a report with this line in my wizard class :

data['form'] = self.read(cr, uid, ids, ['journal_id', 'date_to', 'date_from','date_deposit'], context=context)[0]


In the log, I see that for this data variable. The dates seem to be in a date format/type :

{'form': {'date_deposit': '2016-02-17', 'date_from': '2016-02-01 00:00:00', 'date_to': '2016-02-15 00:00:00', 'id': 39, 'journal_id': (18, u"Journal Caisse Populaire Desjardins d'Alma - CF (CAD)")}}


When these datas arrive in the report paser, in my render_html method, they are like this. I would say that all data is now in a unicode format :

data : {u'form': {u'journal_id': [18, u"Journal Caisse Populaire Desjardins d'Alma - CF (CAD)"], u'date_from': u'2016-02-01 00:00:00', u'date_to': u'2016-02-15 00:00:00', u'id': 39, u'date_deposit': u'2016-02-17'}}


So, in my qweb report, I can not format my date with my usual line :

 <p t-esc="data.get('date_from')" t-field-options='{"format": "d MMMM y"}'/>


I rather have to format my dates with :

<p t-esc="time.strftime('%d %B %Y',time.strptime(data.get('date_from'),'%Y-%m-%d %H:%M:%S'))"/>


My question :

How could I avoid this unicode transformation of my data variable? My date are not in a date type anymore...



UPDATE #1

I have verified data inthe get_action method. Datas are still ok. No trace of unicode.

    @api.v7
    def get_action(self, cr, uid, ids, report_name, data=None, context=None):
        _logger.error("datawwwww :: %s", str(data))



UPDATE #2

According to the tip of Axel Mendoza, I have tried to convert unicode dates to date format. But, it is still not enough to get the right format in my qweb report with

 <p t-esc="data.get('date_from')" t-field-options='{"format": "d MMMM y"}'/>

I still get this in my qweb pdf :

2016-02-01

I have tried this code in me render_html method :

def render_html(self, data=None):
        date_from_buf = datetime.strptime(data['form'].get('date_from'), "%Y-%m-%d %H:%M:%S")
        date_from = date.strftime(date_from_buf, "%Y-%m-%d" )



Here is the log of my docargs. the date_from seems to be right there:

docargs : {'docs': wizard.create.deposit(53,), 'doc_model': u'wizard.create.deposit', 'date_from': '2016-02-01', 'lines': <bound method report.sale_lapagept.report_qweb_create_deposit_cf.lines of report.sale_lapagept.report_qweb_create_deposit_cf()>, 'date_to': datetime.datetime(2016, 2, 15, 20, 32, 58), 'doc_ids': [], 'data': {u'journal_id': [18, u"Journal Caisse Populaire Desjardins d'Alma - CF (CAD)"], u'date_from': u'2016-02-01 20:32:55', u'date_to': u'2016-02-15 20:32:58', u'id': 53, u'date_deposit': u'2016-02-19'}}


UPDATE #3

With this code :

@api.multi

def render_html(self, data=None): 

     date_from = datetime.strptime(data['form'].get('date_from'), "%Y-%m-%d %H:%M:%S")



I get this log :

docargs : {'docs': wizard.create.deposit(54,), 'doc_model': u'wizard.create.deposit', 'date_from': datetime.datetime(2016, 2, 1, 20, 32, 55), 'lines': <bound method report.sale_lapagept.report_qweb_create_deposit_cf.lines of report.sale_lapagept.report_qweb_create_deposit_cf()>, 'date_to': datetime.datetime(2016, 2, 15, 20, 32, 58), 'doc_ids': [], 'data': {u'journal_id': [18, u"Journal Caisse Populaire Desjardins d'Alma - CF (CAD)"], u'date_from': u'2016-02-01 20:32:55', u'date_to': u'2016-02-15 20:32:58', u'id': 54, u'date_deposit': u'2016-02-19'}}



In the qweb template, I have this code :

    <p t-esc="data.get('date_from')" />

    <p t-esc="o.date_from" t-field-options='{"format": "d MMMM y"}'/>

    <p t-esc="date_from" t-field-options='{"format": "d MMMM y"}'/>

    <p t-esc="data.get('date_from')" t-field-options='{"format": "d MMMM y"}'/>

    <p t-esc="time.strftime('%d %B %Y',time.strptime(data.get('date_from'),'%Y-%m-%d %H:%M:%S'))"/>


And I still get the wrong result with {"format": "d MMMM y"}

2016-02-01 20:32:55

2016-02-01 20:32:55

2016-02-01 20:32:55

2016-02-01 20:32:55

01 février 2016


I will become crazy!


0
Avatar
Ignorer
Axel Mendoza

So then my other answer works nice!!

Avatar
Axel Mendoza
Meilleure réponse

In the get_action method the data are not serialized yet, so it's not converted to unicode. The values that you pass using the data are values unrelated to any kind of python data type, normally those values are serialize those values in strings, int and float numbers to be sent it to the browser to be processed by the view action manager to determine what need to be done with the action dict and call the server controller action for the respective type of action, that's when the strings are converted to unicode. So if you wanna the value of the date_from as a datetime value type, you should convert it in the render_html method of your parser before pass it to the render of the report template and the same with all the values that you need to convert it before the report is rendered.

#Update 1

The thing is that the format pattern in t-field-options in qweb is not evaluated using datetime.strftime, it's using babel.dates.format_date function so you need to check on that library method for allowed patterns

or

you could format it by yourself using datetime.strftime before put it on the docargs data

1
Avatar
Ignorer
Pascal Tremblay
Auteur

I have tried to convert unicode to date format... see UPDATE #2.

Axel Mendoza

You are just doing an extra last step trying to convert the datetime value to string again, just put as a datetime value for the docargs data, t-field-options format operates over datetime values not over strings.

Pascal Tremblay
Auteur

May be docargs are still transformed in string by the render() method called at the end of my render_html() method. I will check this tomorrow

Axel Mendoza

see my ·Update 1

Pascal Tremblay
Auteur

thanks for your patience.

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 can we change date view format from dd/mm/yyyy to mm/dd/yyyy Résolu
date format
Avatar
Avatar
Avatar
Avatar
4
oct. 25
80795
QWeb report : calculate number of days late for task deadlines
date qweb
Avatar
Avatar
Avatar
2
oct. 21
8575
How to format data['form']['date_start'] to get the month name in letters? Résolu
date qweb format month letters
Avatar
1
juil. 21
10840
Formatting dates in Qweb report: account.report_overdue_document Résolu
date qweb format report datetime
Avatar
Avatar
Avatar
Avatar
Avatar
7
déc. 23
23577
How could I format the printing date of a qweb report in the customer language?
language date qweb format today
Avatar
0
août 16
6620
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