Skip to content

Commit 8e05667

Browse files
Aung Ko Ko LinAung Ko Ko Lin
authored andcommitted
update
1 parent 24de3d2 commit 8e05667

8 files changed

Lines changed: 133 additions & 45 deletions

File tree

report_qweb_decimal_place/README.rst

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Report Qweb Decimal Place
1010
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1111
:target: https://odoo-community.org/page/development-status
1212
:alt: Beta
13-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14-
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15-
:alt: License: AGPL-3
13+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15+
:alt: License: LGPL-3
1616
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
1717
:target: https://github.com/OCA/reporting-engine/tree/15.0/report_qweb_decimal_place
1818
:alt: OCA/reporting-engine
@@ -25,21 +25,51 @@ Report Qweb Decimal Place
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
2727

28-
This module does the following:
29-
30-
- Adds apply_price_unit_format in currency and the price_unit format of reports will depend on that field.
28+
This module intends to provide the base function for currencies to adjust the number of decimal places
29+
for the unit price in QWeb reports.
30+
Installing this module alone does not affect the presentation of existing QWeb reports.
31+
Individual adjustments need to be done in separate modules in a manner similar to the following:
32+
33+
.. code-block:: xml
34+
35+
<?xml version="1.0" encoding="utf-8" ?>
36+
<odoo>
37+
<template
38+
id="report_saleorder_document_inherit"
39+
inherit_id="sale.report_saleorder_document"
40+
>
41+
<xpath expr="//tbody[@class='sale_tbody']//tr//td[3]" position="replace">
42+
<td name="td_priceunit" class="text-right">
43+
<t t-set="currency" t-value="doc.currency_id" />
44+
<t t-set="price_unit" t-value="line.price_unit" />
45+
<t t-call="report_qweb_decimal_place.price_unit_value_format" />
46+
</td>
47+
</xpath>
48+
</template>
49+
</odoo>
50+
51+
Background:
52+
--------------
53+
Odoo default reports display price unit with the decimal accuracy of product price configuration.
54+
However, globally applying the decimal accuracy setting is sometimes not appropriate under multi-currency settings
55+
where how unit prices should be presented differs depending on the currency.
56+
57+
For example, unit prices in JPY usually do not have decimals (with some exceptions depending on the industry),
58+
while those in USD may require up to 2-4 decimals. If we configure the decimal accuracy based on USD, the unit price
59+
presentation on PDF reports for JPY transactions may appear a bit unconventional.
3160

3261
**Table of contents**
3362

3463
.. contents::
3564
:local:
3665

37-
Usage
38-
=====
66+
Configuration
67+
=============
3968

4069
To apply price unit format:
4170
- Go to Invoicing --> Configuration --> Currencies
42-
- Check apply_price_unit_format field
71+
- Check apply_price_decimal_place field
72+
- Define decimal place in price_decimal_place field
4373

4474
Inherit this module in your xxx_report_qweb_decimal_place module and format the price unit in reports.
4575

report_qweb_decimal_place/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright 2022 Quartile Limited
2-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33
{
44
"name": "Report Qweb Decimal Place",
55
"category": "Reporting",
66
"version": "15.0.1.0.0",
77
"author": "Quartile Limited, Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/reporting-engine",
9-
"license": "AGPL-3",
9+
"license": "LGPL-3",
1010
"depends": ["base"],
1111
"data": [
1212
"reports/price_unit_value_format.xml",
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Copyright 2022 Quartile Limited
2-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33

44
from odoo import fields, models
55

66

77
class ResCurrency(models.Model):
88
_inherit = "res.currency"
99

10-
apply_price_unit_format = fields.Boolean()
10+
apply_price_decimal_place = fields.Boolean(
11+
help="Apply this decimal place to the unit price field of relevant PDF reports "
12+
"where appropriate customization is done."
13+
)
14+
price_decimal_places = fields.Integer(
15+
help="Define decimal places for the unit price field of relevant PDF reports"
16+
)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
To apply price unit format:
22
- Go to Invoicing --> Configuration --> Currencies
3-
- Check apply_price_unit_format field
3+
- Check apply_price_decimal_place field
4+
- Define decimal place in price_decimal_place field
45

56
Inherit this module in your xxx_report_qweb_decimal_place module and format the price unit in reports.
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1-
This module does the following:
1+
This module intends to provide the base function for currencies to adjust the number of decimal places
2+
for the unit price in QWeb reports.
3+
Installing this module alone does not affect the presentation of existing QWeb reports.
4+
Individual adjustments need to be done in separate modules in a manner similar to the following:
25

3-
- Adds apply_price_unit_format in currency and the price_unit format of reports will depend on that field.
6+
.. code-block:: xml
7+
8+
<?xml version="1.0" encoding="utf-8" ?>
9+
<odoo>
10+
<template
11+
id="report_saleorder_document_inherit"
12+
inherit_id="sale.report_saleorder_document"
13+
>
14+
<xpath expr="//tbody[@class='sale_tbody']//tr//td[3]" position="replace">
15+
<td name="td_priceunit" class="text-right">
16+
<t t-set="currency" t-value="doc.currency_id" />
17+
<t t-set="price_unit" t-value="line.price_unit" />
18+
<t t-call="report_qweb_decimal_place.price_unit_value_format" />
19+
</td>
20+
</xpath>
21+
</template>
22+
</odoo>
23+
24+
Background:
25+
--------------
26+
Odoo default reports display price unit with the decimal accuracy of product price configuration.
27+
However, globally applying the decimal accuracy setting is sometimes not appropriate under multi-currency settings
28+
where how unit prices should be presented differs depending on the currency.
29+
30+
For example, unit prices in JPY usually do not have decimals (with some exceptions depending on the industry),
31+
while those in USD may require up to 2-4 decimals. If we configure the decimal accuracy based on USD, the unit price
32+
presentation on PDF reports for JPY transactions may appear a bit unconventional.

report_qweb_decimal_place/reports/price_unit_value_format.xml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@
77
<t t-set="price_unit" t-value="line.price_unit" />
88
<t t-set="currency" t-value="o.currency_id" />
99
-->
10-
<t t-if="currency.apply_price_unit_format">
11-
<t
12-
t-if="round(price_unit) != price_unit
13-
or
14-
not currency.rounding >= 1"
15-
>
16-
<span t-esc="'{:,.2f}'.format(price_unit)" />
17-
</t>
18-
<t
19-
t-if="round(price_unit) == price_unit
20-
and
21-
currency.rounding >= 1"
22-
>
23-
<span t-esc="'{:,.0f}'.format(price_unit)" />
24-
</t>
10+
<t t-if="currency.apply_price_decimal_place">
11+
<span
12+
class="text-nowrap"
13+
t-esc="price_unit"
14+
t-options='{"widget": "float", "precision": currency.price_decimal_places}'
15+
/>
2516
</t>
2617
<t t-else="">
2718
<span class="text-nowrap" t-field="line.price_unit" />

report_qweb_decimal_place/static/description/index.html

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,40 @@ <h1 class="title">Report Qweb Decimal Place</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_qweb_decimal_place"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_qweb_decimal_place"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
371-
<p>This module does the following:</p>
372-
<ul class="simple">
373-
<li>Adds apply_price_unit_format in currency and the price_unit format of reports will depend on that field.</li>
374-
</ul>
370+
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_qweb_decimal_place"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_qweb_decimal_place"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
371+
<p>This module intends to provide the base function for currencies to adjust the number of decimal places
372+
for the unit price in QWeb reports.
373+
Installing this module alone does not affect the presentation of existing QWeb reports.
374+
Individual adjustments need to be done in separate modules in a manner similar to the following:</p>
375+
<pre class="code xml literal-block">
376+
<span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;</span>
377+
<span class="nt">&lt;odoo&gt;</span>
378+
<span class="nt">&lt;template</span>
379+
<span class="na">id=</span><span class="s">&quot;report_saleorder_document_inherit&quot;</span>
380+
<span class="na">inherit_id=</span><span class="s">&quot;sale.report_saleorder_document&quot;</span>
381+
<span class="nt">&gt;</span>
382+
<span class="nt">&lt;xpath</span> <span class="na">expr=</span><span class="s">&quot;//tbody[&#64;class='sale_tbody']//tr//td[3]&quot;</span> <span class="na">position=</span><span class="s">&quot;replace&quot;</span><span class="nt">&gt;</span>
383+
<span class="nt">&lt;td</span> <span class="na">name=</span><span class="s">&quot;td_priceunit&quot;</span> <span class="na">class=</span><span class="s">&quot;text-right&quot;</span><span class="nt">&gt;</span>
384+
<span class="nt">&lt;t</span> <span class="na">t-set=</span><span class="s">&quot;currency&quot;</span> <span class="na">t-value=</span><span class="s">&quot;doc.currency_id&quot;</span> <span class="nt">/&gt;</span>
385+
<span class="nt">&lt;t</span> <span class="na">t-set=</span><span class="s">&quot;price_unit&quot;</span> <span class="na">t-value=</span><span class="s">&quot;line.price_unit&quot;</span> <span class="nt">/&gt;</span>
386+
<span class="nt">&lt;t</span> <span class="na">t-call=</span><span class="s">&quot;report_qweb_decimal_place.price_unit_value_format&quot;</span> <span class="nt">/&gt;</span>
387+
<span class="nt">&lt;/td&gt;</span>
388+
<span class="nt">&lt;/xpath&gt;</span>
389+
<span class="nt">&lt;/template&gt;</span>
390+
<span class="nt">&lt;/odoo&gt;</span>
391+
</pre>
392+
<div class="section" id="background">
393+
<h1>Background:</h1>
394+
<p>Odoo default reports display price unit with the decimal accuracy of product price configuration.
395+
However, globally applying the decimal accuracy setting is sometimes not appropriate under multi-currency settings
396+
where how unit prices should be presented differs depending on the currency.</p>
397+
<p>For example, unit prices in JPY usually do not have decimals (with some exceptions depending on the industry),
398+
while those in USD may require up to 2-4 decimals. If we configure the decimal accuracy based on USD, the unit price
399+
presentation on PDF reports for JPY transactions may appear a bit unconventional.</p>
375400
<p><strong>Table of contents</strong></p>
376401
<div class="contents local topic" id="contents">
377402
<ul class="simple">
378-
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
403+
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
379404
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
380405
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
381406
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
@@ -384,36 +409,37 @@ <h1 class="title">Report Qweb Decimal Place</h1>
384409
</li>
385410
</ul>
386411
</div>
387-
<div class="section" id="usage">
388-
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
412+
<div class="section" id="configuration">
413+
<h2><a class="toc-backref" href="#id1">Configuration</a></h2>
389414
<dl class="docutils">
390415
<dt>To apply price unit format:</dt>
391416
<dd><ul class="first last simple">
392417
<li>Go to Invoicing –&gt; Configuration –&gt; Currencies</li>
393-
<li>Check apply_price_unit_format field</li>
418+
<li>Check apply_price_decimal_place field</li>
419+
<li>Define decimal place in price_decimal_place field</li>
394420
</ul>
395421
</dd>
396422
</dl>
397423
<p>Inherit this module in your xxx_report_qweb_decimal_place module and format the price unit in reports.</p>
398424
</div>
399425
<div class="section" id="bug-tracker">
400-
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
426+
<h2><a class="toc-backref" href="#id2">Bug Tracker</a></h2>
401427
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/reporting-engine/issues">GitHub Issues</a>.
402428
In case of trouble, please check there if your issue has already been reported.
403429
If you spotted it first, help us smashing it by providing a detailed and welcomed
404430
<a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_decimal_place%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
405431
<p>Do not contact contributors directly about support or help with technical issues.</p>
406432
</div>
407433
<div class="section" id="credits">
408-
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
434+
<h2><a class="toc-backref" href="#id3">Credits</a></h2>
409435
<div class="section" id="authors">
410-
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
436+
<h3><a class="toc-backref" href="#id4">Authors</a></h3>
411437
<ul class="simple">
412438
<li>Quartile Limited</li>
413439
</ul>
414440
</div>
415441
<div class="section" id="maintainers">
416-
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
442+
<h3><a class="toc-backref" href="#id5">Maintainers</a></h3>
417443
<p>This module is maintained by the OCA.</p>
418444
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
419445
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
@@ -424,5 +450,6 @@ <h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
424450
</div>
425451
</div>
426452
</div>
453+
</div>
427454
</body>
428455
</html>

report_qweb_decimal_place/views/res_currency_views.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
<field name="inherit_id" ref="base.view_currency_form" />
77
<field name="arch" type="xml">
88
<xpath expr="//field[@name='currency_subunit_label']" position="after">
9-
<field name="apply_price_unit_format" />
9+
<field name="apply_price_decimal_place" />
10+
<field
11+
name="price_decimal_places"
12+
attrs="{'invisible': [('apply_price_decimal_place', '=', False)]}"
13+
/>
1014
</xpath>
1115
</field>
1216
</record>

0 commit comments

Comments
 (0)