Skip to content

Commit 0da5173

Browse files
committed
[ADD] report_qweb_decimal_precision
1 parent 622a3ae commit 0da5173

19 files changed

+870
-0
lines changed
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
=============================
2+
Report Qweb Decimal Precision
3+
=============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:88e7df18a281dcca7d418a47e7a1a6130516e0352493ba792061d9ad97cfa7a0
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
20+
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_decimal_precision
21+
:alt: OCA/reporting-engine
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_decimal_precision
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows administrators to define the decimal precision of
32+
float fields for QWeb report presentation.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Use Cases / Context
40+
===================
41+
42+
Odoo's QWeb reports display values of float fields based on the decimal
43+
accuracy settings, which are global and sometimes bring inconveniences.
44+
45+
For example:
46+
47+
- You have some products which require a fine precision with inventory
48+
management (e.g. liquid, powder, etc.) and you set 'Product Unit of
49+
Measure' to 4, but you don't want to show '2.0000 Units' on your
50+
quotation to sell assembled products (you may just want to show '2
51+
Units').
52+
- You purchase some raw materials in bulk in USD whose unit price comes
53+
down to the 4th decimal place and you set 'Product Price' to this
54+
level or precision, but you don't want to show the unit price of a
55+
product as '120,000.0000' on your JPY quotation (you would just want
56+
to show '120,000').
57+
58+
This module is designed to address these inconveniences.
59+
60+
Configuration
61+
=============
62+
63+
Go to *Settings > Technical > Reporting > Decimal Precision QWeb*, and
64+
create records according to your needs.
65+
66+
For each record:
67+
68+
- choose a model and a float-type field (required)
69+
- set UoM and UoM Field, or Currency and Currency Field (optional)
70+
- set Company (optional)
71+
- set Digits (required)
72+
73+
Usage
74+
=====
75+
76+
Print a QWeb report (quotation, invoice, purchase order, etc.), and the
77+
value presentation for fields like line quantity and price unit are
78+
adjusted according to the Decimal Precision QWeb configuration.
79+
80+
Note that among matching config records, the one with the strictest
81+
condition will be adopted.
82+
83+
Bug Tracker
84+
===========
85+
86+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
87+
In case of trouble, please check there if your issue has already been reported.
88+
If you spotted it first, help us to smash it by providing a detailed and welcomed
89+
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_decimal_precision%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
90+
91+
Do not contact contributors directly about support or help with technical issues.
92+
93+
Credits
94+
=======
95+
96+
Authors
97+
-------
98+
99+
* Quartile Limited
100+
101+
Contributors
102+
------------
103+
104+
- `Quartile Limited <https://www.quartile.co>`__:
105+
106+
- Yoshi Tashiro
107+
- Aung Ko Ko Lin
108+
109+
Maintainers
110+
-----------
111+
112+
This module is maintained by the OCA.
113+
114+
.. image:: https://odoo-community.org/logo.png
115+
:alt: Odoo Community Association
116+
:target: https://odoo-community.org
117+
118+
OCA, or the Odoo Community Association, is a nonprofit organization whose
119+
mission is to support the collaborative development of Odoo features and
120+
promote its widespread use.
121+
122+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_decimal_precision>`_ project on GitHub.
123+
124+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Report Qweb Decimal Precision",
5+
"version": "16.0.1.0.0",
6+
"category": "Technical Settings",
7+
"license": "AGPL-3",
8+
"author": "Quartile Limited, Odoo Community Association (OCA)",
9+
"website": "https://github.com/OCA/reporting-engine",
10+
"depends": ["uom"],
11+
"data": [
12+
"security/ir.model.access.csv",
13+
"security/decimal_precision_qweb_security.xml",
14+
"views/decimal_precision_qweb_views.xml",
15+
],
16+
"installable": True,
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import decimal_precision_qweb
2+
from . import ir_qweb_fields
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class DecimalPrecisioQweb(models.Model):
8+
_name = "decimal.precision.qweb"
9+
_description = "Decimal Precision Qweb"
10+
_order = "res_model_id, field_id"
11+
12+
res_model_id = fields.Many2one(
13+
"ir.model", string="Model", ondelete="cascade", required=True
14+
)
15+
res_model_name = fields.Char("Model Name", related="res_model_id.model", store=True)
16+
field_id = fields.Many2one(
17+
"ir.model.fields",
18+
domain="[('model_id', '=', res_model_id), ('ttype', '=', 'float')]",
19+
string="Field",
20+
ondelete="cascade",
21+
required=True,
22+
)
23+
field_name = fields.Char("Field Name", related="field_id.name", store=True)
24+
uom_id = fields.Many2one("uom.uom", string="UoM", ondelete="cascade")
25+
uom_field_id = fields.Many2one(
26+
"ir.model.fields",
27+
domain="[('model_id', '=', res_model_id), ('relation', '=', 'uom.uom')]",
28+
string="UoM Field",
29+
ondelete="cascade",
30+
)
31+
currency_id = fields.Many2one("res.currency", string="Currency", ondelete="cascade")
32+
currency_field_id = fields.Many2one(
33+
"ir.model.fields",
34+
domain="[('model_id', '=', res_model_id), ('relation', '=', 'res.currency')]",
35+
string="Currency Field",
36+
ondelete="cascade",
37+
)
38+
digits = fields.Integer(required=True)
39+
company_id = fields.Many2one("res.company", string="Company")
40+
41+
def _get_score(self, record):
42+
self.ensure_one()
43+
score = 1
44+
if self.company_id:
45+
if record.company_id == self.company_id:
46+
score += 1
47+
else:
48+
return -1
49+
if self.uom_id:
50+
if record[self.uom_field_id.sudo().name] == self.uom_id:
51+
score += 1
52+
else:
53+
return -1
54+
if self.currency_id:
55+
if record[self.currency_field_id.sudo().name] == self.currency_id:
56+
score += 1
57+
else:
58+
return -1
59+
return score
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models
5+
6+
7+
class FloatConverter(models.AbstractModel):
8+
_inherit = "ir.qweb.field.float"
9+
10+
@api.model
11+
def record_to_html(self, record, field_name, options):
12+
if "precision" not in options and "decimal_precision" not in options:
13+
dp_qweb_recs = self.env["decimal.precision.qweb"].search(
14+
[("res_model_name", "=", record._name), ("field_name", "=", field_name)]
15+
)
16+
precision_rec = max(
17+
dp_qweb_recs, default=None, key=lambda r: r._get_score(record)
18+
)
19+
if precision_rec:
20+
options = dict(options, precision=precision_rec.digits)
21+
return super().record_to_html(record, field_name, options)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Go to *Settings > Technical > Reporting > Decimal Precision QWeb*, and create records
2+
according to your needs.
3+
4+
For each record:
5+
6+
* choose a model and a float-type field (required)
7+
* set UoM and UoM Field, or Currency and Currency Field (optional)
8+
* set Company (optional)
9+
* set Digits (required)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Odoo's QWeb reports display values of float fields based on the decimal accuracy
2+
settings, which are global and sometimes bring inconveniences.
3+
4+
For example:
5+
6+
* You have some products which require a fine precision with inventory management (e.g.
7+
liquid, powder, etc.) and you set 'Product Unit of Measure' to 4, but you don't want
8+
to show '2.0000 Units' on your quotation to sell assembled products (you may just want
9+
to show '2 Units').
10+
* You purchase some raw materials in bulk in USD whose unit price comes down to the 4th
11+
decimal place and you set 'Product Price' to this level or precision, but you don't
12+
want to show the unit price of a product as '120,000.0000' on your JPY quotation (you
13+
would just want to show '120,000').
14+
15+
This module is designed to address these inconveniences.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* [Quartile Limited](https://www.quartile.co):
2+
* Yoshi Tashiro
3+
* Aung Ko Ko Lin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module allows administrators to define the decimal precision of float fields for
2+
QWeb report presentation.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Print a QWeb report (quotation, invoice, purchase order, etc.), and the value
2+
presentation for fields like line quantity and price unit are adjusted according to the
3+
Decimal Precision QWeb configuration.
4+
5+
Note that among matching config records, the one with the strictest condition will be
6+
adopted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="decimal_precision_qweb_company_rule" model="ir.rule">
4+
<field name="name">Decimal Precision QWeb Multi-company</field>
5+
<field name="model_id" ref="model_decimal_precision_qweb" />
6+
<field
7+
name="domain_force"
8+
>['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field>
9+
</record>
10+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_decimal_precision_qweb_user,access.decimal.precisoon.qweb.user,model_decimal_precision_qweb,base.group_user,1,0,0,0
3+
access_decimal_precision_qweb_admin,access.decimal.precisoon.qweb.admin,model_decimal_precision_qweb,base.group_system,1,1,1,1

0 commit comments

Comments
 (0)