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

[ADD] fsm.tag and sequence #5

Merged
merged 9 commits into from
Sep 24, 2018
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
10 changes: 8 additions & 2 deletions fieldservice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/field-service',
'depends': [
'base',
'mail',
'utm',
'rating',
'portal',
],
'data': [
'data/ir_sequence.xml',
'data/mail_message_subtype.xml',
'data/module_category.xml',
'data/fsm_stage.xml',
'security/res_groups.xml',
'security/ir.model.access.csv',
'views/res_config_settings.xml',
'views/fsm_stage.xml',
'views/fsm_tag.xml',
'views/res_partner.xml',
'views/fsm_location.xml',
'views/fsm_person.xml',
'views/fsm_order.xml',
'views/fsm_route.xml',
'views/menu.xml',
'data/fsm_stage.xml',
],
'application': True,
'license': 'AGPL-3',
Expand Down
5 changes: 3 additions & 2 deletions fieldservice/data/fsm_stage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
<field name="sequence">60</field>
</record>

<record id="fsm_stage_complete" model="fsm.stage">
<field name="name">Complete</field>
<record id="fsm_stage_completed" model="fsm.stage">
<field name="name">Completed</field>
<field name="sequence">70</field>
</record>

<record id="fsm_stage_cancelled" model="fsm.stage">
<field name="name">Cancelled</field>
<field name="sequence">100</field>
<field name="fold">True</field>
</record>
</odoo>
22 changes: 22 additions & 0 deletions fieldservice/data/ir_sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<!-- Sequence for fsm.order -->
<record id="seq_fsm_order" model="ir.sequence">
<field name="name">FSM Order</field>
<field name="code">fsm.order</field>
<field name="prefix">FO</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>

<!-- Sequence for fsm.route -->
<record id="seq_fsm_route" model="ir.sequence">
<field name="name">FSM Route</field>
<field name="code">fsm.route</field>
<field name="prefix">SR</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>

</odoo>
76 changes: 76 additions & 0 deletions fieldservice/data/mail_message_subtype.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Order related subtypes for messaging / Chatter -->
<record id="mt_order_new" model="mail.message.subtype">
<field name="name">Order Created</field>
<field name="sequence">0</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="hidden" eval="True"/>
<field name="description">Order created</field>
</record>

<record id="mt_order_confirmed" model="mail.message.subtype">
<field name="name">Order Confirmed</field>
<field name="sequence">10</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order confirmed</field>
</record>

<record id="mt_order_scheduled" model="mail.message.subtype">
<field name="name">Order Scheduled</field>
<field name="sequence">20</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order scheduled</field>
</record>

<record id="mt_order_assigned" model="mail.message.subtype">
<field name="name">Order Assigned</field>
<field name="sequence">30</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order assigned</field>
</record>

<record id="mt_order_enroute" model="mail.message.subtype">
<field name="name">Order En Route</field>
<field name="sequence">40</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order en route</field>
</record>

<record id="mt_order_started" model="mail.message.subtype">
<field name="name">Order Started</field>
<field name="sequence">50</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order started</field>
</record>

<record id="mt_order_completed" model="mail.message.subtype">
<field name="name">Order Completed</field>
<field name="sequence">60</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order completed</field>
</record>

<record id="mt_order_cancelled" model="mail.message.subtype">
<field name="name">Order Cancelled</field>
<field name="sequence">100</field>
<field name="res_model">fsm.order</field>
<field name="default" eval="False"/>
<field name="internal" eval="True"/>
<field name="description">Order cancelled</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions fieldservice/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
res_config_settings,
res_partner,
fsm_stage,
fsm_tag,
fsm_location,
fsm_person,
fsm_order,
Expand Down
93 changes: 81 additions & 12 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,97 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models, _
from . import fsm_stage


class FSMOrder(models.Model):
_name = 'fsm.order'
_description = 'Field Service Order'
_inherit = ['mail.thread', 'utm.mixin', 'rating.mixin',
'mail.activity.mixin', 'portal.mixin']

def _default_stage_id(self):
return self.env.ref('fieldservice.fsm_stage_new')

name = fields.Char(string='Name', required=True)
fsm_route_id = fields.Many2one('fsm.route', string='Route')
customer_id = fields.Many2one('res.partner', string='Customer',
domain=('customer', '=', True))
fsm_location_id = fields.Many2one('fsm.location', string='Location')
fsm_person_id = fields.Many2one('fsm.person',
string='Field Service Person')
requested_date = fields.Datetime(string='Requested Date')
scheduled_date = fields.Datetime(string='Scheduled Date')
date = fields.Datetime(string='Date')
description = fields.Text(string='Description')
stage_id = fields.Many2one('fsm.stage', string='Stage',
track_visibility='onchange',
index=True,
group_expand='_read_group_stage_ids',
default=lambda self: self._default_stage_id())
priority = fields.Selection(fsm_stage.AVAILABLE_PRIORITIES,
string='Priority',
index=True,
default=fsm_stage.AVAILABLE_PRIORITIES[0][0])
tag_ids = fields.Many2many('fsm.tag', 'fsm_order_tag_rel',
'fsm_order_id',
'tag_id', string='Tags',
help="Classify and analyze your orders")
color = fields.Integer('Color Index', default=0)

