From a6acf9e5e99348b897c67e029b69dbf1a40e9d9c Mon Sep 17 00:00:00 2001 From: flora Date: Thu, 26 Jul 2018 11:29:38 +0800 Subject: [PATCH] =?UTF-8?q?[ADD]=E9=94=80=E8=B4=A7=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=B8=8A=E5=A2=9E=E5=8A=A0=E5=87=80=E9=87=8D=E5=90=88=E8=AE=A1?= =?UTF-8?q?=E5=8F=8A=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sell/models/sell_order.py | 8 ++++++++ sell/tests/test_sell_order.py | 6 ++++++ 2 files changed, 14 insertions(+) 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):