Skip to content

Commit

Permalink
[IMP] Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
murtuzasaleh committed Feb 27, 2020
1 parent a55ea16 commit f99c823
Show file tree
Hide file tree
Showing 55 changed files with 1,359 additions and 1,366 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ line_length=88
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party=
known_third_party=setuptools
10 changes: 5 additions & 5 deletions fieldservice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Field Service
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github
:target: https://github.com/OCA/field-service/tree/12.0/fieldservice
:target: https://github.com/OCA/field-service/tree/13.0/fieldservice
:alt: OCA/field-service
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/field-service-12-0/field-service-12-0-fieldservice
:target: https://translation.odoo-community.org/projects/field-service-13-0/field-service-13-0-fieldservice
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/264/12.0
:target: https://runbot.odoo-community.org/runbot/264/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -190,7 +190,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -246,6 +246,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-wolfhall| |maintainer-max3903|

This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/12.0/fieldservice>`_ project on GitHub.
This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/13.0/fieldservice>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
105 changes: 50 additions & 55 deletions fieldservice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,57 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Field Service',
'summary': 'Manage Field Service Locations, Workers and Orders',
'version': '13.0.1.0.0',
'category': 'Field Service',
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/field-service',
'depends': [
'base_geolocalize',
'web_timeline',
'resource',
'contacts',
'partner_fax'
"name": "Field Service",
"summary": "Manage Field Service Locations, Workers and Orders",
"version": "13.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": [
"base_territory",
"base_geolocalize",
"web_timeline",
"resource",
"contacts",
"partner_fax",
],
'data': [
'data/ir_sequence.xml',
'data/mail_message_subtype.xml',
'data/module_category.xml',
'data/fsm_stage.xml',
'data/fsm_team.xml',
'security/res_groups.xml',
'security/ir.model.access.csv',
'security/ir_rule.xml',
'report/fsm_order_report_template.xml',
'views/res_config_settings.xml',
'views/fsm_territory.xml',
'views/fsm_stage.xml',
'views/fsm_tag.xml',
'views/res_partner.xml',
'views/fsm_location.xml',
'views/fsm_location_person.xml',
'views/fsm_person.xml',
'views/fsm_order.xml',
'views/fsm_order_type.xml',
'views/fsm_route.xml',
'views/fsm_schedule.xml',
'views/fsm_category.xml',
'views/fsm_equipment.xml',
'views/fsm_template.xml',
'views/fsm_team.xml',
'views/menu.xml',
'wizard/fsm_wizard.xml',
"data": [
"data/ir_sequence.xml",
"data/mail_message_subtype.xml",
"data/module_category.xml",
"data/fsm_stage.xml",
"data/fsm_team.xml",
"security/res_groups.xml",
"security/ir.model.access.csv",
"security/ir_rule.xml",
"report/fsm_order_report_template.xml",
"views/res_config_settings.xml",
"views/res_territory.xml",
"views/fsm_stage.xml",
"views/fsm_tag.xml",
"views/res_partner.xml",
"views/fsm_location.xml",
"views/fsm_location_person.xml",
"views/fsm_person.xml",
"views/fsm_order.xml",
"views/fsm_order_type.xml",
"views/fsm_schedule.xml",
"views/fsm_category.xml",
"views/fsm_equipment.xml",
"views/fsm_template.xml",
"views/fsm_team.xml",
"views/menu.xml",
"wizard/fsm_wizard.xml",
],
'demo': [
'demo/fsm_demo.xml',
'demo/fsm_equipment.xml',
'demo/fsm_location.xml',
'demo/fsm_person.xml',
],
'qweb': [
'static/src/xml/*.xml',
],
'application': True,
'license': 'AGPL-3',
'development_status': 'Beta',
'maintainers': [
'wolfhall',
'max3903',
"demo": [
"demo/fsm_demo.xml",
"demo/fsm_equipment.xml",
"demo/fsm_location.xml",
"demo/fsm_person.xml",
],
"qweb": ["static/src/xml/*.xml"],
"application": True,
"license": "AGPL-3",
"development_status": "Beta",
"maintainers": ["wolfhall", "max3903"],
}
9 changes: 0 additions & 9 deletions fieldservice/data/ir_sequence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,4 @@
<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>
8 changes: 4 additions & 4 deletions fieldservice/demo/fsm_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<field name="partner_id" eval="ref('test_loc_partner')"/>
<field name="owner_id" eval="ref('test_loc_partner')"/>
<field name="customer_id" eval="ref('test_loc_partner')"/>
<field name="territory_id" eval="ref('test_territory')"/>
<field name="branch_id" eval="ref('test_branch')"/>
<field name="district_id" eval="ref('test_district')"/>
<field name="region_id" eval="ref('test_region')"/>
<field name="territory_id" eval="ref('base_territory.test_territory')"/>
<field name="branch_id" eval="ref('base_territory.test_branch')"/>
<field name="district_id" eval="ref('base_territory.test_district')"/>
<field name="region_id" eval="ref('base_territory.test_region')"/>
<field name="direction">New the old inventory</field>
<field name="street">14 Tower A, main street</field>
<field name="street2">Bangkok, Thailand</field>
Expand Down
4 changes: 2 additions & 2 deletions fieldservice/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
res_config_settings,
fsm_category,
fsm_template,
fsm_territory,
res_territory,
fsm_tag,
fsm_stage,
fsm_team,
Expand All @@ -15,5 +15,5 @@
res_partner,
fsm_equipment,
fsm_order,
fsm_route,
fsm_order_type,
)
28 changes: 15 additions & 13 deletions fieldservice/models/fsm_category.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class FSMCategory(models.Model):
_name = 'fsm.category'
_description = 'Field Service Worker Category'
_name = "fsm.category"
_description = "Field Service Worker Category"

name = fields.Char(string='Name', required='True')
parent_id = fields.Many2one('fsm.category', string='Parent')
color = fields.Integer('Color Index', default=10)
name = fields.Char(string="Name", required="True")
parent_id = fields.Many2one("fsm.category", string="Parent")
color = fields.Integer("Color Index", default=10)
full_name = fields.Char(string="Full Name", compute="_compute_full_name")
description = fields.Char(string='Description')
description = fields.Char(string="Description")
company_id = fields.Many2one(
'res.company', string='Company', required=True, index=True,
"res.company",
string="Company",
required=True,
index=True,
default=lambda self: self.env.user.company_id,
help="Company related to this category")
help="Company related to this category",
)

_sql_constraints = [
('name_uniq', 'unique (name)', "Category name already exists!"),
]
_sql_constraints = [("name_uniq", "unique (name)", "Category name already exists!")]

def _compute_full_name(self):
for record in self:
if record.parent_id:
record.full_name = (record.parent_id.name + '/' + record.name)
record.full_name = record.parent_id.name + "/" + record.name
else:
record.full_name = record.name
106 changes: 57 additions & 49 deletions fieldservice/models/fsm_equipment.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,106 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# Copyright (C) 2020 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class FSMEquipment(models.Model):
_name = 'fsm.equipment'
_description = 'Field Service Equipment'
_inherit = ['mail.thread', 'mail.activity.mixin']
_name = "fsm.equipment"
_description = "Field Service Equipment"
_inherit = ["mail.thread", "mail.activity.mixin"]

name = fields.Char(string='Name', required='True')
person_id = fields.Many2one('fsm.person', string='Assigned Operator')
location_id = fields.Many2one('fsm.location', string='Assigned Location')
notes = fields.Text(string='Notes')
territory_id = fields.Many2one('res.territory', string='Territory')
branch_id = fields.Many2one('fsm.branch', string='Branch')
district_id = fields.Many2one('fsm.district', string='District')
region_id = fields.Many2one('fsm.region', string='Region')
current_location_id = fields.Many2one('fsm.location',
string='Current Location',
required=True)
name = fields.Char(string="Name", required="True")
person_id = fields.Many2one("fsm.person", string="Assigned Operator")
location_id = fields.Many2one("fsm.location", string="Assigned Location")
notes = fields.Text(string="Notes")
territory_id = fields.Many2one("res.territory", string="Territory")
branch_id = fields.Many2one("res.branch", string="Branch")
district_id = fields.Many2one("res.district", string="District")
region_id = fields.Many2one("res.region", string="Region")
current_location_id = fields.Many2one(
"fsm.location", string="Current Location", required=True
)

managed_by_id = fields.Many2one('res.partner', string='Managed By')
owned_by_id = fields.Many2one('res.partner', string='Owned By')
parent_id = fields.Many2one('fsm.equipment', string='Parent')
child_ids = fields.One2many('fsm.equipment', 'parent_id',
string='Children')
stage_id = fields.Many2one('fsm.stage', string='Stage',
track_visibility='onchange',
index=True, copy=False,
group_expand='_read_group_stage_ids',
default=lambda self: self._default_stage_id())
managed_by_id = fields.Many2one("res.partner", string="Managed By")
owned_by_id = fields.Many2one("res.partner", string="Owned By")
parent_id = fields.Many2one("fsm.equipment", string="Parent")
child_ids = fields.One2many("fsm.equipment", "parent_id", string="Children")
stage_id = fields.Many2one(
"fsm.stage",
string="Stage",
track_visibility="onchange",
index=True,
copy=False,
group_expand="_read_group_stage_ids",
default=lambda self: self._default_stage_id(),
)
hide = fields.Boolean(default=False)
color = fields.Integer('Color Index')
color = fields.Integer("Color Index")
company_id = fields.Many2one(
'res.company', string='Company', required=True, index=True,
"res.company",
string="Company",
required=True,
index=True,
default=lambda self: self.env.user.company_id,
help="Company related to this equipment")
help="Company related to this equipment",
)

_sql_constraints = [
('name_uniq', 'unique (name)', "Equipment name already exists!"),
("name_uniq", "unique (name)", "Equipment name already exists!")
]

@api.onchange('location_id')
@api.onchange("location_id")
def _onchange_location_id(self):
self.territory_id = self.location_id.territory_id

@api.onchange('territory_id')
@api.onchange("territory_id")
def _onchange_territory_id(self):
self.branch_id = self.territory_id.branch_id

@api.onchange('branch_id')
@api.onchange("branch_id")
def _onchange_branch_id(self):
self.district_id = self.branch_id.district_id

@api.onchange('district_id')
@api.onchange("district_id")
def _onchange_district_id(self):
self.region_id = self.district_id.region_id

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

def _default_stage_id(self):
return self.env['fsm.stage'].search([('stage_type', '=', 'equipment'),
('sequence', '=', '1')])
return self.env["fsm.stage"].search(
[("stage_type", "=", "equipment"), ("sequence", "=", "1")]
)

def next_stage(self):
seq = self.stage_id.sequence
next_stage = self.env['fsm.stage'].search(
[('stage_type', '=', 'equipment'), ('sequence', '>', seq)],
order="sequence asc")
next_stage = self.env["fsm.stage"].search(
[("stage_type", "=", "equipment"), ("sequence", ">", seq)],
order="sequence asc",
)
if next_stage:
self.stage_id = next_stage[0]
self._onchange_stage_id()

def previous_stage(self):
seq = self.stage_id.sequence
prev_stage = self.env['fsm.stage'].search(
[('stage_type', '=', 'equipment'), ('sequence', '<', seq)],
order="sequence desc")
prev_stage = self.env["fsm.stage"].search(
[("stage_type", "=", "equipment"), ("sequence", "<", seq)],
order="sequence desc",
)
if prev_stage:
self.stage_id = prev_stage[0]
self._onchange_stage_id()

@api.onchange('stage_id')
@api.onchange("stage_id")
def _onchange_stage_id(self):
# get last stage
heighest_stage = self.env['fsm.stage'].search(
[('stage_type', '=', 'equipment')],
order='sequence desc',
limit=1)
heighest_stage = self.env["fsm.stage"].search(
[("stage_type", "=", "equipment")], order="sequence desc", limit=1
)
if self.stage_id.name == heighest_stage.name:
self.hide = True
else:
Expand Down
Loading

0 comments on commit f99c823

Please sign in to comment.