diff --git a/l10n_it_amount_to_text/README.rst b/l10n_it_amount_to_text/README.rst new file mode 100644 index 000000000000..b34c237ae59f --- /dev/null +++ b/l10n_it_amount_to_text/README.rst @@ -0,0 +1,184 @@ +============================================== +ITA - Localizzazione valute per amount_to_text +============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:71bc6284df98f6a3d8ca197c6beb24f1d90dcb5e677e78555dbeda59500686d3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.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-18-0/l10n-italy-18-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=18.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: + +:: + + + + + + + + + + +**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: + +:: + + + + + + + + + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +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. +- Pimolnat Suntian +- 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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_amount_to_text/__init__.py b/l10n_it_amount_to_text/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/l10n_it_amount_to_text/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/l10n_it_amount_to_text/__manifest__.py b/l10n_it_amount_to_text/__manifest__.py new file mode 100644 index 000000000000..5a9c4afc9412 --- /dev/null +++ b/l10n_it_amount_to_text/__manifest__.py @@ -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": "18.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>=0.5.12"]}, + "data": [], + "installable": True, +} diff --git a/l10n_it_amount_to_text/i18n/it.po b/l10n_it_amount_to_text/i18n/it.po new file mode 100644 index 000000000000..872d3bf7e7a2 --- /dev/null +++ b/l10n_it_amount_to_text/i18n/it.po @@ -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" +"Last-Translator: Sergio Zanchetta \n" +"Language-Team: \n" +"Language: it_IT\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" + +#. 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" diff --git a/l10n_it_amount_to_text/i18n/l10n_it_amount_to_text.pot b/l10n_it_amount_to_text/i18n/l10n_it_amount_to_text.pot new file mode 100644 index 000000000000..e9dbdfee87ec --- /dev/null +++ b/l10n_it_amount_to_text/i18n/l10n_it_amount_to_text.pot @@ -0,0 +1,19 @@ +# 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 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_it_amount_to_text +#: model:ir.model,name:l10n_it_amount_to_text.model_res_currency +msgid "Currency" +msgstr "" diff --git a/l10n_it_amount_to_text/models/__init__.py b/l10n_it_amount_to_text/models/__init__.py new file mode 100644 index 000000000000..ea5a680ddcea --- /dev/null +++ b/l10n_it_amount_to_text/models/__init__.py @@ -0,0 +1 @@ +from . import res_currency diff --git a/l10n_it_amount_to_text/models/res_currency.py b/l10n_it_amount_to_text/models/res_currency.py new file mode 100644 index 000000000000..3e415a9b269d --- /dev/null +++ b/l10n_it_amount_to_text/models/res_currency.py @@ -0,0 +1,47 @@ +# 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"%.{self.decimal_places}f" % 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: + num_words = _num2words(integer_value, lang=lang.iso_code) + currency_label = self.currency_unit_label.lower() + amount_words = f"{num_words} {currency_label}" + + if not self.is_zero(amount - integer_value): + fractional_words = _num2words(fractional_value, lang=lang.iso_code) + subunit_label = self.currency_subunit_label.lower() + amount_words += f" e {fractional_words} {subunit_label}" + + return amount_words diff --git a/l10n_it_amount_to_text/pyproject.toml b/l10n_it_amount_to_text/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/l10n_it_amount_to_text/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/l10n_it_amount_to_text/readme/CONFIGURE.md b/l10n_it_amount_to_text/readme/CONFIGURE.md new file mode 100644 index 000000000000..723e83978ead --- /dev/null +++ b/l10n_it_amount_to_text/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +**Italiano** + +Versione libreria `num2words` \>= 0.5.12 + +**English** + +`num2words` library version \>= 0.5.12 diff --git a/l10n_it_amount_to_text/readme/CONTRIBUTORS.md b/l10n_it_amount_to_text/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..5d02966c02fe --- /dev/null +++ b/l10n_it_amount_to_text/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ + - Saran Lim. \<\> + - Pimolnat Suntian \<\> + - Sergio Zanchetta \<\> diff --git a/l10n_it_amount_to_text/readme/DESCRIPTION.md b/l10n_it_amount_to_text/readme/DESCRIPTION.md new file mode 100644 index 000000000000..d8daf9bef2f5 --- /dev/null +++ b/l10n_it_amount_to_text/readme/DESCRIPTION.md @@ -0,0 +1,52 @@ +**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" diff --git a/l10n_it_amount_to_text/readme/USAGE.md b/l10n_it_amount_to_text/readme/USAGE.md new file mode 100644 index 000000000000..06034d9cf529 --- /dev/null +++ b/l10n_it_amount_to_text/readme/USAGE.md @@ -0,0 +1,34 @@ +**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: + + + + + + + + + + +**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: + + + + + + + + + diff --git a/l10n_it_amount_to_text/static/description/icon.png b/l10n_it_amount_to_text/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/l10n_it_amount_to_text/static/description/icon.png differ diff --git a/l10n_it_amount_to_text/static/description/index.html b/l10n_it_amount_to_text/static/description/index.html new file mode 100644 index 000000000000..b5e38dd88337 --- /dev/null +++ b/l10n_it_amount_to_text/static/description/index.html @@ -0,0 +1,512 @@ + + + + + +ITA - Localizzazione valute per amount_to_text + + + +
+

