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

[Odoo 10] text file from Odoo have encoding issue on Windows?

S'inscrire

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

Cette question a été signalée
windowspython2.7textencodingodoo10
1 Répondre
5445 Vues
Avatar
FEDERICO LEONI

I Know is not exactly related to Odoo but Python in general, but I'm getting serious issues creating a simple text file on Windows.

Back story: I have a customer who asked for a custom module to integrate Odoo with his fiscal software here in Brazil. The task was pretty easy, grab infos from POS Order of products and services (product.template inherited with some field to match the fiscal information) and create a .txt on a shared folder to pull automatically the bill inside the other proprietary software.
All working fine on Linux, but fact is the client want all installed under Windows. 
My custom module works fine but I have issues with the encoding, since it can't decode chars like ã or é or ç.  

pgto = '\n'.join(str(e) for e in pgto).replace('.', ',').upper()

f = open(str("/media/pedidos/" + self.pos_reference + ".txt"), "w+")
f.write(pgto.encode('cp1252'))

will create the following txt under Linux:

PEDIDO|CONSUMIDOR NÃO IDENTIFICADO||CAIXA||
ITEM|83002|GUARANÁ 350ML|4,5|1|UN|22021000|17,3|20,0|0,0|IBPT|5405|500|0|0300800|
PGTO|01|4,5|

but the same txt created under Windows results in:

PEDIDO|CONSUMIDOR NÃcO IDENTIFICADO||CAIXA||
ITEM|83002|GUARANá 350ML|4,5|1|UN|22021000|17,3|20,0|0,0|IBPT|5405|500|0|0300800|
PGTO|01|4,5|

Since I've worked with Linux to Windows conversion in the past was quite easy find the correct encoding for Windows (cp1252), doesn't seems as simple as write from Windows to Windows...

I tried with various decode (UTF-8, Latin-1 and so on), but until now with no appreciable results.

Please note I'm dealing with strings inside a var, is not easy add a u' on any field pulled from the DB before creating the text file.
Any clue?

0
Avatar
Ignorer
Avatar
FEDERICO LEONI
Auteur Meilleure réponse

Solved!

There are two solution for this kind of encoding issues under Windows but both may lead to some risks.

1. change the header of the model.py:

From

# -*- coding: utf-8 -*-

To

# -*- coding: cp1252 -*-

This coding will definitely solve the issue when writing on txt, but if you are updating  the DB on the same function at the same time, it could lead to some encoding issue inside the database.

2. Change sys property "on-the-fly":

Is the best solution for me. you can literally hack the sys default enconding and back to UTF-8 without messing too much. Just put in your code this:

import sys
reload (sys)
sys.setdefaultencoding('cp1252')

Problem solved, didn't find (for now) any issue using this method.
Anyway, my first module for Windows was finally deployed.

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 return action window or wizard from def copy()or def write method in odoo 10.
python2.7 odoo10
Avatar
Avatar
2
juil. 25
1737
Show edit button on odoo 10 qweb html report.
python2.7 odoo10
Avatar
0
déc. 24
1901
How to hide field on tree in odoo 10 based on a condition. Résolu
python2.7 odoo10
Avatar
Avatar
2
oct. 24
2138
Remove html tags in a text field with html widget on an exported xml file in odoo 10.
python2.7 odoo10
Avatar
Avatar
1
août 24
3261
Cannot upload pdf file on odoo 10 attachments.
python2.7 odoo10
Avatar
Avatar
2
juil. 24
2533
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