From 85b08a75f616ff412a36a96ac5ae3c52e06898f1 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 18 Aug 2014 17:50:32 +0200 Subject: [PATCH] [FIX] account_voucher: avoid error if no partner The field partner_id is not required on an account.voucher but the validation was failing if none was set (opw 611663). This patch makes a fallback on the account of the voucher if neither a partner nor a writeoff account is specified. --- addons/account_voucher/account_voucher.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index ce6a35adb32..3b0bfe80ba4 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -1337,10 +1337,14 @@ class account_voucher(osv.osv): if voucher.payment_option == 'with_writeoff': account_id = voucher.writeoff_acc_id.id write_off_name = voucher.comment - elif voucher.type in ('sale', 'receipt'): - account_id = voucher.partner_id.property_account_receivable.id + elif voucher.partner_id: + if voucher.type in ('sale', 'receipt'): + account_id = voucher.partner_id.property_account_receivable.id + else: + account_id = voucher.partner_id.property_account_payable.id else: - account_id = voucher.partner_id.property_account_payable.id + # fallback on account of voucher + account_id = voucher.account_id.id sign = voucher.type == 'payment' and -1 or 1 move_line = { 'name': write_off_name or name,