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.

34 lines
1.3 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, fields, models
  7. class AccountAnalyticAccount(models.Model):
  8. _inherit = 'account.analytic.account'
  9. @api.multi
  10. def recurring_create_invoice(self):
  11. contracts = self.search(
  12. [('recurring_next_date', '<=', fields.Date.today()),
  13. ('account_type', '=', 'normal'),
  14. ('recurring_invoices', '=', True)]
  15. )
  16. res = super(AccountAnalyticAccount, self).recurring_create_invoice()
  17. if not contracts:
  18. return res
  19. invoices = self.env['account.invoice'].search([
  20. ('contract_id', 'in', contracts.ids)
  21. ])
  22. invoices2unlink = self.env['account.invoice']
  23. for partner in invoices.mapped('partner_id'):
  24. invoices2merge = invoices.filtered(
  25. lambda x: x.partner_id == partner)
  26. if partner.contract_invoice_merge and len(invoices2merge) > 1:
  27. invoices2merge.do_merge()
  28. invoices2unlink += invoices2merge
  29. invoices2unlink.unlink()
  30. return True