Skip to content

Commit

Permalink
Merge PR #2841 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by francesco-ooops
  • Loading branch information
OCA-git-bot committed Jun 26, 2024
2 parents afb49d5 + b60a711 commit a068cc9
Show file tree
Hide file tree
Showing 17 changed files with 967 additions and 0 deletions.
163 changes: 163 additions & 0 deletions l10n_it_amount_to_text/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
==============================================
ITA - Localizzazione valute per amount_to_text
==============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8f58325e045ce1d0b3579bd4629e533cd95a993fdba6a488e0bcafb540d39365
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_amount_to_text
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_amount_to_text
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

**Italiano**

Il core di Odoo fornisce ``amount_to_text``, il quale converte importi numerici in testo ottenendo la lingua dal contesto fornito o dalle impostazioni utente/partner, con alcune limitazioni.

Esempio: 45,75 €

* Lingua utente "Inglese" → Forty-Five Euros and Seventy-Five Cents
* Lingua utente "Italiano" → Quarantacinque Euros e Settantacinque Cents

L'unità/sottounità di valuta non viene tradotta e non viene gestita la forma singolare. Inoltre tutte le parole possiedono l'iniziale maiuscola, forma non corretta nella lingua italiana.

Questo modulo fornisce una base per tradurre le unità/sottounità di valuta, adattando le parole alle regole della lingua italiana.

Vengono inoltre gestite le eccezioni per la forma singolare delle valute EUR, USD, GBP e CNY.

Esempio: 1,01 €

* La parte intera diventa "un euro", non "uno euro"
* La parte decimale diventa "un centesimo", non "uno centesimi"

**English**

Odoo core provides ``amount_to_text``, which converts numerical amounts to text getting language from given context or user/partner setting, with some limitations.

Example: 45,75 €

* User Language 'English' -> Forty-Five Euros and Seventy-Five Cents
* User Language 'Italian' -> Quaranta Euros e Settantacinque Cents

Currency unit/subunit is not translated and singular form is not handled. Moreover all words are capitalized, which is incorrect in italian language.

This module provides a base for translating currency unit/subunit adapting words to italian language rules.

Singular form expections for EUR, USD, GBP and CNY currencies are handled as well.

Example: 1,01 €

* Integer part becomes "un euro", not "uno euro"
* Decimal part becomes "un centesimo", not "uno centesimi"

**Table of contents**

.. contents::
:local:

Configuration
=============

**Italiano**

Versione libreria ``num2words`` >= 0.5.12

**English**

``num2words`` library version >= 0.5.12

Usage
=====

**Italiano**

Chiamare la funzione ``amount_to_text`` nel modello valuta (``res.currency``).

Per esempio, se è necessario convertire un importo in testo aggiungere questo codice ai report::

<t t-foreach="docs" t-as="o">
<t t-set="currency" t-value="o.currency_id"/>
# Language obtained from context
<t t-esc="currency.with_context({'lang': 'it_IT'}).amount_to_text(45.75)"/>

# Language obtained from user/partner settings.
# If not it_IT, Odoo core amount_to_text will be used.
<t t-esc="currency.amount_to_text(45.75)"/>
</t>

**English**

Call function ``amount_to_text`` in currency model (``res.currency``).

For example, add this code if you need to convert amount to text in your reports::

<t t-foreach="docs" t-as="o">
<t t-set="currency" t-value="o.currency_id"/>
# Language obtained from context
<t t-esc="currency.with_context({'lang': 'it_IT'}).amount_to_text(45.75)"/>

# Language obtained from user/partner settings.
# If not it_IT, Odoo core amount_to_text will be used.
<t t-esc="currency.amount_to_text(45.75)"/>
</t>

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_amount_to_text%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Sergio Zanchetta - Associazione PNLug APS
* Ecosoft Co. Ltd

Contributors
~~~~~~~~~~~~

* Saran Lim. <[email protected]>
* Pimolnat Suntian <[email protected]>
* Sergio Zanchetta <https://github.com/primes2h>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_amount_to_text>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions l10n_it_amount_to_text/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions l10n_it_amount_to_text/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# Copyright 2022 Sergio Zanchetta (Associazione PNLug APS - Gruppo Odoo)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "ITA - Localizzazione valute per amount_to_text",
"version": "14.0.1.0.0",
"category": "Localization/Italy",
"summary": "Localizza le valute in italiano per amount_to_text",
"author": "Sergio Zanchetta - Associazione PNLug APS,"
"Ecosoft Co. Ltd,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-italy",
"license": "AGPL-3",
"depends": ["base"],
"external_dependencies": {"python": ["num2words"]}, # num2words >= 0.5.12
"data": [],
"installable": True,
}
38 changes: 38 additions & 0 deletions l10n_it_amount_to_text/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_it_amount_to_text
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-05 21:06+0100\n"
"PO-Revision-Date: 2021-01-05 21:08+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"
"Last-Translator: Sergio Zanchetta <[email protected]>\n"
"Language: it_IT\n"

