Skip to content

Commit 4cf667a

Browse files
[IMP] product_secondary_unit: add configuration for report presentation
Co-authored-by: Yoshi Tashiro <tashiro@quartile.co>
1 parent 7044ecd commit 4cf667a

File tree

9 files changed

+195
-33
lines changed

9 files changed

+195
-33
lines changed

product_secondary_unit/README.rst

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
======================
62
Product Secondary Unit
73
======================
@@ -17,7 +13,7 @@ Product Secondary Unit
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Production/Stable
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
@@ -40,6 +36,28 @@ other units with their conversion factor.
4036
.. contents::
4137
:local:
4238

39+
Configuration
40+
=============
41+
42+
To configure this module, go to *Settings* and look for the Units of
43+
Measure section:
44+
45+
- **Secondary Unit Price Display**: Controls how unit prices are shown
46+
in reports and portal views when secondary units are used.
47+
48+
- *Primary Unit Price Only*: Shows only the primary unit price
49+
- *Prioritize Secondary Unit Price*: Shows secondary unit price when
50+
available, falls back to primary otherwise
51+
- *Both Primary and Secondary Unit Prices*: Shows both prices
52+
53+
- **Hide Secondary UoM Column**: When enabled, hides the separate
54+
Secondary Qty column in reports and portal views. The secondary
55+
quantity will still be shown in the main Qty column based on the
56+
price display setting above.
57+
58+
These settings are intended to be used by dependency modules (e.g.,
59+
purchase_order_secondary_unit, account_move_secondary_unit).
60+
4361
Usage
4462
=====
4563

@@ -70,11 +88,14 @@ Authors
7088
Contributors
7189
------------
7290

73-
- Carlos Dauden <carlos.dauden@tecnativa.com>
74-
- Sergio Teruel <sergio.teruel@tecnativa.com>
75-
- Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
76-
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
77-
- Alan Ramos <alan.ramos@jarsa.com.mx>
91+
- Carlos Dauden <carlos.dauden@tecnativa.com>
92+
- Sergio Teruel <sergio.teruel@tecnativa.com>
93+
- Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
94+
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
95+
- Alan Ramos <alan.ramos@jarsa.com.mx>
96+
- `Quartile <https://www.quartile.co>`__:
97+
98+
- Yoshi Tashiro
7899

79100
Maintainers
80101
-----------

product_secondary_unit/__manifest__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"application": False,
1313
"installable": True,
1414
"depends": ["product"],
15-
"data": ["security/ir.model.access.csv", "views/product_views.xml"],
15+
"data": [
16+
"security/ir.model.access.csv",
17+
"views/product_views.xml",
18+
"views/res_config_settings_views.xml",
19+
],
1620
"maintainers": ["sergio-teruel"],
1721
}

product_secondary_unit/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
from . import product_second_unit
44
from . import product_secondary_unit_mixin
55
from . import product_template
6+
from . import res_company
7+
from . import res_config_settings

