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] [10.0] hr_employee_operating_unit #97

Closed
wants to merge 15 commits into from
Closed

[ADD] [10.0] hr_employee_operating_unit #97

wants to merge 15 commits into from

Conversation

Matiar
Copy link

@Matiar Matiar commented Oct 8, 2017

This module introduces the following features:

  1. Adds the Operating Unit (OU) to the Employee.
  2. The user’s default Operating Unit (OU) is proposed at the time of creating the Employee.
  3. Security rules are defined to ensure that users can only see the Employee of that Operating Units in which they are allowed access to.

@Matiar
Copy link
Author

Matiar commented Oct 9, 2017

@aheficent Could you please review ?

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

Hi @Matiar Thanks for your module. A couple of things:

  • As there's a field user_id in the employee, if the employee has an user associated, then the employee should have an operating unit from the operating unit of the users.
  • IMHO an employee may belong to different operating units so the field may be One2many. The problem here is that it may be inconsistencies between the operating unit of the employee and the operating unit of the related user.
  • Please attend travis and also fix the description in this PR

@Matiar
Copy link
Author

Matiar commented Oct 9, 2017

Hello @aarón Henríquez,

Thanks for your valuable feedback. I'll fix as you suggested and get back to you.

@Matiar Matiar changed the title [ADD] hr_employee_operating_unit to v10.0 [ADD] [10.0] hr_employee_operating_unit Oct 19, 2017
@Matiar
Copy link
Author

Matiar commented Oct 19, 2017

Hello Aarón Henríquez,

Thanks for your valuable feedback.

As you suggested, when an employee will associate with an user account the operating unit of employee is set with the operating unit of the associated user.

But also you suggest an one2many relationship between employee and operating unit, I didn't yet implement that. I have a question on that as you know the employee has a relationship between department and that is Many2One; Then will it not confusing to maintain One2Many relationship.

Would you please review and let me know your valuable feedback ?

@Matiar
Copy link
Author

Matiar commented Oct 22, 2017

@aheficent Could you please review ?

@AaronHForgeFlow
Copy link
Contributor

Hi @Matiar the question is, can an employee belong to different operating units? If the answer it's true then the field have to be Many2many.

@AaronHForgeFlow
Copy link
Contributor

I think it's not necessary to have a default_operating_unit field in the employee. I'd leave just the many2many relationship. Don't you agree?


@api.onchange('user_id')
def _onchange_user(self):
super(HREmployee, self)._onchange_user()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Matiar Thank you for doing the thing but I was wrong. An employee may belong to different operating units but as a user manage different operating units. So probably this is not needed now. I'm sorry for the misunderstanding.


