mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-21 15:32:02 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -19,26 +19,29 @@ class OnboardingProgress(models.Model):
|
|||
onboarding_state = fields.Selection(
|
||||
ONBOARDING_PROGRESS_STATES, string='Onboarding progress', compute='_compute_onboarding_state', store=True)
|
||||
is_onboarding_closed = fields.Boolean('Was panel closed?')
|
||||
company_id = fields.Many2one('res.company')
|
||||
company_id = fields.Many2one('res.company', ondelete='cascade')
|
||||
onboarding_id = fields.Many2one(
|
||||
'onboarding.onboarding', 'Related onboarding tracked', required=True, ondelete='cascade')
|
||||
progress_step_ids = fields.One2many('onboarding.progress.step', 'progress_id', 'Progress Steps Trackers')
|
||||
_sql_constraints = [
|
||||
('onboarding_company_uniq', 'unique (onboarding_id,company_id)',
|
||||
'There cannot be multiple records of the same onboarding completion for the same company.'),
|
||||
]
|
||||
'onboarding.onboarding', 'Related onboarding tracked', required=True, index=True, ondelete='cascade')
|
||||
progress_step_ids = fields.Many2many('onboarding.progress.step', string='Progress Steps Trackers')
|
||||
|
||||
# not in _sql_constraint because COALESCE is not supported for PostgreSQL constraint
|
||||
_onboarding_company_uniq = models.UniqueIndex("(onboarding_id, COALESCE(company_id, 0))")
|
||||
|
||||
@api.depends('onboarding_id.step_ids', 'progress_step_ids', 'progress_step_ids.step_state')
|
||||
def _compute_onboarding_state(self):
|
||||
progress_steps_data = self.env['onboarding.progress.step'].read_group(
|
||||
[('progress_id', 'in', self.ids), ('step_state', 'in', ['just_done', 'done'])],
|
||||
['progress_id'], ['progress_id']
|
||||
)
|
||||
result = dict((data['progress_id'][0], data['progress_id_count']) for data in progress_steps_data)
|
||||
for progress in self:
|
||||
progress.onboarding_state = (
|
||||
'not_done' if result.get(progress.id, 0) != len(progress.onboarding_id.step_ids)
|
||||
else 'done')
|
||||
'not_done' if (
|
||||
len(progress.progress_step_ids.filtered(lambda p: p.step_state in {'just_done', 'done'}))
|
||||
!= len(progress.onboarding_id.step_ids)
|
||||
)
|
||||
else 'done'
|
||||
)
|
||||
|
||||
def _recompute_progress_step_ids(self):
|
||||
"""Update progress steps when a step (with existing progress) is added to an onboarding."""
|
||||
for progress in self:
|
||||
progress.progress_step_ids = progress.onboarding_id.step_ids.current_progress_step_id
|
||||
|
||||
def action_close(self):
|
||||
self.is_onboarding_closed = True
|
||||
|
|
@ -48,9 +51,11 @@ class OnboardingProgress(models.Model):
|
|||
progress.is_onboarding_closed = not progress.is_onboarding_closed
|
||||
|
||||
def _get_and_update_onboarding_state(self):
|
||||
"""Used to fetch the progress of an onboarding for rendering its panel and is expected to
|
||||
be called by the onboarding controller. It also has the responsibility of updating the
|
||||
'just_done' states into 'done' so that the 'just_done' states are only rendered once.
|
||||
"""Fetch the progress of an onboarding for rendering its panel.
|
||||
|
||||
This method is expected to only be called by the onboarding controller.
|
||||
It also has the responsibility of updating the 'just_done' state into
|
||||
'done' so that the 'just_done' states are only rendered once.
|
||||
"""
|
||||
self.ensure_one()
|
||||
onboarding_states_values = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue