Skip to content

Commit

Permalink
[UPD] ssi_fleet_work_order
Browse files Browse the repository at this point in the history
  • Loading branch information
Miftahussalam committed Jun 6, 2024
1 parent bd6a8dc commit bf6d3b6
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ssi_fleet_work_order/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import (
models,
reports,
)
1 change: 1 addition & 0 deletions ssi_fleet_work_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"views/fleet_work_order_route_template_category_views.xml",
"views/fleet_work_order_type_views.xml",
"views/fleet_work_order_views.xml",
"reports/fleet_work_order_analysis.xml",
],
"images": [],
}
7 changes: 7 additions & 0 deletions ssi_fleet_work_order/reports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
fleet_work_order_analysis,
)
115 changes: 115 additions & 0 deletions ssi_fleet_work_order/reports/fleet_work_order_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class FleetWorkOrderAnalysis(models.Model):
_name = "fleet_work_order_analysis"
_description = "Fleet Work Order Analysis"
_order = "vehicle_id, driver_id"
_auto = False
_rec_name = "vehicle_id"

type_id = fields.Many2one(
string="Type",
comodel_name="fleet_work_order_type",
)
vehicle_id = fields.Many2one(
string="Vehicle",
comodel_name="fleet.vehicle",
)
driver_id = fields.Many2one(
string="Driver",
comodel_name="res.partner",
)
co_driver_id = fields.Many2one(
string="Co-Driver",
comodel_name="res.partner",
)
date_start = fields.Datetime(
string="ETD",
)
date_end = fields.Datetime(
string="ETA",
)
real_date_depart = fields.Datetime(
string="RTD",
)
real_date_arrive = fields.Datetime(
string="RTA",
)
odometer = fields.Float(
string="Odoometer",
)
state = fields.Selection(
string="State",
selection=[
("draft", "Draft"),
("confirm", "Waiting for Approval"),
("reject", "Rejected"),
("ready", "Ready to Start"),
("open", "On Progress"),
("done", "Done"),
("cancel", "Cancelled"),
],
)

@property
def _table_query(self):
return "%s %s %s %s" % (
self._select(),
self._from(),
self._where(),
self._group_by(),
)

@api.model
def _select(self):
select_str = """
SELECT
row_number() OVER() as id,
w.type_id AS type_id,
w.vehicle_id AS vehicle_id,
w.driver_id AS driver_id,
w.co_driver_id AS co_driver_id,
w.date_start AS date_start,
w.date_end AS date_end,
w.real_date_depart AS real_date_depart,
w.real_date_arrive AS real_date_arrive,
w.state AS state,
SUM(w.end_odometer - w.start_odometer) AS odometer
"""
return select_str

@api.model
def _from(self):
from_str = """
FROM
fleet_work_order AS w
"""
return from_str

@api.model
def _where(self):
where_str = """
"""
return where_str

@api.model
def _group_by(self):
group_by_str = """
GROUP BY
w.type_id,
w.vehicle_id,
w.driver_id,
w.co_driver_id,
w.date_start,
w.date_end,
w.real_date_depart,
w.real_date_arrive,
w.state
"""
return group_by_str
210 changes: 210 additions & 0 deletions ssi_fleet_work_order/reports/fleet_work_order_analysis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 OpenSynergy Indonesia
Copyright 2024 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="view_fleet_work_order_analysis_pivot" model="ir.ui.view">
<field name="name">fleet_work_order_analysis.pivot</field>
<field name="model">fleet_work_order_analysis</field>
<field name="arch" type="xml">
<pivot
string="Fleet Work Order Analysis"
display_quantity="true"
disable_linking="True"
sample="1"
>
<field name="odometer" type="measure" />
</pivot>
</field>
</record>

<record id="view_fleet_work_order_analysis_graph" model="ir.ui.view">
<field name="name">fleet_work_order_analysis.graph</field>
<field name="model">fleet_work_order_analysis</field>
<field name="arch" type="xml">
<graph
string="Fleet Work Order Analysis"
type="bar"
sample="1"
disable_linking="1"
>
<field name="odometer" type="measure" />
</graph>
</field>
</record>

