-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] fieldservice_activity: black, isort, prettier
- Loading branch information
1 parent
6192ef1
commit 809e190
Showing
8 changed files
with
861 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.