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.

29 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from openerp import api, models
  6. class AccountAnalyticAccount(models.Model):
  7. _inherit = 'account.analytic.account'
  8. @api.multi
  9. def _recurring_create_invoice(self, automatic=False):
  10. invoice_ids = super(
  11. AccountAnalyticAccount, self)._recurring_create_invoice(automatic)
  12. invoices = self.env['account.invoice'].browse(invoice_ids)
  13. res = []
  14. invoices2unlink = 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. result = invoices2merge.do_merge()
  20. res += result.keys()
  21. invoices2unlink += invoices2merge
  22. else:
  23. res += invoices2merge.ids
  24. invoices2unlink.unlink()
  25. return res