diff --git a/report_qweb_field_option/README.rst b/report_qweb_field_option/README.rst new file mode 100644 index 0000000000..c23713d6b5 --- /dev/null +++ b/report_qweb_field_option/README.rst @@ -0,0 +1,138 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================== +Report Qweb Field Option +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6a839e0b8361541500cea7946ac9d7bfbcbe37ab2a102576061a2940c4343c5c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Freporting--engine-lightgray.png?logo=github + :target: https://github.com/OCA/reporting-engine/tree/19.0/report_qweb_field_option + :alt: OCA/reporting-engine +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/reporting-engine-19-0/reporting-engine-19-0-report_qweb_field_option + :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/reporting-engine&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows administrators to define the decimal precision of +float fields and add option values to fields (e.g., adding a date widget +option to datetime fields) for QWeb report and view presentation. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to *Settings > Technical > Reporting > Qweb Field Options*, and +create records according to your needs. + +For each record: + +- Set **Model** and **Field** (required) +- Set **UoM** and **UoM Field**, or **Currency** and **Currency Field** + only for fields of float type (optional) +- Set **Company** (optional) +- Set **Options** as a string representation of a dictionary. E.g., + ``{"widget": "date"}``, ``{"widget": "monetary"}``, or + ``{"widget": "contact", "fields": ["name", "phone"]}`` +- Set **Digits** (only for float-type fields). The value is ignored if + Options is set + +Usage +===== + +Print a QWeb report (quotation, invoice, purchase order, etc.), and the +value presentation for fields like line quantity, price unit and date +order are adjusted according to the Qweb Field Options configuration. + +Note that among matching configuration records, the one with the +strictest condition will be applied. + +Known issues / Roadmap +====================== + +| #. QWeb field option settings only apply to fields rendered with + ``t-field``. +| They don’t work with ``t-esc`` or other expressions not using + ``t-field``. + +As a workaround, you could create a module that adds a computed field +holding the same value currently computed and displayed in the QWeb +report using ``t-esc``, and adjust the report template to display the +field value using ``t-field``. This would allow you to adjust the +decimal precision as needed. + +#. Assigning Options in a QWeb Field Options record can cause UI issues +if a field is defined twice with different widgets in a view. + +For example, adding ``{"widget": "date"}`` to the date_approve field in +a purchase order can result in two dates appearing under the +Confirmation Date column in the portal view. This occurs because the +field is defined twice with different widgets. + +Reference: +https://github.com/odoo/odoo/blob/5eec379/addons/purchase/views/portal_templates.xml#L101-L102 + +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 +------- + +* Quartile + +Contributors +------------ + +- `Quartile `__: + + - Yoshi Tashiro + - Aung Ko Ko Lin + +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/reporting-engine `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/report_qweb_field_option/__init__.py b/report_qweb_field_option/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/report_qweb_field_option/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/report_qweb_field_option/__manifest__.py b/report_qweb_field_option/__manifest__.py new file mode 100644 index 0000000000..f0f6061730 --- /dev/null +++ b/report_qweb_field_option/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024-2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Report Qweb Field Option", + "version": "19.0.1.0.0", + "category": "Technical Settings", + "license": "AGPL-3", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine", + "depends": ["uom"], + "data": [ + "security/ir.model.access.csv", + "security/qweb_field_options_security.xml", + "views/qweb_field_options_views.xml", + ], + "installable": True, +} diff --git a/report_qweb_field_option/i18n/it.po b/report_qweb_field_option/i18n/it.po new file mode 100644 index 0000000000..9db58d4b83 --- /dev/null +++ b/report_qweb_field_option/i18n/it.po @@ -0,0 +1,167 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_field_option +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-03-30 21:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.2\n" + +#. module: report_qweb_field_option +#: model:ir.model.fields,help:report_qweb_field_option.field_qweb_field_options__field_options +msgid "" +"A string representation of a dictionary to specify field formatting options. Examples:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" +msgstr "" +"Una stringa che rappresenta un dizionario per indicare le opzioni di " +"formattazione dei campi. Esempi:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__company_id +msgid "Company" +msgstr "Azienda" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_uid +msgid "Created by" +msgstr "Creato da" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_date +msgid "Created on" +msgstr "Creato il" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_id +msgid "Currency" +msgstr "Valuta" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_field_id +msgid "Currency Field" +msgstr "Campo valuta" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__digits +msgid "Digits" +msgstr "Cifre" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_id +msgid "Field" +msgstr "Campo" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_name +msgid "Field Name" +msgstr "Nome campo" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_type +msgid "Field Type" +msgstr "Tipo campo" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Group By" +msgstr "Raggruppa per" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__id +msgid "ID" +msgstr "ID" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +#, python-format +msgid "" +"Invalid string for the Options field: %(field_options)s.\n" +"Error: %(error)s" +msgstr "" +"Stringa non valida per il campo opzioni: %(field_options)s.\n" +"Errore: %(error)s" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_uid +msgid "Last Updated by" +msgstr "Ultimo aggiornamento di" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_date +msgid "Last Updated on" +msgstr "Ultimo aggiornamento il" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_id +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Model" +msgstr "Modello" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_name +msgid "Model Name" +msgstr "Nome modello" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_options +msgid "Options" +msgstr "Opzioni" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +#, python-format +msgid "Options must be a dictionary, but got %s" +msgstr "Le opzioni devono essere un dizionario, ma sono %s" + +#. module: report_qweb_field_option +#: model:ir.model,name:report_qweb_field_option.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" + +#. module: report_qweb_field_option +#: model:ir.actions.act_window,name:report_qweb_field_option.action_qweb_field_options_view +#: model:ir.model,name:report_qweb_field_option.model_qweb_field_options +#: model:ir.ui.menu,name:report_qweb_field_option.menu_qweb_field_options +msgid "Qweb Field Options" +msgstr "Opzioni campo Qweb" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Qweb Field Options Search" +msgstr "Ricerca opzioni campo Qweb" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_id +msgid "UoM" +msgstr "UdM" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_field_id +msgid "UoM Field" +msgstr "Campo UdM" diff --git a/report_qweb_field_option/i18n/nl.po b/report_qweb_field_option/i18n/nl.po new file mode 100644 index 0000000000..9df525e55a --- /dev/null +++ b/report_qweb_field_option/i18n/nl.po @@ -0,0 +1,151 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_field_option +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: report_qweb_field_option +#: model:ir.model.fields,help:report_qweb_field_option.field_qweb_field_options__field_options +msgid "" +"A string representation of a dictionary to specify field formatting options. Examples:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__company_id +msgid "Company" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_uid +msgid "Created by" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_date +msgid "Created on" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_id +msgid "Currency" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_field_id +msgid "Currency Field" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__digits +msgid "Digits" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__display_name +msgid "Display Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_id +msgid "Field" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_name +msgid "Field Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_type +msgid "Field Type" +msgstr "" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Group By" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__id +msgid "ID" +msgstr "" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "" +"Invalid string for the Options field: %(field_options)s.\n" +"Error: %(error)s" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_date +msgid "Last Updated on" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_id +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Model" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_name +msgid "Model Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_options +msgid "Options" +msgstr "" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "Options must be a dictionary, but got %s" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model,name:report_qweb_field_option.model_ir_qweb +msgid "Qweb" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.actions.act_window,name:report_qweb_field_option.action_qweb_field_options_view +#: model:ir.model,name:report_qweb_field_option.model_qweb_field_options +#: model:ir.ui.menu,name:report_qweb_field_option.menu_qweb_field_options +msgid "Qweb Field Options" +msgstr "" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Qweb Field Options Search" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_id +msgid "UoM" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_field_id +msgid "UoM Field" +msgstr "" diff --git a/report_qweb_field_option/i18n/nl_NL.po b/report_qweb_field_option/i18n/nl_NL.po new file mode 100644 index 0000000000..c6e2604734 --- /dev/null +++ b/report_qweb_field_option/i18n/nl_NL.po @@ -0,0 +1,160 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_field_option +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-09-11 09:42+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: report_qweb_field_option +#: model:ir.model.fields,help:report_qweb_field_option.field_qweb_field_options__field_options +msgid "" +"A string representation of a dictionary to specify field formatting options. Examples:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" +msgstr "" +"Een stringweergave van een woordenboek om veldopmaakopties te specificeren. " +"Voorbeelden:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__company_id +msgid "Company" +msgstr "Bedrijf" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_uid +msgid "Created by" +msgstr "Aangemaakt door" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_date +msgid "Created on" +msgstr "Aangemaakt op" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_id +msgid "Currency" +msgstr "Valuta" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_field_id +msgid "Currency Field" +msgstr "Valutaveld" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__digits +msgid "Digits" +msgstr "Cijfers" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__display_name +msgid "Display Name" +msgstr "Weergavenaam" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_id +msgid "Field" +msgstr "Veld" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_name +msgid "Field Name" +msgstr "Veldnaam" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_type +msgid "Field Type" +msgstr "Veldtype" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Group By" +msgstr "Groeperen op" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__id +msgid "ID" +msgstr "ID" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "" +"Invalid string for the Options field: %(field_options)s.\n" +"Error: %(error)s" +msgstr "" +"Ongeldige string voor het veld Opties: %(field_options)s.\n" +"Fout: %(error)s" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_uid +msgid "Last Updated by" +msgstr "Laatst bijgewerkt door" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_date +msgid "Last Updated on" +msgstr "Laatst bijgewerkt op" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_id +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Model" +msgstr "Model" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_name +msgid "Model Name" +msgstr "Modelnaam" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_options +msgid "Options" +msgstr "Opties" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "Options must be a dictionary, but got %s" +msgstr "Opties moeten een woordenboek zijn, maar kregen %s" + +#. module: report_qweb_field_option +#: model:ir.model,name:report_qweb_field_option.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" + +#. module: report_qweb_field_option +#: model:ir.actions.act_window,name:report_qweb_field_option.action_qweb_field_options_view +#: model:ir.model,name:report_qweb_field_option.model_qweb_field_options +#: model:ir.ui.menu,name:report_qweb_field_option.menu_qweb_field_options +msgid "Qweb Field Options" +msgstr "Qweb Veldopties" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Qweb Field Options Search" +msgstr "Zoeken in Qweb Veldopties" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_id +msgid "UoM" +msgstr "Eenheid" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_field_id +msgid "UoM Field" +msgstr "Eenheid Veld" diff --git a/report_qweb_field_option/i18n/report_qweb_field_option.pot b/report_qweb_field_option/i18n/report_qweb_field_option.pot new file mode 100644 index 0000000000..7dd2a3f640 --- /dev/null +++ b/report_qweb_field_option/i18n/report_qweb_field_option.pot @@ -0,0 +1,150 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_qweb_field_option +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: report_qweb_field_option +#: model:ir.model.fields,help:report_qweb_field_option.field_qweb_field_options__field_options +msgid "" +"A string representation of a dictionary to specify field formatting options. Examples:\n" +"{'widget': 'date'}\n" +"{'widget': 'monetary'}\n" +"{'widget': 'contact', 'fields': ['name', 'phone']}" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__company_id +msgid "Company" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_uid +msgid "Created by" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__create_date +msgid "Created on" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_id +msgid "Currency" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__currency_field_id +msgid "Currency Field" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__digits +msgid "Digits" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__display_name +msgid "Display Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_id +msgid "Field" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_name +msgid "Field Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_type +msgid "Field Type" +msgstr "" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Group By" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__id +msgid "ID" +msgstr "" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "" +"Invalid string for the Options field: %(field_options)s.\n" +"Error: %(error)s" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__write_date +msgid "Last Updated on" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_id +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Model" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__res_model_name +msgid "Model Name" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__field_options +msgid "Options" +msgstr "" + +#. module: report_qweb_field_option +#. odoo-python +#: code:addons/report_qweb_field_option/models/qweb_field_options.py:0 +msgid "Options must be a dictionary, but got %s" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model,name:report_qweb_field_option.model_ir_qweb +msgid "Qweb" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.actions.act_window,name:report_qweb_field_option.action_qweb_field_options_view +#: model:ir.model,name:report_qweb_field_option.model_qweb_field_options +#: model:ir.ui.menu,name:report_qweb_field_option.menu_qweb_field_options +msgid "Qweb Field Options" +msgstr "" + +#. module: report_qweb_field_option +#: model_terms:ir.ui.view,arch_db:report_qweb_field_option.view_qweb_field_options_searh +msgid "Qweb Field Options Search" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_id +msgid "UoM" +msgstr "" + +#. module: report_qweb_field_option +#: model:ir.model.fields,field_description:report_qweb_field_option.field_qweb_field_options__uom_field_id +msgid "UoM Field" +msgstr "" diff --git a/report_qweb_field_option/models/__init__.py b/report_qweb_field_option/models/__init__.py new file mode 100644 index 0000000000..0d0c2c02f0 --- /dev/null +++ b/report_qweb_field_option/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_qweb +from . import qweb_field_options diff --git a/report_qweb_field_option/models/ir_qweb.py b/report_qweb_field_option/models/ir_qweb.py new file mode 100644 index 0000000000..b37b903358 --- /dev/null +++ b/report_qweb_field_option/models/ir_qweb.py @@ -0,0 +1,33 @@ +# Copyright 2024-2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class IrQweb(models.AbstractModel): + _inherit = "ir.qweb" + + @api.model + def _get_field( + self, record, field_name, expression, tagName, field_options, values + ): + if values.get("report_type") == "pdf": + company = getattr(record, "company_id", False) or self.env.company + options_recs = self.env["qweb.field.options"].search( + [ + ("res_model_name", "=", record._name), + ("field_name", "=", field_name), + "|", + ("company_id", "=", company.id), + ("company_id", "=", False), + ] + ) + options_recs = [r for r in options_recs if r._get_score(record) > 0] + if options_recs: + options_rec = max( + options_recs, default=None, key=lambda r: r._get_score(record) + ) + field_options = options_rec._update_field_options(record, field_options) + return super()._get_field( + record, field_name, expression, tagName, field_options, values + ) diff --git a/report_qweb_field_option/models/qweb_field_options.py b/report_qweb_field_option/models/qweb_field_options.py new file mode 100644 index 0000000000..ca1fb3216b --- /dev/null +++ b/report_qweb_field_option/models/qweb_field_options.py @@ -0,0 +1,119 @@ +# Copyright 2024-2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import ast +import logging + +from odoo import api, fields, models +from odoo.exceptions import ValidationError + +_logger = logging.getLogger(__name__) + + +class QwebFieldOptions(models.Model): + _name = "qweb.field.options" + _description = "Qweb Field Options" + _order = "res_model_id, field_id" + + res_model_id = fields.Many2one( + "ir.model", string="Model", ondelete="cascade", required=True + ) + res_model_name = fields.Char("Model Name", related="res_model_id.model", store=True) + field_id = fields.Many2one( + "ir.model.fields", + domain="[('model_id', '=', res_model_id)]", + string="Field", + ondelete="cascade", + required=True, + ) + field_type = fields.Selection(related="field_id.ttype") + field_name = fields.Char("Field Name", related="field_id.name", store=True) + uom_id = fields.Many2one("uom.uom", string="UoM", ondelete="cascade") + uom_field_id = fields.Many2one( + "ir.model.fields", + domain="[('model_id', '=', res_model_id), ('relation', '=', 'uom.uom')]", + string="UoM Field", + ondelete="cascade", + ) + currency_id = fields.Many2one("res.currency", string="Currency", ondelete="cascade") + currency_field_id = fields.Many2one( + "ir.model.fields", + domain="[('model_id', '=', res_model_id), ('relation', '=', 'res.currency')]", + string="Currency Field", + ondelete="cascade", + ) + field_options = fields.Char( + "Options", + help="A string representation of a dictionary to specify field formatting " + "options. Examples:\n" + "{'widget': 'date'}\n" + "{'widget': 'monetary'}\n" + "{'widget': 'contact', 'fields': ['name', 'phone']}", + ) + digits = fields.Integer() + company_id = fields.Many2one("res.company", string="Company") + + @api.constrains("field_options") + def _check_field_options_format(self): + for rec in self: + if not rec.field_options: + continue + field_options = False + try: + field_options = ast.literal_eval(rec.field_options) + except Exception as e: + raise ValidationError( + self.env._( + "Invalid string for the Options field: %(field_options)s.\n" + "Error: %(error)s", + field_options=rec.field_options, + error=e, + ) + ) from e + if not isinstance(field_options, dict): + raise ValidationError( + self.env._( + "Options must be a dictionary, but got %s", type(field_options) + ) + ) + + def _get_score(self, record): + self.ensure_one() + score = 1 + # Just increment the score as the record already matches the company_id, + # which has been filtered prior to calling this method. + if self.company_id: + score += 1 + if self.uom_id: + if record[self.uom_field_id.sudo().name] == self.uom_id: + score += 1 + else: + return -1 + if self.currency_id: + if record[self.currency_field_id.sudo().name] == self.currency_id: + score += 1 + else: + return -1 + return score + + def _update_field_options(self, record, field_options): + self.ensure_one() + if self.field_options: + try: + extra_options = ast.literal_eval(self.field_options) + if extra_options.get("widget") == "monetary": + extra_options["display_currency"] = ( + self.currency_id + or hasattr(record, "company_id") + and record.company_id.currency_id + or self.env.company.currency_id + ) + field_options.update(extra_options) + except Exception as e: + _logger.error( + "Failed to parse field options as a dictionary: " + f"{self.field_options}. Error: {e}" + ) + elif self.field_type == "float": + field_options["precision"] = self.digits + return field_options diff --git a/report_qweb_field_option/pyproject.toml b/report_qweb_field_option/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/report_qweb_field_option/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/report_qweb_field_option/readme/CONFIGURE.md b/report_qweb_field_option/readme/CONFIGURE.md new file mode 100644 index 0000000000..e8532ad73a --- /dev/null +++ b/report_qweb_field_option/readme/CONFIGURE.md @@ -0,0 +1,14 @@ +Go to *Settings \> Technical \> Reporting \> Qweb Field Options*, and +create records according to your needs. + +For each record: + +- Set **Model** and **Field** (required) +- Set **UoM** and **UoM Field**, or **Currency** and **Currency Field** + only for fields of float type (optional) +- Set **Company** (optional) +- Set **Options** as a string representation of a dictionary. E.g., + `{"widget": "date"}`, `{"widget": "monetary"}`, or + `{"widget": "contact", "fields": ["name", "phone"]}` +- Set **Digits** (only for float-type fields). The value is ignored if + Options is set diff --git a/report_qweb_field_option/readme/CONTRIBUTORS.md b/report_qweb_field_option/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..4d16bdc25a --- /dev/null +++ b/report_qweb_field_option/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Quartile](https://www.quartile.co): + - Yoshi Tashiro + - Aung Ko Ko Lin diff --git a/report_qweb_field_option/readme/DESCRIPTION.md b/report_qweb_field_option/readme/DESCRIPTION.md new file mode 100644 index 0000000000..52521f23fd --- /dev/null +++ b/report_qweb_field_option/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows administrators to define the decimal precision of +float fields and add option values to fields (e.g., adding a date widget +option to datetime fields) for QWeb report and view presentation. diff --git a/report_qweb_field_option/readme/ROADMAP.md b/report_qweb_field_option/readme/ROADMAP.md new file mode 100644 index 0000000000..94caec7c82 --- /dev/null +++ b/report_qweb_field_option/readme/ROADMAP.md @@ -0,0 +1,17 @@ +#. QWeb field option settings only apply to fields rendered with ``t-field``. + They don’t work with ``t-esc`` or other expressions not using ``t-field``. + + As a workaround, you could create a module that adds a computed field holding the + same value currently computed and displayed in the QWeb report using ``t-esc``, and + adjust the report template to display the field value using ``t-field``. This would + allow you to adjust the decimal precision as needed. + + +#. Assigning Options in a QWeb Field Options record can cause UI issues if a field is + defined twice with different widgets in a view. + + For example, adding ``{"widget": "date"}`` to the date_approve field in a purchase + order can result in two dates appearing under the Confirmation Date column in the + portal view. This occurs because the field is defined twice with different widgets. + + Reference: https://github.com/odoo/odoo/blob/5eec379/addons/purchase/views/portal_templates.xml#L101-L102 \ No newline at end of file diff --git a/report_qweb_field_option/readme/USAGE.md b/report_qweb_field_option/readme/USAGE.md new file mode 100644 index 0000000000..491184a26f --- /dev/null +++ b/report_qweb_field_option/readme/USAGE.md @@ -0,0 +1,6 @@ +Print a QWeb report (quotation, invoice, purchase order, etc.), and the +value presentation for fields like line quantity, price unit and date +order are adjusted according to the Qweb Field Options configuration. + +Note that among matching configuration records, the one with the +strictest condition will be applied. diff --git a/report_qweb_field_option/security/ir.model.access.csv b/report_qweb_field_option/security/ir.model.access.csv new file mode 100644 index 0000000000..8472348b35 --- /dev/null +++ b/report_qweb_field_option/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_qweb_field_options_public,access.qweb.field.options.public,model_qweb_field_options,base.group_public,1,0,0,0 +access_qweb_field_options_portal,access.qweb.field.options.portal,model_qweb_field_options,base.group_portal,1,0,0,0 +access_qweb_field_options_user,access.qweb.field.options.user,model_qweb_field_options,base.group_user,1,0,0,0 +access_qweb_field_options_admin,access.qweb.field.options.admin,model_qweb_field_options,base.group_system,1,1,1,1 diff --git a/report_qweb_field_option/security/qweb_field_options_security.xml b/report_qweb_field_option/security/qweb_field_options_security.xml new file mode 100644 index 0000000000..fa28417209 --- /dev/null +++ b/report_qweb_field_option/security/qweb_field_options_security.xml @@ -0,0 +1,10 @@ + + + + Qweb Field Options Multi-company + + ['|', ('company_id', 'in', company_ids), ('company_id', '=', False)] + + diff --git a/report_qweb_field_option/static/description/icon.png b/report_qweb_field_option/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/report_qweb_field_option/static/description/icon.png differ diff --git a/report_qweb_field_option/static/description/index.html b/report_qweb_field_option/static/description/index.html new file mode 100644 index 0000000000..7bca445033 --- /dev/null +++ b/report_qweb_field_option/static/description/index.html @@ -0,0 +1,485 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Report Qweb Field Option

