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

ir_translation for create form

Iscriviti

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

La domanda è stata contrassegnata
transactionsqlir_translationv14
2 Risposte
3429 Visualizzazioni
Avatar
Denis Lutsak

I have made a code that gets the translation value of the name field from the database and allows you to edit it and change it in the database, this code is not very well written (because this is the first time I work directly with the database), but it works for all languages and for all cases when the form is already created, but I can't figure out how to add this code so that it works when creating a new form. I was thinking of making the nameUA, nameRU... fields not count during creation, but only during editing, but I haven't figured out how to do it.

Here are my fields:

name = fields.Char('Name', index=True, required=True, translate=True)
nameUA = fields.Char('Name Ua', default=name, compute='_compute_name_ukr', required=True, readonly=False)
nameRU = fields.Char('Name Ru', default=name, compute='_compute_name_rus', required=True, readonly=False)
nameDE = fields.Char('Name De', default=name, compute='_compute_name_deu', required=True, readonly=False)
nameEN = fields.Char('Name En', default=name, compute='_compute_name_eng', required=True, readonly=False)

Here is my implementation code:

def _compute_name_ukr(self):
for template in self:
template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.name}';""")
src = template.env.cr.fetchall()[0][0]
template.env.cr.execute(f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='uk_UA';""")
name = template.env.cr.fetchall()[0][0]
if name == '':
template.env.cr.execute(
f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='{template.env.user.lang}';""")
name = template.env.cr.fetchall()[0][0]
template.env.cr.execute(
f"""UPDATE ir_translation SET value ='{name}' WHERE src = '{template.nameEN}' and lang ='uk_UA';""")
template.nameUA = name

@api.onchange('nameUA')
def onchange_name_ukr(self):
for template in self:
template.env.cr.execute(f"""UPDATE ir_translation SET value ='{template.nameUA}' WHERE src = '{template.nameEN}' and lang ='uk_UA';""")

def _compute_name_deu(self):
for template in self:
template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.name}';""")
src = template.env.cr.fetchall()[0][0]
template.env.cr.execute(f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='de_DE';""")
name = template.env.cr.fetchall()[0][0]
if name == '':
template.env.cr.execute(
f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='{template.env.user.lang}';""")
name = template.env.cr.fetchall()[0][0]
template.env.cr.execute(
f"""UPDATE ir_translation SET value ='{name}' WHERE src = '{src}' and lang ='de_DE';""")
template.nameDE = name

@api.onchange('nameDE')
def onchange_name_deu(self):
for template in self:
template.env.cr.execute(f"""UPDATE ir_translation SET value ='{template.nameDE}' WHERE src = '{template.nameEN}' and lang ='de_DE';""")

def _compute_name_rus(self):
for template in self:
template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.name}';""")
src = template.env.cr.fetchall()[0][0]
template.env.cr.execute(f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='ru_RU';""")
name = template.env.cr.fetchall()[0][0]
if name == '':
template.env.cr.execute(
f"""SELECT value FROM ir_translation WHERE src = '{src}' and lang ='{template.env.user.lang}';""")
name = template.env.cr.fetchall()[0][0]
template.env.cr.execute(
f"""UPDATE ir_translation SET value ='{name}' WHERE src = '{src}' and lang ='ru_RU';""")
template.nameRU = name

@api.onchange('nameRU')
def onchange_name_rus(self):
for template in self:
template.env.cr.execute(f"""UPDATE ir_translation SET value ='{template.nameRU}' WHERE src = '{template.nameEN}' and lang ='ru_RU';""")
def _compute_name_eng(self):
for template in self:
template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.nameRU}';""")
src = template.env.cr.fetchall()[0][0]
template.nameEN = src

@api.onchange('nameEN')
def onchange_name_eng(self):
for template in self:
template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.nameDE}';""")
src = template.env.cr.fetchall()[0][0]
template.env.cr.execute(
f"""UPDATE ir_translation
SET value ='
{template.nameEN}'
WHERE src = '
{src}' and lang ='en_US';
""")
template.env.cr.execute(
f"""UPDATE ir_translation
SET src ='
{template.nameEN}'
WHERE value ='
{template.nameEN}' and lang ='en_US';
""")
template.env.cr.execute(
f"""UPDATE ir_translation
SET src ='
{template.nameEN}'
WHERE value ='
{template.nameUA}' and lang ='uk_UA';
""")
template.env.cr.execute(
f"""UPDATE ir_translation
SET src ='
{template.nameEN}'
WHERE value ='
{template.nameRU}' and lang ='ru_RU';
""")
template.env.cr.execute(
f"""UPDATE ir_translation
SET src ='
{template.nameEN}'
WHERE value ='
{template.nameDE}' and lang ='de_DE';
""")

template.env.cr.execute(
f"""SELECT src FROM ir_translation WHERE value = '{template.nameRU}';""")
src = template.env.cr.fetchall()[0][0]
template.nameEN = src

@api.onchange('name')
def name_onchange(self):
for template in self:
if template.env.user.lang == 'de_DE':
template.nameDE = template.name
if template.env.user.lang == 'uk_UA':
template.nameUA = template.name
if template.env.user.lang == 'ru_RU':
template.nameRU = template.name
if template.env.user.lang == 'en_US':
template.nameEN = template.name

If anyone can give me a hint to solve my problem I will be most grateful!

0
Avatar
Abbandona
Avatar
Ravi Gadhia
Risposta migliore

Odoo provides built-in support for adding a translation term for translated fields, what's your use case?





I think it's not a good idea to create compute fields for translation,  it would be better to create a new form/widget in js and handle the translation based on context like the translation dialog box did 
ref: https://github.com/odoo/odoo/blob/14.0/addons/web/static/src/js/widgets/translation_dialog.js#L10
https://github.com/odoo/odoo/blob/14.0/addons/web/static/src/js/widgets/translation_dialog.js#L166

0
Avatar
Abbandona
Denis Lutsak
Autore

I know that it can be done with translate=True, but I need to do it in the form, not in a separate window.

Avatar
Savya Sachin
Risposta migliore

Hi,

Instead didn’t you try the builtin feature of translation provider by odoo, you can add the field parameter translate=True,

Just redifine your field like this,

name = fields.Char('Name', index=True, required=True, translate=True)
 For the time being, remove the unnecessary onchange and custom fields.

Now, activate the developer mode, settings -> translations -> in the application terms view filter the terms by your module and search for the name field. You will see all the translations for the name field in different languages and can edit here so that odoo will handle the translation for this field based on the users language preference.

Thanks

0
Avatar
Abbandona
Denis Lutsak
Autore

I know that it can be done with translate=True, but I need to do it in the form, not in a separate window.

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à
d
sql odoo v14
Avatar
0
ago 21
111
How to use self._cr.execute get my data? Risolto
python sql odoo11 v14
Avatar
Avatar
Avatar
Avatar
3
dic 21
16720
Advanced orm, sql insert through select, how to?
transaction orm insert sql select
Avatar
Avatar
1
mar 15
8235
Odoo14 alternative for Automated Translations through Gengo API module
v14
Avatar
Avatar
Avatar
Avatar
3
set 25
3491
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Avatar
0
ago 25
971
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