ITA - Localizzazione valute per amount_to_text

+ + +

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

+

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

+ +
+

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-out="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-out="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-out="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-out="currency.amount_to_text(45.75)"/>
+</t>
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Sergio Zanchetta - Associazione PNLug APS
  • +
  • Ecosoft Co. Ltd
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/l10n_it_amount_to_text/tests/__init__.py b/l10n_it_amount_to_text/tests/__init__.py new file mode 100644 index 000000000000..22e0c06be7e6 --- /dev/null +++ b/l10n_it_amount_to_text/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_amount_to_text diff --git a/l10n_it_amount_to_text/tests/test_amount_to_text.py b/l10n_it_amount_to_text/tests/test_amount_to_text.py new file mode 100644 index 000000000000..06a6bd56eb3c --- /dev/null +++ b/l10n_it_amount_to_text/tests/test_amount_to_text.py @@ -0,0 +1,65 @@ +# 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.tests.common import TransactionCase + + +class TestAmountToText(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.env["res.lang"]._activate_lang("it_IT") + + def test_01_currency_it_amount_to_text(self): + """check that amount_to_text correctly converts text + to italian language""" + currency = self.env.ref("base.EUR") + amount = 1050.75 + amount_text_en = currency.amount_to_text(amount) + self.assertEqual( + amount_text_en, "One Thousand And Fifty Euros and Seventy-Five Cents" + ) + amount_text_it = currency.with_context(lang="it_IT").amount_to_text(amount) + num2words(amount, to="currency", lang="it") + self.assertEqual( + amount_text_it, "millecinquanta euro e settantacinque centesimi" + ) + + def test_02_currency_unit_it_amount_to_text(self): + """check that amount_to_text correctly converts currency + unit/subunit to italian language singular form""" + currency = self.env.ref("base.EUR") + amount = 1.01 + amount_text_it_unit = currency.with_context(lang="it_IT").amount_to_text(amount) + self.assertEqual(amount_text_it_unit, "un euro e un centesimo") + + def test_03_currency_usd_amount_to_text(self): + """check that amount_to_text works as expected""" + currency = self.env.ref("base.USD") + amount = 1050.75 + amount_text_usd = currency.amount_to_text(amount) + self.assertEqual( + amount_text_usd, "One Thousand And Fifty Dollars and Seventy-Five Cents" + ) + + def test_04_currency_zero_fractional_value_it_amount_to_text(self): + """check that amount_to_text correctly converts currency + with zero fractional value""" + currency = self.env.ref("base.EUR") + amount = 3.00 + amount_text_it_zero_fractional = currency.with_context( + lang="it_IT" + ).amount_to_text(amount) + self.assertEqual(amount_text_it_zero_fractional, "tre euro e zero centesimi") + + def test_05_currency_aed_amount_to_text(self): + """check that amount_to_text works in italian language + using a currency different from EUR/USD/GBP/CNY""" + currency = self.env.ref("base.AED") + amount = 1050.75 + amount_text_aed = currency.with_context(lang="it_IT").amount_to_text(amount) + self.assertEqual(amount_text_aed, "millecinquanta dirham e settantacinque fils") diff --git a/requirements.txt b/requirements.txt index d1d1ac5a796d..178abf294635 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ # generated from manifests external_dependencies codicefiscale +num2words>=0.5.12 openupgradelib unidecode