Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] fieldservice: Minor changes #491

Merged
merged 5 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions fieldservice/models/fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FSMLocation(models.Model):
group_expand='_read_group_stage_ids',
default=lambda self: self._default_stage_id())

@api.depends('partner_id.name', 'fsm_parent_id.complete_name')
@api.depends('partner_id.name', 'fsm_parent_id.complete_name', 'ref')
def _compute_complete_name(self):
for loc in self:
if loc.fsm_parent_id:
Expand Down Expand Up @@ -258,16 +258,16 @@ def action_view_contacts(self):
read()[0]
contacts = self.get_action_views(1, 0, location)
action['context'] = self.env.context.copy()
action['context'].update({'group_by': ''})
action['context'].update({'default_service_location_id': self.id})
if len(contacts) == 1:
action['views'] = [(self.env.ref('base.view_partner_form').id,
if len(contacts) == 0 or len(contacts) > 1:
action['domain'] = [('id', 'in', contacts.ids)]
elif contacts:
action['views'] = [(self.env.
ref('base.' +
'view_partner_form').id,
'form')]
action['res_id'] = contacts.id
action['context'].update({'active_id': contacts.id})
else:
action['domain'] = [('id', 'in', contacts.ids)]
action['context'].update({'active_ids': contacts.ids})
action['context'].update({'active_id': ''})
return action
osi-scampbell marked this conversation as resolved.
Show resolved Hide resolved

@api.multi
Expand All @@ -288,6 +288,7 @@ def action_view_equipment(self):
read()[0]
equipment = self.get_action_views(0, 1, location)
action['context'] = self.env.context.copy()
action['context'].update({'group_by': ''})
action['context'].update({'default_location_id': self.id})
if len(equipment) == 0 or len(equipment) > 1:
action['domain'] = [('id', 'in', equipment.ids)]
Expand Down Expand Up @@ -316,6 +317,7 @@ def action_view_sublocation(self):
action = self.env.ref('fieldservice.action_fsm_location').read()[0]
sublocation = self.get_action_views(0, 0, location)
action['context'] = self.env.context.copy()
action['context'].update({'group_by': ''})
action['context'].update({'default_fsm_parent_id': self.id})
if len(sublocation) > 1 or len(sublocation) == 0:
action['domain'] = [('id', 'in', sublocation.ids)]
Expand Down
34 changes: 22 additions & 12 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta
from odoo import api, fields, models, _
from . import fsm_stage
from odoo.exceptions import ValidationError
from odoo.exceptions import ValidationError, UserError


class FSMOrder(models.Model):
Expand Down Expand Up @@ -225,8 +225,16 @@ def create(self, vals):
from_string(vals.get('request_early')) + timedelta(hours=8)
return super(FSMOrder, self).create(vals)

is_button = fields.Boolean(default=False)

@api.multi
def write(self, vals):
if vals.get('stage_id', False) and vals.get('is_button', False):
vals['is_button'] = False
else:
stage_id = self.env['fsm.stage'].browse(vals.get('stage_id'))
if stage_id == self.env.ref('fieldservice.fsm_stage_completed'):
raise UserError(_('Cannot move to completed from Kanban'))
self._calc_scheduled_dates(vals)
res = super(FSMOrder, self).write(vals)
return res
Expand Down Expand Up @@ -283,7 +291,7 @@ def _calc_scheduled_dates(self, vals):

def action_complete(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_completed').id})
'fieldservice.fsm_stage_completed').id, 'is_button': True})

def action_cancel(self):
return self.write({'stage_id': self.env.ref(
Expand All @@ -306,37 +314,39 @@ def onchange_scheduled_duration(self):
self.scheduled_date_end = str(date_to_with_delta)

def copy_notes(self):
old_desc = self.description
self.description = ""
self.location_directions = ""
if self.type and self.type.name not in ['repair', 'maintenance']:
for equipment_id in self.equipment_ids:
if equipment_id:
if equipment_id.notes is not False:
if self.description is not False:
if equipment_id.notes:
if self.description:
self.description = (self.description +
equipment_id.notes + '\n ')
else:
self.description = (equipment_id.notes + '\n ')
else:
if self.equipment_id:
if self.equipment_id.notes is not False:
if self.description is not False:
if self.equipment_id.notes:
if self.description:
self.description = (self.description +
self.equipment_id.notes + '\n ')
else:
self.description = (self.equipment_id.notes + '\n ')
if self.location_id:
s = self.location_id.direction
if s is not False and s != '<p><br></p>':
if s and s != '<p><br></p>':
s = s.replace('<p>', '')
s = s.replace('<br>', '')
s = s.replace('</p>', '\n')
if self.location_directions is not False:
self.location_directions = (self.location_directions +
'\n' + s + '\n')
else:
self.location_directions = (s + '\n ')
self.location_directions = (s + '\n ')
if self.template_id:
self.todo = self.template_id.instructions
if self.description:
self.description += '\n' + old_desc
else:
self.description = old_desc

@api.onchange('location_id')
def onchange_location_id(self):
Expand Down
1 change: 1 addition & 0 deletions fieldservice/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
type="object"
groups="fieldservice.group_fsm_dispatcher"
attrs="{'invisible': [('stage_id', 'in', (%(fieldservice.fsm_stage_completed)d, %(fieldservice.fsm_stage_cancelled)d))]}" />
<field name="is_button" invisible="1"/>
<button id="action_cancel"
name="action_cancel" string="Cancel Order"
type="object"
Expand Down