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] hr fleet : claim report and cars history for one employee #28077

Closed

Conversation

jbm-odoo
Copy link
Contributor

Add a field employee_cars_count (computed) to count the amount of cars the employee drove on employee page. This button open the kanban view with all car drove by this employee.

On the fleet.vehicle.assignation.logs a button (like in expense) to upload documents about the car for a particular employee. On the employee form view, add an action button (with groups fleet_manager) to print all the documents merged in one file. On each document, there is a header to show the vehicle and the dove period.

id=1892039

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

def action_open_employee_cars(self):
self.ensure_one()
Fleet = self.env['fleet.vehicle.assignation.log']
car_line = Fleet.search([('driver_id','=',self.user_id.partner_id.id)]).mapped('vehicle_id').mapped('id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can replace by
car_line = Fleet.search([('driver_id','=',self.user_id.partner_id.id)]).mapped('vehicle_id') (remove mapped('id'))

and put "domain": [("id", "in", car_line.ids)], (add .ids)

def _compute_employee_cars_count(self):
Fleet = self.env['fleet.vehicle.assignation.log'].sudo()
for employee in self:
employee.employee_cars_count = Fleet.search_count([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use read_group instead search_count (only sql request for all employee)

@C3POdoo C3POdoo added the RD research & development, internal work label Oct 24, 2018
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Oct 24, 2018
@RomainLibert RomainLibert force-pushed the master-history-cars-drivers-jbm branch from 3290589 to 499e7d8 Compare October 24, 2018 10:48
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Oct 24, 2018
@jbm-odoo jbm-odoo force-pushed the master-history-cars-drivers-jbm branch from 3290589 to 765944e Compare October 24, 2018 10:59
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Oct 24, 2018
Copy link
Contributor

@tivisse tivisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, mostly linting/guidelines issues. Some chunks of code could be improved too.

Globally it's a good work ! Thanks.

import base64
import io

from odoo import http, _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ is imported but unused. Could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be from odoo.http import request, route, Controller. More compact.

@http.route(["/hrfleet/claimreport/<int:employee_id>"], type='http', auth='user')
def get_claim_report_user(self, employee_id, **post):

user_rec = http.request.env['res.users'].sudo().search([('id', '=', http.request.session.uid)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use browse instead of searching id = uid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the sudo really needed ?

if not user_rec.has_group('fleet.fleet_group_manager'):
return http.request.not_found()

Fleet = http.request.env['fleet.vehicle.assignation.log']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your models are used only once or twice in your method. No need to store them into variables.

Attachment = http.request.env['ir.attachment']
Employee = http.request.env['hr.employee']

employee = Employee.search([('id','=',employee_id)],limit=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space in [('id', '=', employee_id)], limit=1

You could use a linter to avoid those kind of issues. If you're using sublime-text, pylinter is a good one.


partner_id = employee.user_id.partner_id.id
if not partner_id:
return http.request.not_found()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be factored into:

        employee = Employee.search([('id', '=', employee_id)], limit=1)
        partner_id = employee.user_id.partner_id
        if not employee or not partner:
            return http.request.not_found()


def _compute_employee_cars_count(self):
Fleet = self.env['fleet.vehicle.assignation.log'].sudo()
driver_id = self.mapped('user_id').mapped('partner_id').ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as self.mapped('user_id.partner_id').ids

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And driver_id could be a list of ids, so you could rename it into driver_ids

fleet_data = Fleet.read_group(domain=[('driver_id', 'in', driver_id)], fields=['driver_id'], groupby=['driver_id'])
mapped_data = dict([(m['driver_id'][0], m['driver_id_count']) for m in fleet_data])
for employee in self:
employee.employee_cars_count = mapped_data.get(employee.user_id.partner_id.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great you used read_group instead of search_count. This is a good practice!

'name': 'Claim Report',
'type': 'ir.actions.act_url',
'url': '/hrfleet/claimreport/%(employee_id)s' % {'employee_id': self.id},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting issue (missing end of file line)



class HrFleet(http.Controller):
@http.route(["/hrfleet/claimreport/<int:employee_id>"], type='http', auth='user')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route could be renamed into /fleet/print_claim_report/<int:employee_id>

from odoo import api, fields, models


class FleetVehicleAssignationLog(models.Model):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that the model name is not sexy, but according to the guidelines, the file should be named fleet_vehicle_assignation_log

@jbm-odoo jbm-odoo force-pushed the master-history-cars-drivers-jbm branch from 765944e to 57ed957 Compare October 25, 2018 13:18
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses and removed CI 🤖 Robodoo has seen passing statuses labels Oct 25, 2018
Purpose
=======

When an employee leaves the company, the fleet manager must ask to the insurance company
a claim report for this employee. But in oddo, there is no easy way to have an history
of the drivers.

Specification
=============

1/ On the employee form, add a stat button: "x cars". The button shouldn't be displayed if the count = 0.
   Make a bridge (auto_install: True in the manifest) depending on hr (hr.employee) and fleet (fleet.vehicle.assignation.log)
   - Add a field employee_cars_count (computed) to count the amount of cars the employee drove.
   - Add an method action_open_employee_cars, that return an action (ir.actions.act_window)
     that open on the fleet.vehicle kanban filtered on cars the employee had driven.
2/ In this bridge module, add on the fleet.vehicle.assignation.logs a button (like in expense) to upload
   documents about the car for a particular employee (PV, rapport d'assurance, blabla). On the employee
   form view, add an action button (with groups fleet_manager) to print all the related documents
   (all the attachements on the fleet.vehicle.assignation.logs for the employee).
@tivisse tivisse force-pushed the master-history-cars-drivers-jbm branch from 57ed957 to 167dc68 Compare November 6, 2018 13:04
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Nov 6, 2018
Copy link
Contributor

@tivisse tivisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments.

@http.route(["/fleet/print_claim_report/<int:employee_id>"], type='http', auth='user')
def get_claim_report_user(self, employee_id, **post):

user_rec = http.request.env['res.users'].browse(http.request.session.uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get user from request.env.user. No need to browse it.

import base64
import io

from odoo import http, _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be from odoo.http import request, route, Controller. More compact.

@tivisse
Copy link
Contributor

tivisse commented Nov 6, 2018

@robodoo r+

@robodoo robodoo added the r+ 👌 label Nov 6, 2018
<header>
<button name="action_get_claim_report" string="Claim Report"
type="object" groups="fleet.fleet_group_manager"
attrs="{'invisible': [('employee_cars_count','=', 0)]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sur it work ?, because employee_cars_count is not prevent in the view
<field name='employee_cars_count' invisible="1"/>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmdl If you look, the field is present inside the second button ;)

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Nov 6, 2018
robodoo pushed a commit that referenced this pull request Nov 6, 2018
Purpose
=======

When an employee leaves the company, the fleet manager must ask to the insurance company
a claim report for this employee. But in oddo, there is no easy way to have an history
of the drivers.

Specification
=============

1/ On the employee form, add a stat button: "x cars". The button shouldn't be displayed if the count = 0.
   Make a bridge (auto_install: True in the manifest) depending on hr (hr.employee) and fleet (fleet.vehicle.assignation.log)
   - Add a field employee_cars_count (computed) to count the amount of cars the employee drove.
   - Add an method action_open_employee_cars, that return an action (ir.actions.act_window)
     that open on the fleet.vehicle kanban filtered on cars the employee had driven.
2/ In this bridge module, add on the fleet.vehicle.assignation.logs a button (like in expense) to upload
   documents about the car for a particular employee (PV, rapport d'assurance, blabla). On the employee
   form view, add an action button (with groups fleet_manager) to print all the related documents
   (all the attachements on the fleet.vehicle.assignation.logs for the employee).

closes #28077
@robodoo
Copy link
Contributor

robodoo commented Nov 6, 2018

Merged, thanks!

@robodoo robodoo closed this Nov 6, 2018
@tivisse tivisse deleted the master-history-cars-drivers-jbm branch November 6, 2018 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI 🤖 Robodoo has seen passing statuses RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants