-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstock.py
66 lines (53 loc) · 1.72 KB
/
stock.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
stock.py
"""
from trytond.pool import PoolMeta, Pool
__metaclass__ = PoolMeta
__all__ = ['StockMove']
class StockMove:
"Stock move"
__name__ = "stock.move"
@classmethod
def __setup__(cls):
super(StockMove, cls).__setup__()
cls._error_messages.update({
'weight_required':
'Weight for product %s in stock move is missing',
})
def get_weight(self, weight_uom, silent=False):
"""
Returns weight as required for carrier
:param weight_uom: Weight uom used by carrier
:param silent: Raise error if not silent
"""
ProductUom = Pool().get('product.uom')
if self.quantity <= 0:
return 0
if not self.product.weight:
if silent:
return 0
self.raise_user_error(
'weight_required',
error_args=(self.product.name,)
)
# Find the quantity in the default uom of the product as the weight
# is for per unit in that uom
if self.uom != self.product.default_uom:
quantity = ProductUom.compute_qty(
self.uom,
self.quantity,
self.product.default_uom
)
else:
quantity = self.quantity
weight = self.product.weight * quantity
# Compare product weight uom with the weight uom used by carrier
# and calculate weight if botth are not same
if self.product.weight_uom.symbol != weight_uom.symbol:
weight = ProductUom.compute_qty(
self.product.weight_uom,
weight,
weight_uom
)
return weight