diff --git a/sale_order_secondary_unit_convert/README.rst b/sale_order_secondary_unit_convert/README.rst new file mode 100644 index 00000000..fd710824 --- /dev/null +++ b/sale_order_secondary_unit_convert/README.rst @@ -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 `_. +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 `_. + +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 `_ project on GitHub. + +You are welcome to contribute. diff --git a/sale_order_secondary_unit_convert/__init__.py b/sale_order_secondary_unit_convert/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/sale_order_secondary_unit_convert/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_order_secondary_unit_convert/__manifest__.py b/sale_order_secondary_unit_convert/__manifest__.py new file mode 100644 index 00000000..93751599 --- /dev/null +++ b/sale_order_secondary_unit_convert/__manifest__.py @@ -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, +} diff --git a/sale_order_secondary_unit_convert/models/__init__.py b/sale_order_secondary_unit_convert/models/__init__.py new file mode 100644 index 00000000..8eb9d1d4 --- /dev/null +++ b/sale_order_secondary_unit_convert/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order_line diff --git a/sale_order_secondary_unit_convert/models/sale_order_line.py b/sale_order_secondary_unit_convert/models/sale_order_line.py new file mode 100644 index 00000000..ea5274c3 --- /dev/null +++ b/sale_order_secondary_unit_convert/models/sale_order_line.py @@ -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) diff --git a/sale_order_secondary_unit_convert/pyproject.toml b/sale_order_secondary_unit_convert/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/sale_order_secondary_unit_convert/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_order_secondary_unit_convert/readme/DESCRIPTION.md b/sale_order_secondary_unit_convert/readme/DESCRIPTION.md new file mode 100644 index 00000000..6fc25427 --- /dev/null +++ b/sale_order_secondary_unit_convert/readme/DESCRIPTION.md @@ -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. diff --git a/sale_order_secondary_unit_convert/static/description/index.html b/sale_order_secondary_unit_convert/static/description/index.html new file mode 100644 index 00000000..5e8409dc --- /dev/null +++ b/sale_order_secondary_unit_convert/static/description/index.html @@ -0,0 +1,410 @@ + + + + + +Sale Order Secondary Unit Convert + + + +
+

Sale Order Secondary Unit Convert

+ + +

Beta License: AGPL-3 qrtl/hls-custom

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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 project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/sale_order_secondary_unit_convert/views/sale_order_views.xml b/sale_order_secondary_unit_convert/views/sale_order_views.xml new file mode 100644 index 00000000..4b0bde95 --- /dev/null +++ b/sale_order_secondary_unit_convert/views/sale_order_views.xml @@ -0,0 +1,31 @@ + + + + + sale.order.form.secondary.unit.internal + sale.order + + + + + + + + + +