# Request
name = fields.Char(string='Name', required=True,
default=lambda self: _('New'))
customer_id = fields.Many2one('res.partner', string='Customer',
domain=[('customer', '=', True)],
required=True,
change_default=True,
index=True,
track_visibility='always')
fsm_location_id = fields.Many2one('fsm.location', string='Location',
index=True)
requested_date = fields.Datetime(string='Requested Date')
description = fields.Text(string='Description')
origin = fields.Char(string='Origin')

# Planning
fsm_person_id = fields.Many2one('fsm.person',
string='Field Service Person',
index=True)
fsm_route_id = fields.Many2one('fsm.route', string='Route', index=True)
scheduled_date = fields.Datetime(string='Scheduled Date')
todo = fields.Text(string='Instructions')

# Execution
log = fields.Text(string='Log')
date = fields.Datetime(string='Date')

@api.model
def _read_group_stage_ids(self, stages, domain, order):
stage_ids = self.env['fsm.stage'].search([])
return stage_ids

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('fsm.order') \
or _('New')
return super(FSMOrder, self).create(vals)

def action_confirm(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_confirmed').id})

def action_schedule(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_scheduled').id})

def action_assign(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_assigned').id})

def action_enroute(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_enroute').id})

def action_start(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_started').id})

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

def action_cancel(self):
return self.write({'stage_id': self.env.ref(
'fieldservice.fsm_stage_cancelled').id})
13 changes: 11 additions & 2 deletions fieldservice/models/fsm_route.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models, _


class FSMRoute(models.Model):
_name = 'fsm.route'
_description = 'Field Service Route'
_order = 'date, name'

name = fields.Char(string='Name')
name = fields.Char(string='Name', required=True,
default=lambda self: _('New'))
fsm_order_ids = fields.One2many('fsm.order', 'fsm_route_id',
string='Orders')
fsm_person_id = fields.Many2one('fsm.person',
Expand All @@ -21,3 +23,10 @@ class FSMRoute(models.Model):
'unique (fsm_person_id, date)',
"You cannot create 2 routes for the same person on the same day!"),
]

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('fsm.route')\
or _('New')
return super(FSMRoute, self).create(vals)
20 changes: 20 additions & 0 deletions fieldservice/models/fsm_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@
from odoo import fields, models


AVAILABLE_PRIORITIES = [
('0', 'Normal'),
('1', 'Low'),
('2', 'High'),
('3', 'Urgent'),
]


class FSMStage(models.Model):
_name = 'fsm.stage'
_description = 'Field Service Stage'
_order = 'sequence, name, id'

name = fields.Char(string='Name', required=True)
sequence = fields.Integer('Sequence', default=1,
help="Used to order stages. Lower is better.")
legend_priority = fields.Text('Priority Management Explanation',
translate=True,
help='Explanation text to help users using'
' the star and priority mechanism on'
' stages or orders that are in this'
' stage.')
fold = fields.Boolean('Folded in Kanban',
help='This stage is folded in the kanban view when '
'there are no record in that stage to display.')
16 changes: 16 additions & 0 deletions fieldservice/models/fsm_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FSMTag(models.Model):
_name = 'fsm.tag'
_description = 'Field Service Tag'

name = fields.Char(string='Name', required=True)
color = fields.Integer('Color Index', default=10)

_sql_constraints = [
('name_uniq', 'unique (name)', "Tag name already exists!"),
]
2 changes: 2 additions & 0 deletions fieldservice/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_fsm_stage_fsm_user,fsm.stage.user,model_fsm_stage,fieldservice.group_fsm_user,1,0,0,0
access_fsm_stage_fsm_manager,fsm.stage.manager,model_fsm_stage,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_tag_fsm_user,fsm.tag.user,model_fsm_tag,fieldservice.group_fsm_user,1,0,0,0
access_fsm_tag_fsm_manager,fsm.tag.manager,model_fsm_tag,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_person_user,fsm.person.user,model_fsm_person,fieldservice.group_fsm_user,1,1,0,0
access_fsm_person_manager,fsm.person.manager,model_fsm_person,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user,1,1,0,0
Expand Down
Loading