From 87b77a2e5d989a3a0e2097eaa4d67af724eb2110 Mon Sep 17 00:00:00 2001 From: jmartin Date: Mon, 2 Mar 2015 16:03:29 +0100 Subject: [PATCH] Fix AttributeError: 'NoneType' object has no attribute 'id' when party is created before company and has not any default account receivable defined --- sale.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sale.py b/sale.py index 91107a9..29c3980 100644 --- a/sale.py +++ b/sale.py @@ -113,6 +113,8 @@ class WizardSalePayment(Wizard): 'has not been created.'), 'not_customer_invoice': ('A customer invoice/refund ' 'from sale device has not been created.'), + 'party_without_account_receivable': 'Party %s has no any ' + 'account receivable defined. Please, assign one.', }) def default_start(self, fields): @@ -155,13 +157,18 @@ class WizardSalePayment(Wizard): if not sale.reference: Sale.set_reference([sale]) + account = (sale.party.account_receivable + and sale.party.account_receivable.id + or self.raise_user_error('party_without_account_receivable', + error_args=(sale.party.name,))) + if form.payment_amount: payment = StatementLine( statement=statements[0].id, date=Date.today(), amount=form.payment_amount, party=sale.party.id, - account=sale.party.account_receivable.id, + account=account, description=sale.reference, sale=active_id )