Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

ir_translation for create form

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
transactionsqlir_translationv14
2 Antwoorden
3507 Weergaven
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
Annuleer
Avatar
Ravi Gadhia
Beste antwoord

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
Annuleer
Denis Lutsak
Auteur

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
Beste antwoord

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
Annuleer
Denis Lutsak
Auteur

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

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
d
sql odoo v14
Avatar
0
aug. 21
111
How to use self._cr.execute get my data? Opgelost
python sql odoo11 v14
Avatar
Avatar
Avatar
Avatar
3
dec. 21
16802
Advanced orm, sql insert through select, how to?
transaction orm insert sql select
Avatar
Avatar
1
mrt. 15
8337
Odoo14 alternative for Automated Translations through Gengo API module
v14
Avatar
Avatar
Avatar
Avatar
3
sep. 25
3629
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Avatar
0
aug. 25
1063
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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