@api.model
def _get_operating_unit(self):
return self.operating_unit_default_get(self._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 it possible to achieve the same result in a single method?

@oca-clabot
Copy link

Hey @Matiar, thank you for your Pull Request.

It looks like some users haven't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement here: http://odoo-community.org/page/website.cla
Here is a list of the users:

Appreciation of efforts,
OCA CLAbot

@Matiar
Copy link
Author

Matiar commented Oct 25, 2017

Hello @aheficent ,

Thanks for your overall feedback and reviewing the PR. I'm not sure how to fix codecov/project & codecov/patch failure issue. Could you please share some source or link to understand the problem and fixing it.

@AaronHForgeFlow
Copy link
Contributor

Hi @Matiar,

You need to add some tests in order to turn green codecov. For example you can test that users cannot see the employees the are not allowed to. You can also test the default method.Are you familiarized with unit test?

@Matiar
Copy link
Author

Matiar commented Oct 25, 2017

Hello @aheficent,

Thanks for your valuable feedback and keeping your patience to accept my mistakes. I added the unit tests as you suggested. Could you please review again ?

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

Code looks nice. Only a minor thing

# © 2017 Genweb2 Limited - Matiar Rahman
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
from . import tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Importing tests is not needed

Copy link
Author

Choose a reason for hiding this comment

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

Hi @aheficent ,

I fixed that. Thanks.

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

It works fine. Just a little thing. Can you remove the Create and edit from the widget?
image

BTW, have you signed the CLA?

@Matiar
Copy link
Author

Matiar commented Oct 28, 2017

Hello @aheficent ,

Thanks for your review and valuable feedback, But IMHO, the change you suggested belongs to the feature of HR module, do you think this module (hr_employee_operating_unit) is the right place to
implement your suggested change ?

@JordiBForgeFlow
Copy link
Sponsor Member

JordiBForgeFlow commented Oct 28, 2017 via email

@oca-clabot
Copy link

Hey @Matiar, thank you for your Pull Request.

It looks like some users haven't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement here: http://odoo-community.org/page/website.cla
Here is a list of the users:

Appreciation of efforts,
OCA CLAbot

@oca-clabot
Copy link

Hey @Matiar,
We acknowledge that the following users have signed our Contributor License Agreement:

Appreciation of efforts,
OCA CLAbot

@Matiar
Copy link
Author

Matiar commented Oct 29, 2017

Hello @aheficent ,

Thanks for your feedback. I incorporated your suggested change. Could you please review again ?
And yes, I signed the CLA couple of months back.

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

Tested on runbot and working fine. Just some minor comments to the code.

<?xml version="1.0" encoding="utf-8"?>

<odoo>
<data noupdate="0">
Copy link
Contributor

Choose a reason for hiding this comment

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

data it's not necessary anymore. Use

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry. I meant <odoo noupdate="0"> but it does not matter because that it's the same as <odoo>

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<openerp>
Copy link
Contributor

Choose a reason for hiding this comment

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

odoo

</field>
</record>

<!-- Employee -->
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed IMO

@Matiar
Copy link
Author

Matiar commented Oct 30, 2017

Hello @aheficent ,

Thanks again for your time and feedback. I've fixed your suggested changes. Take a look at your convenient time.

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

👍 Functional + code. Thanks @Matiar for attending all the comments.

@Matiar
Copy link
Author

Matiar commented Nov 1, 2017

Hello @aheficent ,

Thanks for your time and approve the PR. Could you please inform me what will be my next step to merge the PR with OCA branch or when it will be merged ?

@AaronHForgeFlow
Copy link
Contributor

AaronHForgeFlow commented Nov 2, 2017

Hi @Matiar we need at least two more approvals. Normally it takes some time but eventually it'll be merged 😄

Copy link

@grindtildeath grindtildeath left a comment

Choose a reason for hiding this comment

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

@Matiar
Thanks for your contribution. Here are a few remarks/recommandations.


@api.model
def _get_operating_unit(self):
user = self.env['res.users'].browse(self._uid)

Choose a reason for hiding this comment

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

No need to browse here, you can do return self.env.user.default_operating_unit_id

return user.default_operating_unit_id

@api.model
def _get_operating_units(self):

Choose a reason for hiding this comment

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

I suppose you can get rid of this method and call directly _get_operating_unit ?

operating_unit_ids = fields.Many2many('operating.unit',
'operating_unit_emp_rel',
'emp_id', 'ou_id', 'Operating Units',
default=_get_operating_units)

Choose a reason for hiding this comment

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

Please use lambda to proxy the call to _get_operating_unit

def _create_user(self, login, groups, company, operating_units):
""" Create a user. """
group_ids = [group.id for group in groups]
user = self.res_users_model.create({

Choose a reason for hiding this comment

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

Here would be nice to add with_context('no_reset_password': True, 'mail_create_nosubscribe': True) to avoid sending unnecessary emails during the test.


def _create_user(self, login, groups, company, operating_units):
""" Create a user. """
group_ids = [group.id for group in groups]

Choose a reason for hiding this comment

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

You can remove this line and do groups.ids to get the same list.

'email': 'test@yourcompany.com',
'company_id': company.id,
'company_ids': [(4, company.id)],
'operating_unit_ids': [(4, ou.id) for ou in operating_units],
Copy link

Choose a reason for hiding this comment

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

Shouldn't [6, 0, operating_units.ids] do the same ?


emp = self.hr_employee_model.sudo(self.user2.id).search(
[('id', '=', self.emp1.id),
('operating_unit_ids', '=', self.main_OU.id)])

Choose a reason for hiding this comment

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

Not sure this is working as operating_unit_ids is a x2m field. You probably should use in instead of = or remove the line all together as you're already searching with an id.

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>

<odoo>

Choose a reason for hiding this comment

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

Missed in the last review but please add noupdate="1" here.

<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>

Choose a reason for hiding this comment

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

I'm not sure about this but all the other modules only define perm_read to 1 on the record rule. Is there any reason to set all the perms to 1 ?

@AaronHForgeFlow
Copy link
Contributor

Hi @Matiar are you still working on this?

@max3903 max3903 added this to the 10.0 milestone Dec 27, 2019
@github-actions
Copy link

github-actions bot commented Nov 7, 2021

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Nov 7, 2021
@github-actions github-actions bot closed this Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants