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

[14.0][FIX] base_delivery_carrier_label: fix weight computation logic #802

Closed
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
55 changes: 21 additions & 34 deletions base_delivery_carrier_label/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,34 @@
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import fields, models

_logger = logging.getLogger(__name__)
from odoo.tools import float_round


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

weight = fields.Float(digits="Stock Weight", help="Weight of the pack_operation")
weight = fields.Float(digits="Stock Weight")

def get_weight(self):
"""Calc and save weight of pack.operations.

Warning: Type conversion not implemented
it will return False if at least one uom or uos not in kg
return:
the sum of the weight of [self]
"""
total_weight = 0
kg = self.env.ref("uom.product_uom_kgm").id
units = self.env.ref("uom.product_uom_unit").id
allowed = (False, kg, units)
cant_calc_total = False
for operation in self:
product = operation.product_id

# if not defined we assume it's in kg
if product.uom_id.id not in allowed:
_logger.warning(
"Type conversion not implemented for product %s" % product.id
prec = self.env["decimal.precision"].precision_get("Stock Weight")
weight_uom_categ_id = self.env.ref("uom.product_uom_categ_kgm").id
ref_weight_uom = self.env[
"product.template"
]._get_weight_uom_id_from_ir_config_parameter()
total_weight = 0.0
for line in self:
product = line.product_id
if line.product_uom_id.category_id.id == weight_uom_categ_id:
total_weight += line.product_uom_id._compute_quantity(
line.qty_done, ref_weight_uom, round=False
)
cant_calc_total = True
# product_qty may be 0 if you don't set move line
# individually but directly validate the picking
qty = operation.qty_done or operation.product_qty
operation.weight = product.weight * qty

total_weight += operation.weight

if cant_calc_total:
return False
return total_weight
else:
total_weight += (
line.product_uom_id._compute_quantity(
line.qty_done, product.uom_id, round=False
)
* product.weight
)
return float_round(total_weight, precision_digits=prec)
Loading
Loading