-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
stock_move_line.py
48 lines (37 loc) · 1.51 KB
/
stock_move_line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright 2016 Hpar
# 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__)
class StockMoveLine(models.Model):
_inherit = "stock.move.line"
weight = fields.Float(digits="Stock Weight", help="Weight of the pack_operation")
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
)
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