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.

31 lines
1.1 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. if not self.invoicing_sales:
  15. return invoices
  16. sales = self.env['sale.order'].search([
  17. ('analytic_account_id', '=', self.analytic_account_id.id),
  18. ('partner_invoice_id', 'child_of',
  19. self.partner_id.commercial_partner_id.ids),
  20. ('invoice_status', '=', 'to invoice'),
  21. ('date_order', '<=',
  22. '{} 23:59:59'.format(self.recurring_next_date)),
  23. ])
  24. if sales:
  25. invoice_ids = sales.action_invoice_create()
  26. invoices |= self.env['account.invoice'].browse(invoice_ids)[:1]