From 37a2f426a9b2ae6db40a68f3abef529fed11ee74 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 19 Aug 2015 14:26:04 +0200 Subject: [PATCH] [FIX] hr_timesheet_invoice: invoice timesheet of contract with no customer If there is no partner on the contract to which are invoiced the timesheets, the error telling you to set a partner (and a pricelist) must be raised before trying to create the invoice, not before creating the lines of the invoice. In this case, this is because if you set no customer on the contract, there is no pricelist automatically filled as well, and the currency is took from the pricelist, which will be False in the case there is no pricelist on the contract, and you cannot create an invoice with no currency set. opw-647672 --- addons/hr_timesheet_invoice/hr_timesheet_invoice.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index 96e8125a4e2..fa895c7e7a9 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -273,7 +273,10 @@ class account_analytic_line(osv.osv): for (key_id, company_id, currency_id), analytic_lines in invoice_grouping.items(): # key_id is an account.analytic.account - partner = analytic_lines[0].account_id.partner_id # will be the same for every line + account = analytic_lines[0].account_id + partner = account.partner_id # will be the same for every line + if (not partner) or not (currency_id): + raise osv.except_osv(_('Error!'), _('Contract incomplete. Please fill in the Customer and Pricelist fields for %s.') % (account.name)) curr_invoice = self._prepare_cost_invoice(cr, uid, partner, company_id, currency_id, analytic_lines, context=context) invoice_context = dict(context, @@ -288,8 +291,6 @@ class account_analytic_line(osv.osv): invoice_lines_grouping = {} for analytic_line in analytic_lines: account = analytic_line.account_id - if (not partner) or not (account.pricelist_id): - raise osv.except_osv(_('Error!'), _('Contract incomplete. Please fill in the Customer and Pricelist fields for %s.') % (account.name)) if not analytic_line.to_invoice: raise osv.except_osv(_('Error!'), _('Trying to invoice non invoiceable line for %s.') % (analytic_line.product_id.name))