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.

33 lines
1.2 KiB

  1. # Copyright 2018 Tecnativa - Carlos Dauden
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class ContractContract(models.Model):
  5. _inherit = 'contract.contract'
  6. invoicing_sales = fields.Boolean(
  7. string='Invoice Pending Sales Orders',
  8. help='If checked include sales with same analytic account to invoice '
  9. 'in contract invoice creation.',
  10. )
  11. @api.multi
  12. def _recurring_create_invoice(self, date_ref=False):
  13. invoices = super()._recurring_create_invoice(date_ref)
  14. for rec in self:
  15. if not rec.invoicing_sales:
  16. return invoices
  17. sales = self.env['sale.order'].search([
  18. ('analytic_account_id', '=', rec.group_id.id),
  19. ('partner_invoice_id', 'child_of',
  20. rec.partner_id.commercial_partner_id.ids),
  21. ('invoice_status', '=', 'to invoice'),
  22. ('date_order', '<=',
  23. '{} 23:59:59'.format(rec.recurring_next_date)),
  24. ])
  25. if sales:
  26. invoice_ids = sales.action_invoice_create()
  27. invoices |= self.env['account.invoice'].browse(invoice_ids)[:1]
  28. return invoices