Skip to content

Commit

Permalink
[IMP] fieldservice_activity: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
brian10048 committed Jul 22, 2020
1 parent 6192ef1 commit 740408f
Show file tree
Hide file tree
Showing 8 changed files with 861 additions and 557 deletions.
35 changes: 15 additions & 20 deletions fieldservice_activity/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
'name': 'Field Service Activity',
'summary': '''Field Service Activities are a set of actions
that need to be performed on a service order''',
'version': '12.0.1.0.0',
'category': 'Field Service',
'license': 'AGPL-3',
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/field-service',
'depends': [
'fieldservice'
],
'data': [
'views/fsm_order.xml',
'views/fsm_template.xml',
'security/ir.model.access.csv'
],
'development_status': 'Beta',
'maintainers': [
'max3903',
'osi-scampbell'
"name": "Field Service Activity",
"summary": """Field Service Activities are a set of actions
that need to be performed on a service order""",
"version": "12.0.1.0.0",
"category": "Field Service",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": ["fieldservice"],
"data": [
"views/fsm_order.xml",
"views/fsm_template.xml",
"security/ir.model.access.csv",
],
"development_status": "Beta",
"maintainers": ["max3903", "osi-scampbell"],
}
53 changes: 30 additions & 23 deletions fieldservice_activity/models/fsm_activity.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from datetime import datetime

from odoo import fields, models


class FSMActiity(models.Model):
_name = 'fsm.activity'
_description = 'Field Service Activity'
_name = "fsm.activity"
_description = "Field Service Activity"

name = fields.Char('Name', required=True,
readonly=True, states={'todo': [('readonly', False)]})
required = fields.Boolean('Requireid', default=False,
readonly=True,
states={'todo': [('readonly', False)]})
sequence = fields.Integer('Sequence')
completed = fields.Boolean('Completed', default=False)
completed_on = fields.Datetime('Completed On', readonly=True)
completed_by = fields.Many2one('res.users',
'Completed By', readonly=True,)
ref = fields.Char('Reference', readonly=True,
states={'todo': [('readonly', False)]})
fsm_order_id = fields.Many2one('fsm.order', 'FSM Order')
fsm_template_id = fields.Many2one('fsm.template', 'FSM Template')
state = fields.Selection([('todo', 'To Do'),
('done', 'Completed'),
('cancel', 'Cancelled')], 'State',
readonly=True, default='todo')
name = fields.Char(
"Name", required=True, readonly=True, states={"todo": [("readonly", False)]}
)
required = fields.Boolean(
"Requireid",
default=False,
readonly=True,
states={"todo": [("readonly", False)]},
)
sequence = fields.Integer("Sequence")
completed = fields.Boolean("Completed", default=False)
completed_on = fields.Datetime("Completed On", readonly=True)
completed_by = fields.Many2one("res.users", "Completed By", readonly=True)
ref = fields.Char(
"Reference", readonly=True, states={"todo": [("readonly", False)]}
)
fsm_order_id = fields.Many2one("fsm.order", "FSM Order")
fsm_template_id = fields.Many2one("fsm.template", "FSM Template")
state = fields.Selection(
[("todo", "To Do"), ("done", "Completed"), ("cancel", "Cancelled")],
"State",
readonly=True,
default="todo",
)

@api.multi
def action_done(self):
self.completed = True
self.completed_on = datetime.now()
self.completed_by = self.env.user
self.state = 'done'
self.state = "done"

@api.multi
def action_cancel(self):
self.state = 'cancel'
self.state = "cancel"
41 changes: 25 additions & 16 deletions fieldservice_activity/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
# Copyright (C) 2019, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class FSMOrder(models.Model):
_inherit = 'fsm.order'
_inherit = "fsm.order"

order_activity_ids = fields.One2many('fsm.activity', 'fsm_order_id',
'Activites')
order_activity_ids = fields.One2many("fsm.activity", "fsm_order_id", "Activites")

@api.multi
@api.onchange('template_id')
@api.onchange("template_id")
def _onchange_template_id(self):
res = super()._onchange_template_id()
for rec in self:
if rec.template_id:
activity_list = []
for temp_activity in rec.template_id.temp_activity_ids:
activity_list.append((0, 0,
{'name': temp_activity.name,
'required': temp_activity.required,
'ref': temp_activity.ref,
'state': temp_activity.state}))
activity_list.append(
(
0,
0,
{
"name": temp_activity.name,
"required": temp_activity.required,
"ref": temp_activity.ref,
"state": temp_activity.state,
},
)
)
rec.order_activity_ids = activity_list
rec.template_id.temp_activity_ids.write(
{'fsm_template_id': False})
rec.template_id.temp_activity_ids.write({"fsm_template_id": False})
return res

@api.multi
def action_complete(self):
res = super().action_complete()
for activity_id in self.order_activity_ids:
if activity_id.required and activity_id.state == 'todo':
raise ValidationError(_(
"You must complete activity '%s' before \
completing this order.") % activity_id.name)
if activity_id.required and activity_id.state == "todo":
raise ValidationError(
_(
"You must complete activity '%s' before \
completing this order."
)
% activity_id.name
)
for activity_id in self.activity_ids:
activity_id.done = True
return res
5 changes: 2 additions & 3 deletions fieldservice_activity/models/fsm_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class FSMTemplate(models.Model):
_inherit = 'fsm.template'
_inherit = "fsm.template"

temp_activity_ids = fields.One2many('fsm.activity', 'fsm_template_id',
'Activites')
temp_activity_ids = fields.One2many("fsm.activity", "fsm_template_id", "Activites")
Loading

0 comments on commit 740408f

Please sign in to comment.