<record id="view_fleet_work_order_analysis_search" model="ir.ui.view">
<field name="name">fleet_work_order_analysis.search</field>
<field name="model">fleet_work_order_analysis</field>
<field name="arch" type="xml">
<search string="Fleet Work Order Analysis">
<field name="type_id" />
<field name="vehicle_id" />
<field name="driver_id" />
<field name="co_driver_id" />
<field name="date_start" />
<field name="date_end" />
<field name="real_date_depart" />
<field name="real_date_arrive" />
<field name="odometer" />
<field name="state" />
<separator />
<filter name="filter_empty" string="Empty" domain="[('id','=',0)]" />
<group expand="1" string="Group By">
<group name="row_group" string="Row Grouping">
<filter
name="row_group_type"
string="Type"
context="{'group_by':'type_id'}"
/>
<filter
name="row_group_vehicle"
string="Vehicle"
context="{'group_by':'vehicle_id'}"
/>
<filter
name="row_group_driver"
string="Driver"
context="{'group_by':'driver_id'}"
/>
<filter
name="row_group_codriver"
string="Co-Driver"
context="{'group_by':'co_driver_id'}"
/>
<filter
name="row_group_state"
string="State"
context="{'group_by':'state'}"
/>
<filter
name="row_group_eta_year"
string="ETA by Year"
context="{'group_by':'date_start:year'}"
/>
<filter
name="row_group_eta_month"
string="ETA by Month"
context="{'group_by':'date_start:month'}"
/>
<filter
name="row_group_eta_week"
string="ETA by Week"
context="{'group_by':'date_start:week'}"
/>
<filter
name="row_group_eta_day"
string="ETA by Day"
context="{'group_by':'date_start:day'}"
/>
<filter
name="row_group_etd_year"
string="ETD by Year"
context="{'group_by':'date_end:year'}"
/>
<filter
name="row_group_etd_month"
string="ETD by Month"
context="{'group_by':'date_end:month'}"
/>
<filter
name="row_group_etd_week"
string="ETD by Week"
context="{'group_by':'date_end:week'}"
/>
<filter
name="row_group_etd_day"
string="ETD by Day"
context="{'group_by':'date_end:day'}"
/>
</group>
<group name="col_group" string="Col Grouping">
<filter
name="col_group_type"
string="Type"
context="{'col_group_by':'type_id'}"
/>
<filter
name="col_group_vehicle"
string="Vehicle"
context="{'col_group_by':'vehicle_id'}"
/>
<filter
name="col_group_driver"
string="Driver"
context="{'col_group_by':'driver_id'}"
/>
<filter
name="col_group_codriver"
string="Co-Driver"
context="{'col_group_by':'co_driver_id'}"
/>
<filter
name="col_group_state"
string="State"
context="{'col_group_by':'state'}"
/>
<filter
name="col_group_eta_year"
string="ETA by Year"
context="{'col_group_by':'date_start:year'}"
/>
<filter
name="col_group_eta_month"
string="ETA by Month"
context="{'col_group_by':'date_start:month'}"
/>
<filter
name="col_group_eta_week"
string="ETA by Week"
context="{'col_group_by':'date_start:week'}"
/>
<filter
name="col_group_eta_day"
string="ETA by Day"
context="{'col_group_by':'date_start:day'}"
/>
<filter
name="col_group_etd_year"
string="ETD by Year"
context="{'col_group_by':'date_end:year'}"
/>
<filter
name="col_group_etd_month"
string="ETD by Month"
context="{'col_group_by':'date_end:month'}"
/>
<filter
name="col_group_etd_week"
string="ETD by Week"
context="{'col_group_by':'date_end:week'}"
/>
<filter
name="col_group_etd_day"
string="ETD by Day"
context="{'col_group_by':'date_end:day'}"
/>
</group>
</group>
</search>
</field>
</record>

<record id="action_fleet_work_order_analysis" model="ir.actions.act_window">
<field name="name">Fleet Work Order Analysis</field>
<field name="res_model">fleet_work_order_analysis</field>
<field name="view_mode">pivot,graph</field>
<field name="search_view_id" ref="view_fleet_work_order_analysis_search" />
<field name="context">{"search_default_filter_empty": True}</field>
</record>

<menuitem
id="menu_fleet_work_order_analysis"
parent="ssi_timesheet.reporting_menu"
action="action_fleet_work_order_analysis"
sequence="10"
groups="fleet_work_order_analysis_group"
/>

</odoo>
1 change: 1 addition & 0 deletions ssi_fleet_work_order/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ access_fleet_work_order_user,fleet_work_order - user,model_fleet_work_order,flee
access_fleet_work_order_route_all,fleet_work_order_route - all,model_fleet_work_order_route,,1,0,0,0
access_fleet_work_order_route_viewer,fleet_work_order_route - viewer,model_fleet_work_order_route,fleet_work_order_viewer_group,1,0,0,0
access_fleet_work_order_route_user,fleet_work_order_route - user,model_fleet_work_order_route,fleet_work_order_user_group,1,1,1,1
access_fleet_work_order_analysis_all,fleet_work_order_analysis - all,model_fleet_work_order_analysis,fleet_work_order_analysis_group,1,0,0,0
15 changes: 15 additions & 0 deletions ssi_fleet_work_order/security/ir_module_category_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
ref="ssi_fleet_management.fleet_management_module_category"
/>
</record>
<record
id="fleet_work_order_analysis_data_ownership_module_category"
model="ir.module.category"
>
<field name="name">Fleet Work Order Analysis</field>
<field name="parent_id" ref="ssi_fleet_management.fleet_management_module_category" />
</record>

<!-- Configurator -->
<record
Expand All @@ -35,4 +42,12 @@
ref="ssi_fleet_management.fleet_management_module_category"
/>
</record>

<!-- Reporting -->
<record id="fleet_work_order_reporting_module_category" model="ir.module.category">
<field name="name">Fleet Work Order - Reporting</field>
<field name="parent_id"
ref="ssi_fleet_management.fleet_management_module_category"
/>
</record>
</odoo>
Loading

0 comments on commit bf6d3b6

Please sign in to comment.