mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - improve post_init_hook and _generate_forecast_periods
This commit is contained in:
@@ -19,8 +19,12 @@ def post_init_hook(cr, registry):
|
|||||||
)
|
)
|
||||||
with api.Environment.manage():
|
with api.Environment.manage():
|
||||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||||
contract_lines = env["account.analytic.invoice.line"].search(
|
offset = 0
|
||||||
[('is_canceled', '=', False)]
|
while True:
|
||||||
)
|
contract_lines = env["account.analytic.invoice.line"].search(
|
||||||
for contract_line in contract_lines:
|
[('is_canceled', '=', False)], limit=100, offset=offset
|
||||||
contract_line.with_delay()._generate_forecast_periods()
|
)
|
||||||
|
contract_lines.with_delay()._generate_forecast_periods()
|
||||||
|
if len(contract_lines) < 100:
|
||||||
|
break
|
||||||
|
offset += 100
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class AccountAnalyticInvoiceLine(models.Model):
|
|||||||
def _generate_forecast_periods(self):
|
def _generate_forecast_periods(self):
|
||||||
values = []
|
values = []
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
rec.forecast_period_ids.unlink()
|
||||||
if rec.recurring_next_date:
|
if rec.recurring_next_date:
|
||||||
last_date_invoiced = (
|
last_date_invoiced = (
|
||||||
rec.last_date_invoiced
|
rec.last_date_invoiced
|
||||||
@@ -99,11 +100,6 @@ class AccountAnalyticInvoiceLine(models.Model):
|
|||||||
)
|
)
|
||||||
return self.env["contract.line.forecast.period"].create(values)
|
return self.env["contract.line.forecast.period"].create(values)
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@job(default_channel=QUEUE_CHANNEL)
|
|
||||||
def _unlink_forecast_periods(self):
|
|
||||||
return self.mapped("forecast_period_ids").unlink()
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, values):
|
def create(self, values):
|
||||||
contract_lines = super(AccountAnalyticInvoiceLine, self).create(values)
|
contract_lines = super(AccountAnalyticInvoiceLine, self).create(values)
|
||||||
@@ -140,6 +136,5 @@ class AccountAnalyticInvoiceLine(models.Model):
|
|||||||
]
|
]
|
||||||
):
|
):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec._unlink_forecast_periods()
|
rec.with_delay()._generate_forecast_periods()
|
||||||
rec._generate_forecast_periods()
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user