Skip to content

Commit

Permalink
[IMP] fleet: improve activity management on fleet contract model
Browse files Browse the repository at this point in the history
This commit improves fleet contracts management through a better integration
of activities and addition of automated activities. Several things are done
in this commit :

 * fleet vehicle log contract does not inherit from mail.activity.mixin.
   This commit adds the inherit so that fleet users and managers can now
   schedule and manage activities on vehicle contracts. This will help them
   in their daily job;
 * automatic activities generation is added when contracts are nearly expired
   and renewal is required;
 * a menu to configure activity types is added. Indeed fleet managers should
   be able to see and configure activity types related to their job;
 * filters are added to be able to use the systray and to filter the kanban
   view based on activities

Having automated activities allow to replace some messages posted on the
contract. Indeed currently there are messages posted on vehicles about
contracts to renew. As we now have automated activities on contracts to
remind assigned people to renew it the log can be safely removed. It will
lessen noise generated on chatter.
  • Loading branch information
tde-banana-odoo committed Mar 27, 2018
1 parent fce3376 commit 77c7b68
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
2 changes: 2 additions & 0 deletions addons/fleet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
'views/fleet_vehicle_views.xml',
'views/fleet_vehicle_cost_views.xml',
'views/fleet_board_view.xml',
'views/mail_activity_views.xml',
'data/fleet_cars_data.xml',
'data/fleet_data.xml',
'data/mail_data.xml',
],

'demo': ['data/fleet_demo.xml'],
Expand Down
10 changes: 10 additions & 0 deletions addons/fleet/data/mail_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo><data noupdate="1">

<record id="mail_act_fleet_contract_to_renew" model="mail.activity.type">
<field name="name">Contract to Renew</field>
<field name="icon">fa-car</field>
<field name="res_model_id" ref="fleet.model_fleet_vehicle_log_contract"/>
</record>

</data></odoo>
16 changes: 5 additions & 11 deletions addons/fleet/models/fleet_vehicle_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create(self, data):


class FleetVehicleLogContract(models.Model):
_inherit = ['mail.thread']
_inherit = ['mail.thread', 'mail.activity.mixin']
_inherits = {'fleet.vehicle.cost': 'cost_id'}
_name = 'fleet.vehicle.log.contract'
_description = 'Contract information on a vehicle'
Expand Down Expand Up @@ -263,17 +263,12 @@ def scheduler_manage_contract_expiration(self):
date_today = fields.Date.from_string(fields.Date.today())
in_fifteen_days = fields.Date.to_string(date_today + relativedelta(days=+15))
nearly_expired_contracts = self.search([('state', '=', 'open'), ('expiration_date', '<', in_fifteen_days)])
res = {}
for contract in nearly_expired_contracts:
if contract.vehicle_id.id in res:
res[contract.vehicle_id.id] += 1
else:
res[contract.vehicle_id.id] = 1

Vehicle = self.env['fleet.vehicle']
for vehicle, value in res.items():
Vehicle.browse(vehicle).message_post(body=_('%s contract(s) will expire soon and should be renewed and/or closed!') % value)
nearly_expired_contracts.write({'state': 'diesoon'})
for contract in nearly_expired_contracts.filtered(lambda contract: contract.user_id):
contract.activity_schedule(
'fleet.mail_act_fleet_contract_to_renew', contract.expiration_date,
user_id=contract.user_id.id)

expired_contracts = self.search([('state', '!=', 'expired'), ('expiration_date', '<',fields.Date.today() )])
expired_contracts.write({'state': 'expired'})
Expand All @@ -284,7 +279,6 @@ def scheduler_manage_contract_expiration(self):
now_running_contracts = self.search([('state', '=', 'futur'), ('start_date', '<=', fields.Date.today())])
now_running_contracts.write({'state': 'open'})

@api.model
def run_scheduler(self):
self.scheduler_manage_auto_costs()
self.scheduler_manage_contract_expiration()
Expand Down
1 change: 1 addition & 0 deletions addons/fleet/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ fleet_vehicle_log_services_access_right,fleet_vehicle_log_services_access_right,
fleet_vehicle_log_contract_access_right,fleet_vehicle_log_contract_access_right,model_fleet_vehicle_log_contract,fleet_group_manager,1,1,1,1
fleet_service_type_access_right,fleet_service_type_access_right,model_fleet_service_type,fleet_group_manager,1,1,1,1
access_fleet_vehicle_cost,access_fleet_vehicle_cost,model_fleet_vehicle_cost,fleet_group_manager,1,1,1,1
access_mail_activity_type_fleet_manager,mail.activity.type.fleet.manager,mail.model_mail_activity_type,fleet.fleet_group_manager,1,1,1,1
10 changes: 10 additions & 0 deletions addons/fleet/views/fleet_vehicle_cost_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread" options='{"thread_level": 1}'/>
</div>
</form>
Expand Down Expand Up @@ -337,6 +338,15 @@
<filter string="In Progress" name="open" domain="[('state', '=', 'open')]"/>
<filter string="Expired" name="expired" domain="[('state', '=', 'expired')]"/>
<filter string="Expiring Soon" name="expire_soon" domain="[('state', '=', 'diesoon')]"/>
<separator/>
<filter string="Late Activities" name="activities_overdue"
domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
help="Show all records which has next action date is before today"/>
<filter string="Today Activities" name="activities_today"
domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"/>
<filter string="Future Activities" name="activities_upcoming_all"
domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))
]"/>
<group expand="0" string="Group By">
<filter string="Vehicle" name="vehicle" context="{'group_by':'vehicle_id'}"/>
</group>
Expand Down
2 changes: 1 addition & 1 deletion addons/fleet/views/fleet_vehicle_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,6 @@
</field>
</record>

<menuitem id="fleet_vehicle_tag_menu" parent="fleet_configuration" action="fleet_vehicle_tag_action" sequence="112"/>
<menuitem id="fleet_vehicle_tag_menu" parent="fleet_configuration" action="fleet_vehicle_tag_action" sequence="89"/>

</odoo>
17 changes: 17 additions & 0 deletions addons/fleet/views/mail_activity_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>
<!-- Activity types config -->
<record id="mail_activity_type_action_config_fleet" model="ir.actions.act_window">
<field name="name">Activity Types</field>
<field name="res_model">mail.activity.type</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">['|', ('res_model_id', '=', False), ('res_model_id.model', '=', 'fleet.vehicle.log.contract')]</field>
<field name="context">{'default_res_model': 'fleet.vehicle.log.contract'}</field>
</record>
<menuitem id="fleet_menu_config_activity_type"
action="mail_activity_type_action_config_fleet"
parent="fleet_configuration"
sequence="99"
groups="base.group_no_one"/>
</odoo>

0 comments on commit 77c7b68

Please sign in to comment.