-
-
Notifications
You must be signed in to change notification settings - Fork 816
[18.0][IMP] product_secondary_unit: add configuration for report presentation #2211
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
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
| PRICE_DISPLAY_SELECTION = [ | ||
| ("primary", "Primary Unit Price Only"), | ||
| ("secondary", "Prioritize Secondary Unit Price"), | ||
| ("both", "Both Primary and Secondary Unit Prices"), | ||
| ] | ||
|
|
||
|
|
||
| class ResCompany(models.Model): | ||
| _inherit = "res.company" | ||
|
|
||
| secondary_uom_price_display_sale = fields.Selection( | ||
| selection=PRICE_DISPLAY_SELECTION, | ||
| string="Secondary Unit Price Display (Sales)", | ||
| default="primary", | ||
| required=True, | ||
| ) | ||
| secondary_uom_price_display_purchase = fields.Selection( | ||
| selection=PRICE_DISPLAY_SELECTION, | ||
| string="Secondary Unit Price Display (Purchase)", | ||
| default="primary", | ||
| required=True, | ||
| ) | ||
| # Added for supporting the existing report presentation. We can drop this together | ||
| # with the second qty column in reports if the community agrees with it. | ||
| hide_secondary_uom_column_sale = fields.Boolean( | ||
| string="Hide Secondary UoM Column (Sales)", | ||
| default=False, | ||
| ) | ||
| hide_secondary_uom_column_purchase = fields.Boolean( | ||
| string="Hide Secondary UoM Column (Purchase)", | ||
| default=False, | ||
| ) | ||
|
|
||
| def hide_secondary_uom_column(self, record): | ||
| """Return whether to hide the 'Second Qty' column for this document type.""" | ||
| if record._name == "sale.order" or ( | ||
| record._name == "account.move" | ||
| and record.is_sale_document(include_receipts=True) | ||
| ): | ||
| return self.hide_secondary_uom_column_sale | ||
| if record._name == "purchase.order" or ( | ||
| record._name == "account.move" | ||
| and record.is_purchase_document(include_receipts=True) | ||
| ): | ||
| return self.hide_secondary_uom_column_purchase | ||
| return True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResConfigSettings(models.TransientModel): | ||
| _inherit = "res.config.settings" | ||
|
|
||
| secondary_uom_price_display_sale = fields.Selection( | ||
| related="company_id.secondary_uom_price_display_sale", | ||
| readonly=False, | ||
| ) | ||
| secondary_uom_price_display_purchase = fields.Selection( | ||
| related="company_id.secondary_uom_price_display_purchase", | ||
| readonly=False, | ||
| ) | ||
| hide_secondary_uom_column_sale = fields.Boolean( | ||
| related="company_id.hide_secondary_uom_column_sale", | ||
| readonly=False, | ||
| ) | ||
| hide_secondary_uom_column_purchase = fields.Boolean( | ||
| related="company_id.hide_secondary_uom_column_purchase", | ||
| readonly=False, | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify me please:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these options will work for Accounting even if Sales or Purchase is not installed. These are intended for use in Sales, Purchase, and Accounting. I did not add them to the corresponding extension modules because, if they were moved there, account_move_secondary_unit would need to depend on those extension modules. I wanted to avoid that. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| To configure this module, go to **Settings** and locate the **Units of Measure** | ||
| section. | ||
|
|
||
| ## Secondary Unit Price Display | ||
|
|
||
| Configure how unit prices and quantities are shown in reports when secondary units are | ||
| used. | ||
|
|
||
| - **Sales**: Select the display policy for sales order and customer invoice reports and | ||
| portal views. | ||
| - **Purchase**: Select the display policy for purchase order and vendor bill reports and | ||
| portal views. | ||
|
|
||
| Available options: | ||
|
|
||
| - **Primary Unit Price Only**: Show only the primary unit price. | ||
| - **Prioritize Secondary Unit Price**: Show the secondary unit price when available, | ||
| otherwise fall back to the primary unit price. | ||
| - **Both Primary and Secondary Unit Prices**: Show both primary and secondary unit | ||
| prices. | ||
|
|
||
| ## Hide Secondary Qty Column | ||
|
|
||
| Hide the separate **Second Qty** column in reports. | ||
|
|
||
| - When enabled, the **Second Qty** column is hidden in reports. The | ||
| secondary quantity can still be shown in the main **Qty** column | ||
| depending on the selected price display policy above. | ||
| - Apply the setting per document type: | ||
| - **Sales** | ||
| - **Purchase** | ||
|
|
||
| These settings are intended to be used by dependency modules (for example, | ||
| `purchase_order_secondary_unit` and `account_move_secondary_unit`). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <odoo> | ||
| <record id="group_sale_secondary_unit" model="res.groups"> | ||
| <field name="name">Sale Secondary Unit</field> | ||
| <field name="category_id" ref="base.module_category_hidden" /> | ||
| </record> | ||
| <record id="group_purchase_secondary_unit" model="res.groups"> | ||
| <field name="name">Purchase Secondary Unit</field> | ||
| <field name="category_id" ref="base.module_category_hidden" /> | ||
| </record> | ||
| </odoo> |
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.
This configurability level seems a bit insane. Are you going to display UoM price on sale, but not on purchase, but show the UoM? Can't this be fit with a single security group "Show seconday unit prices"?
Uh oh!
There was an error while loading. Please reload this page.
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.
For showing the UoM column option, it is intended only to preserve the existing Sales/Purchase report behavior of
sale_order_secondary_unitandpurchase_order_secondary_unitwhenPrimary Unit Price Onlyis selected. For the other price display modes, the secondary UoM is already shown in thequantityandpricecolumns, so showing an additional UoM column would be redundant.I don't think Sales and Purchase should always share the same display style for the secondary unit price and the secondary unit column. Therefore, I prefer separate settings for Sales and Purchase documents, with separate security groups to control each document type.
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.
This is the expected report when

Primary Unit Price Onlyis selected without hiding the UoM column.This is the expected report when

Prioritize Secondary Unit Priceis selected.This is the expected report when

Both Primary and Secondary Unit Pricesis selected.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.
But as said, this is too many configurations, while it's not a usual problem to show both. This only increases the maintenance burden to the main module being a residual feature that most people won't use, being enough with the default option. I think this has to be simplified.
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.
@pedrobaeza To me it makes sense to be able to configure sales and purchasing separately as they have different needs. But we can do the secondary UoM price display thing in a separate module if it's too much to be covered in the main module, which will mean four new additional modules (i.e., product_secondary_unit_price, purchase_order_secondary_unit_price, sale_order_secondary_unit_price and account_move_secondary_unit_price).
What we still want to do in this module, though, is to be able to hide the secondary qty column in reports. For this, we don't need to have separate config for sales and purchasing (as we will most likely disable this for both anyway).
Does this sound like a good approach?
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.
I also came across this need: to choose if the secondary unit should be visible on sales document or purchase documents.
It can be the case that the feature helps pick quantities on order lines, but we don't want/need them on the PDFs.
And the decision can be different for sale or purchase.
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.
@AungKoKoLin1997 That's a feature change and should go in a separate commit, so that it can be backported. Thanks.
Uh oh!
There was an error while loading. Please reload this page.
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.
@dreispt For easier backporting, I’ll split this into two commits:
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.
@dreispt I split into two commits.
Uh oh!
There was an error while loading. Please reload this page.
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.
@sergio-teruel Can you please review the changes in this PR? We’re planning to use this module for our customer and would like to proceed. If you think the current changes aren’t suitable, I can follow up based on @yostashiro suggestion above.