Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions report_qweb_field_option/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. 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
========================
Expand All @@ -17,7 +13,7 @@ Report Qweb Field Option
.. |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
.. |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%2Freporting--engine-lightgray.png?logo=github
Expand Down Expand Up @@ -49,15 +45,18 @@ 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
- Set **Model** and **Field** (required)
- Set **UoM** and **UoM Field**, or **Currency** and **Currency Field**
only for fields of float type (optional)
- Set **Additional Conditions** to specify a domain for more specific
filtering (e.g., ``[('secondary_uom_id', '=', 1)]`` to apply only
when a specific secondary UoM is used) (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
=====
Expand Down Expand Up @@ -115,10 +114,10 @@ Authors
Contributors
------------

- `Quartile <https://www.quartile.co>`__:
- `Quartile <https://www.quartile.co>`__:

- Yoshi Tashiro
- Aung Ko Ko Lin
- Yoshi Tashiro
- Aung Ko Ko Lin

Maintainers
-----------
Expand Down
151 changes: 151 additions & 0 deletions report_qweb_field_option/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -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: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=1; plural=0;\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 ""
51 changes: 50 additions & 1 deletion report_qweb_field_option/models/qweb_field_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import ast
import logging

from odoo import _, api, fields, models
from odoo import _, api, fields, models, tools
from odoo.exceptions import ValidationError
from odoo.osv.expression import normalize_domain
from odoo.tools.safe_eval import safe_eval

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,6 +54,15 @@ class QwebFieldOptions(models.Model):
)
digits = fields.Integer()
company_id = fields.Many2one("res.company", string="Company")
domain = fields.Char(
"Additional Conditions",
help="Optional domain for additional filtering conditions.\n"
"This is evaluated in addition to UoM/Currency conditions.\n"
"Examples:\n"
"[('secondary_uom_id', '=', 1)]\n"
"[('secondary_uom_id.name', '=', 'Box')]\n"
"[('state', 'in', ['sale', 'done'])]",
)

@api.constrains("field_options")
def _check_field_options_format(self):
Expand All @@ -74,6 +85,28 @@ def _check_field_options_format(self):
_("Options must be a dictionary, but got %s") % type(field_options)
)

def _get_eval_context(self):
return {
"time": tools.safe_eval.time,
"datetime": tools.safe_eval.datetime,
"dateutil": tools.safe_eval.dateutil,
"timezone": tools.safe_eval.pytz.timezone,
"context_today": lambda: fields.Date.context_today(self),
}

@api.constrains("domain")
def _check_domain_format(self):
for rec in self:
if not rec.domain:
continue
try:
normalize_domain(safe_eval(rec.domain, rec._get_eval_context()))
except Exception as e:
raise ValidationError(
_("Invalid domain format: %(domain)s.\n" "Error: %(error)s")
% {"domain": rec.domain, "error": e}
) from e

def _get_score(self, record):
self.ensure_one()
score = 1
Expand All @@ -91,6 +124,22 @@ def _get_score(self, record):
score += 1
else:
return -1
if self.domain:
try:
domain = normalize_domain(
safe_eval(self.domain, self._get_eval_context())
)
if not record.filtered_domain(domain):
return -1
score += 1
except Exception as e:
_logger.warning(
"Failed to evaluate domain %s for record %s: %s",
self.domain,
record,
e,
)
return -1
return score

def _update_field_options(self, record, field_options):
Expand Down
3 changes: 3 additions & 0 deletions report_qweb_field_option/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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 **Additional Conditions** to specify a domain for more specific
filtering (e.g., `[('secondary_uom_id', '=', 1)]` to apply only when
a specific secondary UoM is used) (optional)
- Set **Company** (optional)
- Set **Options** as a string representation of a dictionary. E.g.,
`{"widget": "date"}`, `{"widget": "monetary"}`, or
Expand Down
Loading
Loading