Skip to content

Commit

Permalink
[IMP] fieldservice_location_builder: code after pre-commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Murtaza-OSI authored and dreispt committed Dec 10, 2021
1 parent 4f9a23b commit d45fe97
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 90 deletions.
1 change: 0 additions & 1 deletion fieldservice_location_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import wizard
34 changes: 16 additions & 18 deletions fieldservice_location_builder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Field Service Location Builder',
'summary': 'Adds a tool to help build out Location Hierarchies',
'version': '14.0.1.0.0',
'category': 'Field Service',
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/field-service',
'depends': [
'fieldservice_account_analytic'
"name": "Field Service Location Builder",
"summary": "Adds a tool to help build out Location Hierarchies",
"version": "14.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": ["fieldservice"],
"data": [
"security/ir.model.access.csv",
"wizard/fsm_location_builder_wizard.xml",
"wizard/fsm_location_level.xml",
],
'data': [
'security/ir.model.access.csv',
'wizard/fsm_location_builder_wizard.xml',
'wizard/fsm_location_level.xml',
],
'license': 'AGPL-3',
'development_status': 'Beta',
'maintainers': [
'osi-scampbell',
'max3903',
"license": "AGPL-3",
"development_status": "Beta",
"maintainers": [
"osi-scampbell",
"max3903",
],
}
12 changes: 6 additions & 6 deletions fieldservice_location_builder/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
With the Field Service App, building out a site like an apartment complex
with multiple buildings, floors, units can become cumbersome and
tedious to build all the records. Even building an importable spreadsheet
With the Field Service App, building out a site like an apartment complex
with multiple buildings, floors, units can become cumbersome and
tedious to build all the records. Even building an importable spreadsheet
can be tedious to build, and new users will struggle with this.

This module is for organizations that needs to create the locations
structure (~100 sub-locations) of a new site in less than a minute.
It provides a wizard on a location that will assist in building the
This module is for organizations that needs to create the locations
structure (~100 sub-locations) of a new site in less than a minute.
It provides a wizard on a location that will assist in building the
sub-location hierarchy.
56 changes: 27 additions & 29 deletions fieldservice_location_builder/wizard/fsm_location_builder_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,52 @@


class FSMLocationBuilderWizard(models.TransientModel):
_name = 'fsm.location.builder.wizard'
_description = 'FSM Location Builder Wizard'
level_ids = fields.One2many('fsm.location.level',
'wizard_id', string="Level ID's")

_name = "fsm.location.builder.wizard"
_description = "FSM Location Builder Wizard"
level_ids = fields.One2many("fsm.location.level", "wizard_id", string="Level ID's")

def create_sub_locations(self):
levels = len(self.level_ids) - 1
location = self.env['fsm.location'].\
browse(self.env.context.get('active_id'))
location = self.env["fsm.location"].browse(self.env.context.get("active_id"))

def build_location(parent, num):
if self.level_ids[num].spacer:
spacer = " " + self.level_ids[num].spacer + " "
else:
spacer = " "
for lev_id in range(self.level_ids[num].start_number,
self.level_ids[num].end_number + 1):
for lev_id in range(
self.level_ids[num].start_number, self.level_ids[num].end_number + 1
):
vals = self.prepare_fsm_location_values(
location, parent, spacer, lev_id, num)
new_location = self.env['fsm.location'].create(vals)
location, parent, spacer, lev_id, num
)
new_location = self.env["fsm.location"].create(vals)
if num < levels:
build_location(new_location, num + 1)

build_location(location, 0)

def prepare_fsm_location_values(self, location, parent,
spacer, lev_id, num):
def prepare_fsm_location_values(self, location, parent, spacer, lev_id, num):
tags = self.level_ids[num].tag_ids.ids
vals = {'name': self.level_ids[num].name + spacer + str(lev_id),
'owner_id': location.owner_id.id,
'customer_id': location.customer_id.id,
'fsm_parent_id': parent.id,
'street': location.street,
'street2': self.level_ids[num].name + spacer + str(lev_id),
'city': location.city,
'zip': location.zip,
}
vals = {
"name": self.level_ids[num].name + spacer + str(lev_id),
"owner_id": location.owner_id.id,
"customer_id": location.customer_id.id,
"fsm_parent_id": parent.id,
"street": location.street,
"street2": self.level_ids[num].name + spacer + str(lev_id),
"city": location.city,
"zip": location.zip,
}
if tags:
vals.update({
'category_id': [(6, 0, tags)]
})
vals.update({"category_id": [(6, 0, tags)]})

