Skip to content
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

[15.0][IMP] product_secondary_unit: Add helper method to secondary units to get secondary qty computed #1469

Merged
Merged
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
11 changes: 11 additions & 0 deletions product_secondary_unit/models/product_second_unit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# 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 ProductSecondaryUnit(models.Model):
Expand Down Expand Up @@ -67,3 +68,13 @@
name=name, args=args, operator=operator, limit=limit
)
return units.name_get()

def _get_secondary_qty(self, qty, uom, product_uom_field="uom_id"):
"""Helper method to obtain the secondary uom quantity from a given main unit"""
self.ensure_one()
factor = self.factor * (

Check warning on line 75 in product_secondary_unit/models/product_second_unit.py

View check run for this annotation

Codecov / codecov/patch

product_secondary_unit/models/product_second_unit.py#L74-L75

Added lines #L74 - L75 were not covered by tests
uom.factor if self.product_id[product_uom_field] != uom else 1.0
)
return float_round(

Check warning on line 78 in product_secondary_unit/models/product_second_unit.py

View check run for this annotation

Codecov / codecov/patch

product_secondary_unit/models/product_second_unit.py#L78

Added line #L78 was not covered by tests
qty / (factor or 1.0), precision_rounding=self.uom_id.rounding
)
Loading