Skip to content

Commit

Permalink
[IMP] crm(_iap_lead_enrich): correctly enable / disable the enrich CRON
Browse files Browse the repository at this point in the history
Purpose
=======
The parameter "lead_enrich_auto" enable or disable the enrich CRON.

This is done in an onchange and so, if we enable manually the CRON, the
change will not be reflected on the parameter.

Task 2443338

closes odoo#65007

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
  • Loading branch information
std-odoo committed Jan 29, 2021
1 parent 2dd697f commit 8e7cfb6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions addons/crm_iap_lead_enrich/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

@api.onchange('lead_enrich_auto')
def _onchange_cron_lead_enrich(self):
""" change the active status of the cron according to the settings"""
if self.module_crm_iap_lead_enrich == True:
cron = self.sudo().with_context(active_test=False).env.ref('crm_iap_lead_enrich.ir_cron_lead_enrichment')
if cron:
cron.active = self.lead_enrich_auto != 'manual'
@api.model
def get_values(self):
values = super(ResConfigSettings, self).get_values()
cron = self.sudo().with_context(active_test=False).env.ref('crm_iap_lead_enrich.ir_cron_lead_enrichment', raise_if_not_found=False)
values['lead_enrich_auto'] = 'auto' if cron and cron.active else 'manual'
return values

def set_values(self):
super(ResConfigSettings, self).set_values()
cron = self.sudo().with_context(active_test=False).env.ref('crm_iap_lead_enrich.ir_cron_lead_enrichment', raise_if_not_found=False)
if cron:
cron.active = self.lead_enrich_auto == 'auto'

0 comments on commit 8e7cfb6

Please sign in to comment.