Skip to content

Commit

Permalink
Merge PR #40 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Oct 30, 2019
2 parents 2170722 + fe08ad7 commit 1e83c76
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 60 deletions.
2 changes: 1 addition & 1 deletion connector_equipment/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _connect(self, function, serviceprofiles=None):
for sp_id in serviceprofiles:
self.remove_service(sp_id)

@api.multi
@api.model
def create(self, vals):
res = super().create(vals)
if self.managed:
Expand Down
174 changes: 120 additions & 54 deletions connector_equipment_service/models/agreement_serviceprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,135 @@
class AgreementServiceProfile(models.Model):
_inherit = ['agreement.serviceprofile']

@api.multi
def write(self, vals):
# If equipment was empty and now set to managed equipment
if vals.get('equipment_id', False) and not self.equipment_id:
@api.model
def create(self, vals):
# If SP is created with a managed equipment
if vals.get('equipment_id', False):
new = self.env['maintenance.equipment'].\
browse(vals.get('equipment_id'))
new._connect('add_service', serviceprofiles=self)
new._connect('add_service',
serviceprofiles=self)
return super().create(vals)

@api.multi
def write(self, vals):
equip_id = self.get_equip(vals)
# Add Service
# If equipment was empty and now set to managed or stage in draft
if equip_id and (not self.equipment_id or
self.get_stage(vals) == 'draft'):
equip_id._connect('add_service', serviceprofiles=self)
self.message_post(body=_('Added Service'))

# Update Service
# If SP is changed but not the managed equipment
if 'equipment_id' not in vals and self.equipment_id.managed:
if 'equipment_id' not in vals and equip_id:
self.equipment_id._connect('update_service',
serviceprofiles=self)
self.message_post(body=_('Updated Service'))
# If SP state is changed to In Progress and equipment is managed
if (vals.get('stage_id', False) == self.env.
ref('contract.servpro_stage_progress').id and
self.equipment_id.managed):
self.equipment_id._connect('activate_service',
serviceprofiles=self)

# Activate Service (Provision?)
# If SP state -> In Progress and equipment is managed
if self.get_stage(vals) == 'in_progress' and equip_id:
equip_id._connect('activate_service',
serviceprofiles=self)
self.message_post(body=_('Activated Service'))
# If SP state is changed to Suspend and equipment is managed
if (vals.get('stage_id', False) == self.env.
ref('contract.servpro_stage_suspend').id and
self.equipment_id.managed):
self.equipment_id._connect('suspend_service',
serviceprofiles=self)

# Suspend Service
# If SP state -> Suspend and equipment is managed
if self.get_stage(vals) == 'suspend' and equip_id:
equip_id._connect('suspend_service',
serviceprofiles=self)
self.message_post(body=_('Suspended Service'))

# Suspend/Remove Service
# If SP state -> Closed or Cancelled and equipment is managed
if self.get_stage(vals) in ['closed', 'cancelled'] and equip_id:
equip_id._connect('suspend_service',
serviceprofiles=self)
equip_id._connect('remove_service',
serviceprofiles=self)
self.message_post(body=_('Suspended Service'))
# If equipment was a managed equipment and is changed to False
if 'equipment_id' in vals and self.equipment_id.managed:
if not vals['equipment_id']:
self.message_post(body=_('Removed Service'))

# If equipment was changed, handle old equipment accordingly
if vals.get('equipment_id', False):
self.equip_changed(vals)

return super().write(vals)

# This method handles the old equipment if it is changed
def equip_changed(self, vals):
# Was the old Equipment Managed?
if self.equipment_id.managed:
# Is the SP In Progress (or going to be)
if self.get_stage(vals) in ['in_progress', 'to_renew']:
# Suspend
self.equipment_id._connect('suspend_service',
serviceprofiles=self)
self.message_post(body=_('Previous Service Suspended'))
# SP is not In Progress (or going to be)
else:
# Remove
self.equipment_id._connect('remove_service',
serviceprofiles=self)
self.message_post(body=_('Removed Service'))
# If equipment is changed to another equipment
if vals.get('equipment_id', False) and self.equipment_id:
# If previous equipment is managed
if self.equipment_id.managed:
# SP is Active (or going to be)
if ((self.stage_id.id == self.env.
ref('contract.servpro_stage_progress').id and
not vals.get('stage_id', False))
or vals.get('stage_id', False) == self.env.
ref('contract.servpro_stage_progress').id):
self.equipment_id._connect('suspend_service',
serviceprofiles=self)
self.message_post(body=_('Previous Service Suspended'))
else:
self.equipment_id._connect('remove_service',
serviceprofiles=self)
self.message_post(body=_('Previous Service Removed'))
# If new equipment is managed and SP is Active (or going to be)
new = self.env['maintenance.equipment'].\
self.message_post(body=_('Previous Service Removed'))

# This method returns the final equipment on the form
# If there is a managed equipment in vals, use it
# If there is not, check self for managed equipment
# If neither, return False
def get_equip(self, vals):
equip = vals.get('equipment_id', False)
if equip:
equip = self.env['maintenance.equipment'].\
browse(vals.get('equipment_id'))
if new.managed:
# SP is Active (or going to be)
if ((self.stage_id.id == self.env.
ref('contract.servpro_stage_progress').id and
not vals.get('stage_id', False))
or vals.get('stage_id', False) == self.env.
ref('contract.servpro_stage_progress').id):
new._connect('activate_service', serviceprofiles=self)
self.message_post(body=_('New Service Activated'))
else:
new._connect('add_service', serviceprofiles=self)
self.message_post(body=_('New Service Added'))
return super().write(vals)
if equip.managed:
return equip
else:
if self.equipment_id.managed:
return self.equipment_id
return False

# This method returns the appriopriate stage_id
# If there is a stage in vals, use it
# If there is no stage in vals, use the current stage
def get_stage(self, vals):
x = ''
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_draft').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_draft').id)):
x = 'draft'
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_progress').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_progress').id)):
x = 'in_progress'
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_suspend').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_suspend').id)):
x = 'suspend'
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_renew').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_renew').id)):
x = 'to_renew'
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_close').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_close').id)):
x = 'closed'
if ((vals.get('stage_id', False) == self.env.
ref('agreement_serviceprofile.servpro_stage_cancel').id) or
(not vals.get('stage_id', False) and
self.stage_id.id == self.env.
ref('agreement_serviceprofile.servpro_stage_cancel').id)):
x = 'cancel'
return x
15 changes: 10 additions & 5 deletions connector_equipment_service/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ class MaintenanceEquipment(models.Model):

@api.multi
def add_service(self, service_profile):
raise NotImplementedError()
return False
# raise NotImplementedError()

@api.multi
def update_service(self, service_profile):
raise NotImplementedError()
return False
# raise NotImplementedError()

@api.multi
def activate_service(self, service_profile):
raise NotImplementedError()
return False
# raise NotImplementedError()

@api.multi
def suspend_service(self, service_profile):
raise NotImplementedError()
return False
# raise NotImplementedError()

@api.multi
def remove_service(self, service_profile):
raise NotImplementedError()
return False
# raise NotImplementedError()

0 comments on commit 1e83c76

Please sign in to comment.