product_secondary_unit/models/product_secondary_unit_mixin.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,25 @@ def default_get(self, fields_list):
151151
):
152152
defaults["secondary_uom_qty"] = 1.0
153153
return defaults
154+
155+
def get_secondary_uom_display_mode(self):
156+
"""Return the secondary UoM price display mode for QWeb reports."""
157+
if not self.secondary_uom_id:
158+
return "primary"
159+
return self.company_id.secondary_uom_price_display or "primary"
160+
161+
def report_show_price_uom(self, uom_source=None):
162+
"""Return True if UoM should be shown in price column.
163+
164+
UoM is shown when the line displays multiple UoMs.
165+
"""
166+
if not self.secondary_uom_id:
167+
return False
168+
if (
169+
uom_source == "primary_uom"
170+
and self.get_secondary_uom_display_mode() == "secondary"
171+
):
172+
return False
173+
hide_col = self.company_id.hide_secondary_uom_column
174+
display = self.company_id.secondary_uom_price_display
175+
return not hide_col or display == "both"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2026 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
secondary_uom_price_display = fields.Selection(
11+
selection=[
12+
("primary", "Primary Unit Price Only"),
13+
("secondary", "Prioritize Secondary Unit Price"),
14+
("both", "Both Primary and Secondary Unit Prices"),
15+
],
16+
string="Secondary Unit Price Display",
17+
default="primary",
18+
help="Configure how unit prices are displayed in the reports when "
19+
"secondary units are used.\n"
20+
"- Primary Unit Price Only: Shows only the primary unit price\n"
21+
"- Prioritize Secondary Unit Price: Shows secondary unit price when "
22+
"available, falls back to primary otherwise\n"
23+
"- Both: Shows both prices (primary and secondary)",
24+
)
25+
# Added for supporting the existing report presentation. We can drop this together
26+
# with the second qty column in reports if the community agrees with it.
27+
hide_secondary_uom_column = fields.Boolean(
28+
string="Hide Secondary UoM Column",
29+
default=False,
30+
help="When enabled, hides the separate Secondary Qty column in the "
31+
"reports. The secondary quantity will still be shown in the main Qty column "
32+
"based on the 'Secondary Unit Price Display' setting.",
33+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2026 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
secondary_uom_price_display = fields.Selection(
11+
related="company_id.secondary_uom_price_display",
12+
readonly=False,
13+
)
14+
hide_secondary_uom_column = fields.Boolean(
15+
related="company_id.hide_secondary_uom_column",
16+
readonly=False,
17+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
To configure this module, go to *Settings* and look for the Units of Measure
2+
section:
3+
4+
- **Secondary Unit Price Display**: Controls how unit prices are shown in reports
5+
and portal views when secondary units are used.
6+
- *Primary Unit Price Only*: Shows only the primary unit price
7+
- *Prioritize Secondary Unit Price*: Shows secondary unit price when available, falls
8+
back to primary otherwise
9+
- *Both Primary and Secondary Unit Prices*: Shows both prices
10+
11+
- **Hide Secondary UoM Column**: When enabled, hides the separate Secondary Qty column
12+
in reports and portal views. The secondary quantity will still be
13+
shown in the main Qty column based on the price display setting above.
14+
15+
These settings are intended to be used by dependency modules (e.g.,
16+
purchase_order_secondary_unit, account_move_secondary_unit).

product_secondary_unit/static/description/index.html

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Product Secondary Unit</title>
77
<style type="text/css">
88

99
/*
@@ -360,38 +360,55 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="product-secondary-unit">
364+
<h1 class="title">Product Secondary Unit</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="product-secondary-unit">
370-
<h1>Product Secondary Unit</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:0029efd789786ccc3b328f612bf8dec00c53357a6b825b322a5170cdc451ba88
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" 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 image-reference" href="https://github.com/OCA/product-attribute/tree/18.0/product_secondary_unit"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>This module extends the functionality of product module to allow define
379374
other units with their conversion factor.</p>
380375
<p><strong>Table of contents</strong></p>
381376
<div class="contents local topic" id="contents">
382377
<ul class="simple">
383-
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
384-
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
385-
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
386-
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
387-
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
388-
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
378+
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
379+
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
380+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
381+
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
382+
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
383+
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
384+
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
385+
</ul>
386+
</li>
387+
</ul>
388+
</div>
389+
<div class="section" id="configuration">
390+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
391+
<p>To configure this module, go to <em>Settings</em> and look for the Units of
392+
Measure section:</p>
393+
<ul class="simple">
394+
<li><strong>Secondary Unit Price Display</strong>: Controls how unit prices are shown
395+
in reports and portal views when secondary units are used.<ul>
396+
<li><em>Primary Unit Price Only</em>: Shows only the primary unit price</li>
397+
<li><em>Prioritize Secondary Unit Price</em>: Shows secondary unit price when
398+
available, falls back to primary otherwise</li>
399+
<li><em>Both Primary and Secondary Unit Prices</em>: Shows both prices</li>
389400
</ul>
390401
</li>
402+
<li><strong>Hide Secondary UoM Column</strong>: When enabled, hides the separate
403+
Secondary Qty column in reports and portal views. The secondary
404+
quantity will still be shown in the main Qty column based on the
405+
price display setting above.</li>
391406
</ul>
407+
<p>These settings are intended to be used by dependency modules (e.g.,
408+
purchase_order_secondary_unit, account_move_secondary_unit).</p>
392409
</div>
393410
<div class="section" id="usage">
394-
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
411+
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
395412
<p>To use this module you need to:</p>
396413
<ol class="arabic simple">
397414
<li>Go to a <em>Product &gt; General Information tab</em>.</li>
@@ -400,33 +417,37 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
400417
</ol>
401418
</div>
402419
<div class="section" id="bug-tracker">
403-
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
420+
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
404421
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-attribute/issues">GitHub Issues</a>.
405422
In case of trouble, please check there if your issue has already been reported.
406423
If you spotted it first, help us to smash it by providing a detailed and welcomed
407424
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_secondary_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
408425
<p>Do not contact contributors directly about support or help with technical issues.</p>
409426
</div>
410427
<div class="section" id="credits">
411-
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
428+
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
412429
<div class="section" id="authors">
413-
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
430+
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
414431
<ul class="simple">
415432
<li>Tecnativa</li>
416433
</ul>
417434
</div>
418435
<div class="section" id="contributors">
419-
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
436+
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
420437
<ul class="simple">
421438
<li>Carlos Dauden &lt;<a class="reference external" href="mailto:carlos.dauden&#64;tecnativa.com">carlos.dauden&#64;tecnativa.com</a>&gt;</li>
422439
<li>Sergio Teruel &lt;<a class="reference external" href="mailto:sergio.teruel&#64;tecnativa.com">sergio.teruel&#64;tecnativa.com</a>&gt;</li>
423440
<li>Kitti Upariphutthiphong &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
424441
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
425442
<li>Alan Ramos &lt;<a class="reference external" href="mailto:alan.ramos&#64;jarsa.com.mx">alan.ramos&#64;jarsa.com.mx</a>&gt;</li>
443+
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
444+
<li>Yoshi Tashiro</li>
445+
</ul>
446+
</li>
426447
</ul>
427448
</div>
428449
<div class="section" id="maintainers">
429-
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
450+
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
430451
<p>This module is maintained by the OCA.</p>
431452
<a class="reference external image-reference" href="https://odoo-community.org">
432453
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -441,6 +462,5 @@ <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
441462
</div>
442463
</div>
443464
</div>
444-
</div>
445465
</body>
446466
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="res_config_settings_view_form" model="ir.ui.view">
4+
<field name="name">res.config.settings.view.form.inherit.secondary.unit</field>
5+
<field name="model">res.config.settings</field>
6+
<field name="inherit_id" ref="product.res_config_settings_view_form" />
7+
<field name="arch" type="xml">
8+
<setting id="manage_volume_uom_setting" position="after">
9+
<setting
10+
id="secondary_uom_price_display"
11+
company_dependent="1"
12+
string="Secondary Unit Price Display"
13+
help="Configure how unit prices and quantities are shown in reports when secondary units are used"
14+
>
15+
<field name="secondary_uom_price_display" widget="radio" />
16+
</setting>
17+
<setting
18+
id="secondary_uom_price_display"
19+
company_dependent="1"
20+
help="If selected, the 'Second Qty' column will be hidden in purchase order and quotation reports."
21+
>
22+
<field name="hide_secondary_uom_column" />
23+
</setting>
24+
</setting>
25+
</field>
26+
</record>
27+
</odoo>

0 commit comments

Comments
 (0)