assert len(self) == 1, 'This option should only be used for a single id at a time.'
template = self.env.ref('account.email_template_edi_invoice', False)
compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)
- ctx = dict(self._context,
+ ctx = dict(
default_model='account.invoice',
default_res_id=self.id,
default_use_template=bool(template),
for tax in self.tax_line:
if tax.manual:
continue
- key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id, tax.account_analytic_id.id)
+ key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id)
tax_key.append(key)
if key not in compute_taxes:
raise except_orm(_('Warning!'), _('Global taxes defined, but they are not in invoice lines !'))
continue
ctx = dict(self._context, lang=inv.partner_id.lang)
- date_invoice = inv.date_invoice or fields.Date.context_today(self)
+
+ if not inv.date_invoice:
+ inv.with_context(ctx).write({'date_invoice': fields.Date.context_today(self)})
+ date_invoice = inv.date_invoice
company_currency = inv.company_id.currency_id
# create the analytical lines, one move line per invoice line
move = account_move.with_context(ctx).create(move_vals)
# make the invoice point to that move
vals = {
- 'date_invoice': date_invoice,
'move_id': move.id,
'period_id': period.id,
'move_name': move.name,
val['account_id'] = tax['account_paid_id'] or line.account_id.id
val['account_analytic_id'] = tax['account_analytic_paid_id']
- key = (val['tax_code_id'], val['base_code_id'], val['account_id'], val['account_analytic_id'])
+ # If the taxes generate moves on the same financial account as the invoice line
+ # and no default analytic account is defined at the tax level, propagate the
+ # analytic account from the invoice line to the tax line. This is necessary
+ # in situations were (part of) the taxes cannot be reclaimed,
+ # to ensure the tax move is allocated to the proper analytic account.
+ if not val.get('account_analytic_id') and line.account_analytic_id and val['account_id'] == line.account_id.id:
+ val['account_analytic_id'] = line.account_analytic_id.id
+
+ key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
if not key in tax_grouped:
tax_grouped[key] = val
else: