Fix required computation when line has no purchase

issue7281
review41221002
This commit is contained in:
Cédric Krier
2018-03-30 18:14:21 +02:00
parent 6b56c40491
commit 06cd7eadcb
2 changed files with 10 additions and 4 deletions
+4 -3
View File
@@ -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')
+6 -1
View File
@@ -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')