-
-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][ADD] report_qweb_field_converter #857
Open
AungKoKoLin1997
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
qrtl:16.0-add-report_qweb_field_converter
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
=========================== | ||
Report Qweb Field Converter | ||
=========================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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%2Freporting--engine-lightgray.png?logo=github | ||
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_field_converter | ||
: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-16-0/reporting-engine-16-0-report_qweb_field_converter | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/143/16.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows administrators to define the decimal precision of float fields and to | ||
add option values for fields (e.g., adding a date widget option for datetime fields) for | ||
QWeb report presentation. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
Go to Settings > Technical > Reporting > Qweb Field Converter, and create records | ||
according to your needs. | ||
|
||
For each record: | ||
|
||
- choose a model and a field (required) | ||
- set UoM and UoM Field, or Currency and Currency Field for only float-type field | ||
(optional) | ||
- Set options: Add the options for your fields in JSON format (e.g. {"widget": "date"}). | ||
- set Company (optional) | ||
- set Digits (required for only float-type field) | ||
|
||
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 Converter configuration. | ||
|
||
Note that among matching config records, the one with the strictest condition will be | ||
adopted. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_field_converter%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* Quartile Limited | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
- [Quartile Limited](https://www.quartile.co): | ||
- 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 <https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_field_converter>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2024 Quartile Limited (https://www.quartile.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Report Qweb Field Converter", | ||
"version": "16.0.1.0.0", | ||
"category": "Technical Settings", | ||
"license": "AGPL-3", | ||
"author": "Quartile Limited, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/reporting-engine", | ||
"depends": ["uom"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"security/qweb_field_converter_security.xml", | ||
"views/qweb_field_converter_views.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import qweb_field_converter | ||
from . import ir_qweb_fields | ||
from . import ir_qweb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2024 Quartile Limited (https://www.quartile.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
import logging | ||
|
||
from odoo import api, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class IrQweb(models.AbstractModel): | ||
_inherit = "ir.qweb" | ||
|
||
@api.model | ||
def _get_field( | ||
self, record, field_name, expression, tagName, field_options, values | ||
): | ||
report_type = values.get("report_type") | ||
if not report_type or report_type != "pdf": | ||
return super()._get_field( | ||
record, field_name, expression, tagName, field_options, values | ||
) | ||
qweb_recs = self.env["qweb.field.converter"].search( | ||
[("res_model_name", "=", record._name), ("field_name", "=", field_name)] | ||
) | ||
options_rec = max(qweb_recs, default=None, key=lambda r: r._get_score(record)) | ||
if options_rec and options_rec.field_options: | ||
try: | ||
additional_options = json.loads(options_rec.field_options) | ||
field_options.update(additional_options) | ||
except json.JSONDecodeError as e: | ||
_logger.error(f"JSON decoding error for field options: {e}") | ||
return super()._get_field( | ||
record, field_name, expression, tagName, field_options, values | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 Quartile Limited (https://www.quartile.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class FloatConverter(models.AbstractModel): | ||
_inherit = "ir.qweb.field.float" | ||
|
||
@api.model | ||
def record_to_html(self, record, field_name, options): | ||
if "precision" not in options and "decimal_precision" not in options: | ||
qweb_recs = self.env["qweb.field.converter"].search( | ||
[("res_model_name", "=", record._name), ("field_name", "=", field_name)] | ||
) | ||
precision_rec = max( | ||
qweb_recs, default=None, key=lambda r: r._get_score(record) | ||
) | ||
if precision_rec: | ||
options = dict(options, precision=precision_rec.digits) | ||
return super().record_to_html(record, field_name, options) |
63 changes: 63 additions & 0 deletions
63
report_qweb_field_converter/models/qweb_field_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright 2024 Quartile Limited (https://www.quartile.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class QwebFieldConverter(models.Model): | ||
_name = "qweb.field.converter" | ||
_description = "Qweb Field Converter" | ||
_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", store=True) | ||
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.Text( | ||
"Options", help="JSON-formatted string to specify field formatting options" | ||
) | ||
digits = fields.Integer() | ||
company_id = fields.Many2one("res.company", string="Company") | ||
|
||
def _get_score(self, record): | ||
self.ensure_one() | ||
score = 1 | ||
if self.company_id: | ||
if record.company_id == self.company_id: | ||
score += 1 | ||
else: | ||
return -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Go to Settings > Technical > Reporting > Qweb Field Converter, and create records | ||
according to your needs. | ||
|
||
For each record: | ||
|
||
- choose a model and a field (required) | ||
- set UoM and UoM Field, or Currency and Currency Field for only float-type field | ||
(optional) | ||
- set Options: Add the options for your fields in JSON format (e.g. {"widget": "date"}). | ||
- set Company (optional) | ||
- set Digits (required for only float-type field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- [Quartile Limited](https://www.quartile.co): | ||
- Yoshi Tashiro | ||
- Aung Ko Ko Lin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows administrators to define the decimal precision of float fields and to | ||
add option values for fields (e.g., adding a date widget option for datetime fields) for | ||
QWeb report presentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The Options attribute in QWeb Field Converter is meant for use in PDF reports | ||
to prevent UI issues in web views. | ||
For example, adding {"widget": "date"} for the date_approve field in a purchase order | ||
can cause two dates to appear under the confirmation date column in the portal view, | ||
due to it being defined twice with different widgets. | ||
https://github.com/odoo/odoo/blob/5eec37961c2170b354ef837b46f94e89ebf37d52/addons/purchase/views/portal_templates.xml#L101-L102 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Converter configuration. | ||
|
||
Note that among matching config records, the one with the strictest condition will be | ||
adopted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_qweb_field_converter_all,access.qweb.field.converter.all,model_qweb_field_converter,,1,0,0,0 | ||
access_qweb_field_converter_admin,access.qweb.field.converter.admin,model_qweb_field_converter,base.group_system,1,1,1,1 |
10 changes: 10 additions & 0 deletions
10
report_qweb_field_converter/security/qweb_field_converter_security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record id="qweb_field_converter_company_rule" model="ir.rule"> | ||
<field name="name">Qweb Field Converter Multi-company</field> | ||
<field name="model_id" ref="model_qweb_field_converter" /> | ||
<field | ||
name="domain_force" | ||
>['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field> | ||
</record> | ||
</odoo> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either do this or make
qweb.field.converter
globally accessible. Please check and suggest which way is better. Portal users get 403 forbidden error when accessing their documents otherwise.