You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  4. # Copyright 2017 Vicent Cubells <vicent.cubells@tecnativa.com>
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  6. from openerp import api, models
  7. class AccountAnalyticAccount(models.Model):
  8. _inherit = 'account.analytic.account'
  9. @api.multi
  10. def recurring_create_invoice(self):
  11. invoices = super(
  12. AccountAnalyticAccount, self).recurring_create_invoice()
  13. invoices_info = {}
  14. invoices2unlink = AccountInvoice = self.env['account.invoice']
  15. for partner in invoices.mapped('partner_id'):
  16. invoices2merge = invoices.filtered(
  17. lambda x: x.partner_id == partner)
  18. if partner.contract_invoice_merge and len(invoices2merge) > 1:
  19. invoices_info.update(invoices2merge.do_merge())
  20. invoices2unlink += invoices2merge
  21. invoices -= invoices2unlink
  22. invoices2unlink.unlink()
  23. return invoices | AccountInvoice.browse(invoices_info.keys())