diff --git a/sell/models/sell_order.py b/sell/models/sell_order.py index bff3ec6a4..2e055bb58 100644 --- a/sell/models/sell_order.py +++ b/sell/models/sell_order.py @@ -80,6 +80,12 @@ def _compute_delivery(self): order.delivery_count = len([deli for deli in order.delivery_ids if not deli.is_return]) order.return_count = len([deli for deli in order.delivery_ids if deli.is_return]) + @api.one + @api.depends('line_ids.goods_id', 'line_ids.quantity') + def _compute_net_weight(self): + '''计算净重合计''' + self.net_weight = sum(line.goods_id.net_weight * line.quantity for line in self.line_ids) + partner_id = fields.Many2one('partner', u'客户', ondelete='restrict', states=READONLY_STATES, help=u'签约合同的客户') @@ -194,6 +200,8 @@ def _compute_delivery(self): readonly=True, copy=False, help=u'输入预收款确认时产生的预收款单') + net_weight = fields.Float( + string=u'净重合计', compute='_compute_net_weight', store=True) @api.onchange('address_id') def onchange_partner_address(self): diff --git a/sell/tests/test_sell_order.py b/sell/tests/test_sell_order.py index 1408b9325..aaa7752f8 100644 --- a/sell/tests/test_sell_order.py +++ b/sell/tests/test_sell_order.py @@ -225,6 +225,12 @@ def test_sell_order_done_no_attribute(self): with self.assertRaises(UserError): self.order.sell_order_done() + def test_compute_net_weight(self): + '''计算净重合计''' + self.env.ref('goods.mouse').net_weight = 50 + self.order.line_ids[0].quantity = 10 + self.assertEqual(self.order.net_weight, 50 * 10) + class TestSellOrderLine(TransactionCase):