#. module: l10n_it_amount_to_text
#: model:ir.model,name:l10n_it_amount_to_text.model_res_currency
msgid "Currency"
msgstr "Valuta"

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency__id
msgid "ID"
msgstr "ID"

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"
38 changes: 38 additions & 0 deletions l10n_it_amount_to_text/i18n/l10n_it_amount_to_text.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_it_amount_to_text
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-05 21:06+0100\n"
"PO-Revision-Date: 2021-01-05 19:58+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 2.0.6\n"

#. module: l10n_it_amount_to_text
#: model:ir.model,name:l10n_it_amount_to_text.model_res_currency
msgid "Currency"
msgstr ""

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency__display_name
msgid "Display Name"
msgstr ""

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency__id
msgid "ID"
msgstr ""

#. module: l10n_it_amount_to_text
#: model:ir.model.fields,field_description:l10n_it_amount_to_text.field_res_currency____last_update
msgid "Last Modified on"
msgstr ""
1 change: 1 addition & 0 deletions l10n_it_amount_to_text/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_currency
51 changes: 51 additions & 0 deletions l10n_it_amount_to_text/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th)
# Copyright 2022 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from num2words import num2words

from odoo import models, tools


class Currency(models.Model):
_inherit = "res.currency"

def amount_to_text(self, amount):
self.ensure_one()
lang = tools.get_lang(self.env)
lang_code = lang.code
if lang_code != "it_IT":
return super().amount_to_text(amount)

def _num2words(number, lang):
try:
return num2words(number, lang=lang)
except NotImplementedError:
return num2words(number, lang="en")

formatted_amount = "%.{}f".format(self.decimal_places) % amount
parts = formatted_amount.partition(".")
integer_value = int(parts[0])
fractional_value = int(parts[2] or 0)

# use num2words native 'currency' option to handle exceptions.
# eg. 'uno euro' -> 'un euro', 'uno centesimi' -> 'un centesimo'"""
try:
return num2words(
formatted_amount, to="currency", lang=lang.iso_code, currency=self.name
)
except NotImplementedError:
amount_words = tools.ustr("{amt_value} {amt_word}").format(
amt_value=_num2words(integer_value, lang=lang.iso_code),
amt_word=self.currency_unit_label.lower(),
)
if not self.is_zero(amount - integer_value):
amount_words += (
" "
+ "e"
+ tools.ustr(" {amt_value} {amt_word}").format(
amt_value=_num2words(fractional_value, lang=lang.iso_code),
amt_word=self.currency_subunit_label.lower(),
)
)
return amount_words
7 changes: 7 additions & 0 deletions l10n_it_amount_to_text/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Italiano**

Versione libreria ``num2words`` >= 0.5.12

**English**

``num2words`` library version >= 0.5.12
3 changes: 3 additions & 0 deletions l10n_it_amount_to_text/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Saran Lim. <[email protected]>
* Pimolnat Suntian <[email protected]>
* Sergio Zanchetta <https://github.com/primes2h>
39 changes: 39 additions & 0 deletions l10n_it_amount_to_text/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
**Italiano**

Il core di Odoo fornisce ``amount_to_text``, il quale converte importi numerici in testo ottenendo la lingua dal contesto fornito o dalle impostazioni utente/partner, con alcune limitazioni.

Esempio: 45,75 €

* Lingua utente "Inglese" → Forty-Five Euros and Seventy-Five Cents
* Lingua utente "Italiano" → Quarantacinque Euros e Settantacinque Cents

L'unità/sottounità di valuta non viene tradotta e non viene gestita la forma singolare. Inoltre tutte le parole possiedono l'iniziale maiuscola, forma non corretta nella lingua italiana.

Questo modulo fornisce una base per tradurre le unità/sottounità di valuta, adattando le parole alle regole della lingua italiana.

Vengono inoltre gestite le eccezioni per la forma singolare delle valute EUR, USD, GBP e CNY.

Esempio: 1,01 €

* La parte intera diventa "un euro", non "uno euro"
* La parte decimale diventa "un centesimo", non "uno centesimi"

**English**

Odoo core provides ``amount_to_text``, which converts numerical amounts to text getting language from given context or user/partner setting, with some limitations.

Example: 45,75 €

* User Language 'English' -> Forty-Five Euros and Seventy-Five Cents
* User Language 'Italian' -> Quaranta Euros e Settantacinque Cents

Currency unit/subunit is not translated and singular form is not handled. Moreover all words are capitalized, which is incorrect in italian language.

This module provides a base for translating currency unit/subunit adapting words to italian language rules.

Singular form expections for EUR, USD, GBP and CNY currencies are handled as well.

Example: 1,01 €

* Integer part becomes "un euro", not "uno euro"
* Decimal part becomes "un centesimo", not "uno centesimi"
Loading

0 comments on commit a068cc9

Please sign in to comment.