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

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

Iscriviti

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

La domanda è stata contrassegnata
windowspython2.7textencodingodoo10
1 Rispondi
5462 Visualizzazioni
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
Abbandona
Avatar
FEDERICO LEONI
Autore Risposta migliore

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
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 return action window or wizard from def copy()or def write method in odoo 10.
python2.7 odoo10
Avatar
Avatar
2
lug 25
1744
Show edit button on odoo 10 qweb html report.
python2.7 odoo10
Avatar
0
dic 24
1909
How to hide field on tree in odoo 10 based on a condition. Risolto
python2.7 odoo10
Avatar
Avatar
2
ott 24
2142
Remove html tags in a text field with html widget on an exported xml file in odoo 10.
python2.7 odoo10
Avatar
Avatar
1
ago 24
3267
Cannot upload pdf file on odoo 10 attachments.
python2.7 odoo10
Avatar
Avatar
2
lug 24
2538
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