forked from techspawn/total_weight_reckoner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsale_order_weight.py
39 lines (29 loc) · 1.41 KB
/
sale_order_weight.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
from openerp import models, fields, api
class SaleWeight(models.Model):
_inherit = 'sale.order.line'
so_weight = fields.Float(string='Gross Weight',
store=True,
related='product_id.weight')
so_net_weight = fields.Float(string='Net Weight',
store=True,
related='product_id.weight_net')
so_quantity = fields.Float(string='Quantity',
store=True,
related='product_uos_qty')
class SaleWeightOrder(models.Model):
_inherit = 'sale.order'
@api.depends('order_line.so_weight')
@api.depends('order_line.so_net_weight')
@api.depends('order_line.so_quantity')
def _calcweight(self):
currentweight = 0
for order_line in self.order_line:
currentweight = currentweight + (order_line.so_weight * order_line.so_quantity)
self.so_weight_total = currentweight
so_weight_total = fields.Float(compute='_calcweight', string='Total Gross Weight')
def _calcweight_net(self):
currentweight_net = 0
for order_line in self.order_line:
currentweight_net = currentweight_net + (order_line.so_net_weight * order_line.so_quantity)
self.so_net_weight_total = currentweight_net
so_net_weight_total = fields.Float(compute='_calcweight_net', string='Total Net Weight')