From 06cd7eadcbd6540fdf3a94792cd5faf7f8f55b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 30 Mar 2018 18:14:21 +0200 Subject: [PATCH] Fix required computation when line has no purchase issue7281 review41221002 --- purchase.py | 7 ++++--- tests/scenario_analytic_purchase.rst | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/purchase.py b/purchase.py index 94c8841c15..08f847e943 100644 --- a/purchase.py +++ b/purchase.py @@ -91,9 +91,10 @@ class AnalyticAccountEntry: PurchaseLine = pool.get('purchase.line') required = super(AnalyticAccountEntry, self).on_change_with_required( name) - if (self.origin and isinstance(self.origin, PurchaseLine) - and self.origin.purchase.state in ['cancel', 'draft']): - return False + if isinstance(self.origin, PurchaseLine): + if (not self.origin.purchase + or self.origin.purchase.state in ['cancel', 'draft']): + return False return required @fields.depends('origin') diff --git a/tests/scenario_analytic_purchase.rst b/tests/scenario_analytic_purchase.rst index 7d6490ea3e..846fe021c3 100644 --- a/tests/scenario_analytic_purchase.rst +++ b/tests/scenario_analytic_purchase.rst @@ -112,11 +112,16 @@ Purchase with analytic accounts:: >>> mandatory_entry.root == mandatory_root True >>> bool(mandatory_entry.required) - True + False >>> purchase_line.product = product >>> purchase_line.quantity = 5 >>> mandatory_entry.account = mandatory_analytic_account >>> purchase.click('quote') + >>> purchase_line, = purchase.lines + >>> mandatory_entry, = [a for a in purchase_line.analytic_accounts + ... if a.root == mandatory_root] + >>> bool(mandatory_entry.required) + True >>> purchase.click('confirm') >>> purchase.click('process')