mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
Merge pull request #261 from Tecnativa/11.0-imp-cron_limit
[11.0] contract: allow to limit records on cron
This commit is contained in:
@@ -278,13 +278,18 @@ class AccountAnalyticAccount(models.Model):
|
||||
return invoice
|
||||
|
||||
@api.multi
|
||||
def recurring_create_invoice(self):
|
||||
def recurring_create_invoice(self, limit=None):
|
||||
"""Create invoices from contracts
|
||||
|
||||
:param int limit:
|
||||
Max of invoices to create.
|
||||
|
||||
:return: invoices created
|
||||
"""
|
||||
invoices = self.env['account.invoice']
|
||||
for contract in self:
|
||||
if limit and len(invoices) >= limit:
|
||||
break
|
||||
ref_date = contract.recurring_next_date or fields.Date.today()
|
||||
if (contract.date_start > ref_date or
|
||||
contract.date_end and contract.date_end < ref_date):
|
||||
@@ -312,7 +317,7 @@ class AccountAnalyticAccount(models.Model):
|
||||
return invoices
|
||||
|
||||
@api.model
|
||||
def cron_recurring_create_invoice(self):
|
||||
def cron_recurring_create_invoice(self, limit=None):
|
||||
today = fields.Date.today()
|
||||
contracts = self.with_context(cron=True).search([
|
||||
('recurring_invoices', '=', True),
|
||||
@@ -321,7 +326,7 @@ class AccountAnalyticAccount(models.Model):
|
||||
('date_end', '=', False),
|
||||
('date_end', '>=', today),
|
||||
])
|
||||
return contracts.recurring_create_invoice()
|
||||
return contracts.recurring_create_invoice(limit=limit)
|
||||
|
||||
@api.multi
|
||||
def action_contract_send(self):
|
||||
|
||||
Reference in New Issue
Block a user