+ +

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

+

This module allows administrators to define the decimal precision of +float fields and add option values to fields (e.g., adding a date widget +option to datetime fields) for QWeb report and view presentation.

+

Table of contents

+ +
+

Configuration

+

Go to Settings > Technical > Reporting > Qweb Field Options, and +create records according to your needs.

+

For each record:

+
    +
  • Set Model and Field (required)
  • +
  • Set UoM and UoM Field, or Currency and Currency Field +only for fields of float type (optional)
  • +
  • Set Company (optional)
  • +
  • Set Options as a string representation of a dictionary. E.g., +{"widget": "date"}, {"widget": "monetary"}, or +{"widget": "contact", "fields": ["name", "phone"]}
  • +
  • Set Digits (only for float-type fields). The value is ignored if +Options is set
  • +
+
+
+

Usage

+

Print a QWeb report (quotation, invoice, purchase order, etc.), and the +value presentation for fields like line quantity, price unit and date +order are adjusted according to the Qweb Field Options configuration.

+

Note that among matching configuration records, the one with the +strictest condition will be applied.

+
+
+

Known issues / Roadmap

+
+
#. QWeb field option settings only apply to fields rendered with +t-field.
+
They don’t work with t-esc or other expressions not using +t-field.
+
+

As a workaround, you could create a module that adds a computed field +holding the same value currently computed and displayed in the QWeb +report using t-esc, and adjust the report template to display the +field value using t-field. This would allow you to adjust the +decimal precision as needed.

