Browse Source

[IMP] - improve post_init_hook and _generate_forecast_periods

pull/283/head
sbejaoui 6 years ago
parent
commit
71a88097b9
  1. 14
      contract_forecast/hooks.py
  2. 9
      contract_forecast/models/contract_line.py

14
contract_forecast/hooks.py

@ -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(
[('is_canceled', '=', False)]
)
for contract_line in contract_lines:
contract_line.with_delay()._generate_forecast_periods()
offset = 0
while True:
contract_lines = env["account.analytic.invoice.line"].search(
[('is_canceled', '=', False)], limit=100, offset=offset
)
contract_lines.with_delay()._generate_forecast_periods()
if len(contract_lines) < 100:
break
offset += 100

9
contract_forecast/models/contract_line.py

@ -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._generate_forecast_periods()
rec.with_delay()._generate_forecast_periods()
return res return res
Loading…
Cancel
Save