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.

32 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 AccountAnalyticAccount(models.Model):
  5. _inherit = 'account.analytic.account'
  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 _create_invoice(self, invoice=False):
  13. if not self.invoicing_sales:
  14. return super(AccountAnalyticAccount, self)._create_invoice()
  15. sales = self.env['sale.order'].search([
  16. ('analytic_account_id', '=', self.id),
  17. ('partner_invoice_id', 'child_of',
  18. self.partner_id.commercial_partner_id.ids),
  19. ('invoice_status', '=', 'to invoice'),
  20. ('date_order', '<=',
  21. '{} 23:59:59'.format(self.recurring_next_date)),
  22. ])
  23. if sales:
  24. invoice_ids = sales.action_invoice_create()
  25. invoice = self.env['account.invoice'].browse(invoice_ids)[:1]
  26. return super(AccountAnalyticAccount, self)._create_invoice(
  27. invoice=invoice)