+

#. Assigning Options in a QWeb Field Options record can cause UI issues +if a field is defined twice with different widgets in a view.

+

For example, adding {"widget": "date"} to the date_approve field in +a purchase order can result in two dates appearing under the +Confirmation Date column in the portal view. This occurs because the +field is defined twice with different widgets.

+

Reference: +https://github.com/odoo/odoo/blob/5eec379/addons/purchase/views/portal_templates.xml#L101-L102

+
+
+

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

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile:
      +
    • Yoshi Tashiro
    • +
    • Aung Ko Ko Lin
    • +
    +
  • +
+
+
+

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

+

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

+
+
+
+
+ + diff --git a/report_qweb_field_option/tests/__init__.py b/report_qweb_field_option/tests/__init__.py new file mode 100644 index 0000000000..0c4db8b9c1 --- /dev/null +++ b/report_qweb_field_option/tests/__init__.py @@ -0,0 +1 @@ +from . import test_report_qweb_field_options diff --git a/report_qweb_field_option/tests/test_models.py b/report_qweb_field_option/tests/test_models.py new file mode 100644 index 0000000000..521131845c --- /dev/null +++ b/report_qweb_field_option/tests/test_models.py @@ -0,0 +1,15 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class TestQwebFieldModel(models.Model): + _name = "test.qweb.field.options" + _description = "Test Qweb Field Options" + + name = fields.Char() + quantity = fields.Float() + uom_id = fields.Many2one("uom.uom") + value = fields.Float(string="Rounding Factor") + currency_id = fields.Many2one("res.currency") + company_id = fields.Many2one("res.company") diff --git a/report_qweb_field_option/tests/test_report_qweb_field_options.py b/report_qweb_field_option/tests/test_report_qweb_field_options.py new file mode 100644 index 0000000000..83931f69c1 --- /dev/null +++ b/report_qweb_field_option/tests/test_report_qweb_field_options.py @@ -0,0 +1,150 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.orm.model_classes import add_to_registry +from odoo.tests.common import TransactionCase + + +class TestQwebFieldOptions(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + from .test_models import TestQwebFieldModel + + add_to_registry(cls.registry, TestQwebFieldModel) + cls.registry._setup_models__(cls.env.cr, ["test.qweb.field.options"]) + cls.registry.init_models( + cls.env.cr, ["test.qweb.field.options"], {"models_to_check": True} + ) + cls.addClassCleanup(cls.registry.__delitem__, "test.qweb.field.options") + cls.test_model = cls.env["ir.model"]._get("test.qweb.field.options") + cls.quantity_field = cls.env["ir.model.fields"]._get( + "test.qweb.field.options", "quantity" + ) + cls.uom_field = cls.env["ir.model.fields"]._get( + "test.qweb.field.options", "uom_id" + ) + cls.value_field = cls.env["ir.model.fields"]._get( + "test.qweb.field.options", "value" + ) + cls.currency_field = cls.env["ir.model.fields"]._get( + "test.qweb.field.options", "currency_id" + ) + cls.IrQweb = cls.env["ir.qweb"] + cls.test_currency = cls.env["res.currency"].create( + {"name": "Test Currency", "symbol": "$"} + ) + cls.unit_uom = cls.env.ref("uom.product_uom_unit") + cls.test_record = cls.env["test.qweb.field.options"].create( + { + "name": "Test", + "quantity": 1.00, + "value": 1.00, + "currency_id": cls.test_currency.id, + "company_id": cls.env.company.id, + } + ) + cls.qweb_options_rec = cls.env["qweb.field.options"].create( + { + "res_model_id": cls.test_model.id, + "field_id": cls.value_field.id, + "currency_id": cls.test_currency.id, + "currency_field_id": cls.currency_field.id, + "digits": 0, + } + ) + cls.env["qweb.field.options"].create( + { + "res_model_id": cls.test_model.id, + "field_id": cls.quantity_field.id, + "uom_id": cls.unit_uom.id, + "uom_field_id": cls.uom_field.id, + "digits": 3, + } + ) + + def test_qweb_field_option(self): + values = {"report_type": "pdf"} + # Test with 0 digits + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertEqual(content, "1") + + # Test with 2 digits + self.qweb_options_rec.digits = 2 + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertEqual(content, "1.00") + + # Test with 3 digits + self.qweb_options_rec.digits = 3 + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertEqual(content, "1.000") + + # Test with widget + self.qweb_options_rec.field_options = "{'widget': 'monetary'}" + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertIn("$", content) + + # Test that an error is raised when the input value is incorrect. + with self.assertRaises(ValidationError): + self.qweb_options_rec.field_options = ( + "{'widget': 'monetary', 'currency_field': self.test_record}" + ) + + with self.assertRaises(ValidationError): + self.qweb_options_rec.field_options = "'widget': 'monetary'" + + def test_qweb_field_option_with_multiple_record(self): + values = {"report_type": "pdf"} + qweb_options_company_rec = self.env["qweb.field.options"].create( + { + "res_model_id": self.test_model.id, + "field_id": self.value_field.id, + "currency_id": self.test_currency.id, + "currency_field_id": self.currency_field.id, + "company_id": self.env.company.id, + "digits": 1, + } + ) + + # If there are two records, one with and one without a company, + # it should prioritize the record with the company_id + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertEqual(content, "1.0") + + qweb_options_company_rec.field_options = "{'widget': 'monetary'}" + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertIn("$", content) + + # Test after unlinking the options record + qweb_options_company_rec.unlink() + _, content, _ = self.IrQweb._get_field( + self.test_record, "value", False, False, {}, values + ) + self.assertNotEqual(content, "1.0") + self.assertNotIn("$", content) + + def test_qweb_field_option_with_uom(self): + values = {"report_type": "pdf"} + self.test_record.uom_id = self.unit_uom.id + _, content, _ = self.IrQweb._get_field( + self.test_record, "quantity", False, False, {}, values + ) + self.assertEqual(content, "1.000") + self.test_record.uom_id = self.env.ref("uom.product_uom_dozen").id + _, content, _ = self.IrQweb._get_field( + self.test_record, "quantity", False, False, {}, values + ) + self.assertEqual(content, "1.0") diff --git a/report_qweb_field_option/views/qweb_field_options_views.xml b/report_qweb_field_option/views/qweb_field_options_views.xml new file mode 100644 index 0000000000..8d9bcddaad --- /dev/null +++ b/report_qweb_field_option/views/qweb_field_options_views.xml @@ -0,0 +1,73 @@ + + + + qweb.field.options.list + qweb.field.options + list + + + + + + + + + + + + + + + + + qweb.field.options.search + qweb.field.options + + + + + + + + + + + + + + + + Qweb Field Options + qweb.field.options + list + + + +