if location.state_id:
vals.update([('state_id', location.state_id.id)])
vals.update([("state_id", location.state_id.id)])
if location.country_id:
vals.update([('country_id', location.country_id.id)])
vals.update([("country_id", location.country_id.id)])
if location.territory_id:
vals.update([('territory_id', location.territory_id.id)])
vals.update([("territory_id", location.territory_id.id)])
if location.tz:
vals.update([('tz', location.tz)])
vals.update([("tz", location.tz)])
return vals
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
<form>
<field name="level_ids">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
<field name="spacer"/>
<field name="start_number"/>
<field name="end_number"/>
<field name="total_number"/>
<field name="sequence" widget="handle" />
<field name="name" />
<field
name="tag_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"
/>
<field name="spacer" />
<field name="start_number" />
<field name="end_number" />
<field name="total_number" />
</tree>
</field>
<footer>
<button name="create_sub_locations" string="Create Sub Locations" class="oe_right oe_highlight" type="object"/>
<button string="Cancel" class="oe_right" special="cancel"/>
<button
name="create_sub_locations"
string="Create Sub Locations"
class="oe_right oe_highlight"
type="object"
/>
<button string="Cancel" class="oe_right" special="cancel" />
</footer>
</form>
</field>
Expand All @@ -30,7 +39,9 @@
<field name="target">new</field>
<field name="binding_model_id" ref="fieldservice.model_fsm_location" />
<field name="binding_view_types">form</field>
<field name="context">{'default_primary_location_id': active_id, 'default_owner_id': context.get('owner_id.id',False)}</field>
<field
name="context"
>{'default_primary_location_id': active_id, 'default_owner_id': context.get('owner_id.id',False)}</field>
</record>

</odoo>
24 changes: 12 additions & 12 deletions fieldservice_location_builder/wizard/fsm_location_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@


class FSMLocationLevel(models.TransientModel):
_name = 'fsm.location.level'
_description = 'Level in the FSM location tree structure'
_name = "fsm.location.level"
_description = "Level in the FSM location tree structure"

sequence = fields.Integer("Sequence")
name = fields.Char("Name", required=True)
spacer = fields.Char("Spacer")
start_number = fields.Integer("Start Number")
end_number = fields.Integer("End Number")
total_number = fields.Integer("Total", compute='_compute_total_number')
tag_ids = fields.Many2many('res.partner.category', string="Tags",
readonly=False)
wizard_id = fields.Many2one('fsm.location.builder.wizard', "Wizard")
total_number = fields.Integer("Total", compute="_compute_total_number")
tag_ids = fields.Many2many("res.partner.category", string="Tags", readonly=False)
wizard_id = fields.Many2one("fsm.location.builder.wizard", "Wizard")

@api.depends('start_number', 'end_number')
@api.depends("start_number", "end_number")
def _compute_total_number(self):
for level_id in self:
level_id.total_number = 0
if (level_id.start_number is not None and
level_id.end_number is not None and
level_id.start_number < level_id.end_number):
level_id.total_number = (level_id.end_number -
level_id.start_number + 1)
if (
level_id.start_number is not None
and level_id.end_number is not None
and level_id.start_number < level_id.end_number
):
level_id.total_number = level_id.end_number - level_id.start_number + 1
28 changes: 14 additions & 14 deletions fieldservice_location_builder/wizard/fsm_location_level.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<field name="model">fsm.location.level</field>
<field name="arch" type="xml">
<tree string="Location Level">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="spacer"/>
<field name="start_number"/>
<field name="end_number"/>
<field name="total_number"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="sequence" widget="handle" />
<field name="name" />
<field name="spacer" />
<field name="start_number" />
<field name="end_number" />
<field name="total_number" />
<field name="tag_ids" widget="many2many_tags" />
</tree>
</field>
</record>
Expand All @@ -24,14 +24,14 @@
<field name="arch" type="xml">
<form string="Location Level">
<sheet>
<label for="name" class="oe_edit_only"/>
<h1> <field name="name"/></h1>
<label for="name" class="oe_edit_only" />
<h1> <field name="name" /></h1>
<group>
<field name="spacer"/>
<field name="start_number"/>
<field name="end_number"/>
<field name="total_number"/>
<field name="tag_ids" widget="many2many_tags"/>
<field name="spacer" />
<field name="start_number" />
<field name="end_number" />
<field name="total_number" />
<field name="tag_ids" widget="many2many_tags" />
</group>
</sheet>
</form>
Expand Down
6 changes: 6 additions & 0 deletions setup/fieldservice_location_builder/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit d45fe97

Please sign in to comment.