Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions sale_order_secondary_unit_convert/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=================================
Sale Order Secondary Unit Convert
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:77e2e5ee13ea91067966507a56acdf7acf6515f5dc6cb3596b8a195ffbf8bab6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-qrtl%2Fhls--custom-lightgray.png?logo=github
:target: https://github.com/qrtl/hls-custom/tree/18.0/sale_order_secondary_unit_convert
:alt: qrtl/hls-custom

|badge1| |badge2| |badge3|

This module lets users enter sale order line quantities in an internal
secondary unit while the line keeps being displayed in another secondary
unit.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/qrtl/hls-custom/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/qrtl/hls-custom/issues/new?body=module:%20sale_order_secondary_unit_convert%0Aversion:%2018.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

Maintainers
-----------

This module is part of the `qrtl/hls-custom <https://github.com/qrtl/hls-custom/tree/18.0/sale_order_secondary_unit_convert>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions sale_order_secondary_unit_convert/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions sale_order_secondary_unit_convert/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Order Secondary Unit Convert",
"summary": "Enter sale order line quantities in an internal secondary unit"
" while displaying another secondary unit.",
"version": "18.0.1.0.0",
"author": "Quartile",
"website": "https://www.quartile.co",
"category": "Sale",
"license": "AGPL-3",
"depends": ["sale_order_secondary_unit"],
"data": [
"views/sale_order_views.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions sale_order_secondary_unit_convert/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order_line
56 changes: 56 additions & 0 deletions sale_order_secondary_unit_convert/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.tools.float_utils import float_round


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

internal_secondary_uom_id = fields.Many2one(
comodel_name="product.secondary.unit",
string="Internal Secondary Unit",
)
internal_secondary_qty = fields.Float(
digits="Product Unit of Measure",
compute="_compute_internal_secondary_qty",
inverse="_inverse_internal_secondary_qty",
store=True,
readonly=False,
)

def _convert_qty_to_internal_secondary_uom(self):
self.ensure_one()
uom = self.internal_secondary_uom_id
qty = self.product_uom_qty
uom_line = self.product_uom
uom_product = self.product_id.uom_id
if uom_line and uom_product and uom_line != uom_product:
qty = uom_line._compute_quantity(qty, uom_product)
return float_round(
qty / (uom.factor or 1.0),
precision_rounding=uom.uom_id.rounding,
)

@api.depends(
"product_id", "product_uom_qty", "product_uom", "internal_secondary_uom_id"
)
def _compute_internal_secondary_qty(self):
for line in self:
uom = line.internal_secondary_uom_id
if not uom or uom.dependency_type == "independent":
line.internal_secondary_qty = 0.0
continue
line.internal_secondary_qty = line._convert_qty_to_internal_secondary_uom()

def _inverse_internal_secondary_qty(self):
for line in self:
uom = line.internal_secondary_uom_id
if not uom or uom.dependency_type == "independent" or not line.product_id:
continue
base_qty = line.internal_secondary_qty * (uom.factor or 1.0)
line.product_uom_qty = line.product_id.uom_id._compute_quantity(
base_qty, line.product_uom
)
line.env.remove_to_compute(line._fields["internal_secondary_qty"], line)
3 changes: 3 additions & 0 deletions sale_order_secondary_unit_convert/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions sale_order_secondary_unit_convert/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module lets users enter sale order line quantities in an internal
secondary unit while the line keeps being displayed in another secondary unit.
Loading
Loading