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

[17.0][FIX] hr_employee_calendar_planning: Change test employee name #1409

Merged

Conversation

pilarvargas-tecnativa
Copy link
Contributor

@pilarvargas-tecnativa pilarvargas-tecnativa commented Dec 10, 2024

This test collides with the dms module. In this test an employee is being created with a name that already exists in another test. The employee's file directory is created with the name of this employee. As there is already an employee with that name, there is already a directory with that name and this is what causes the error. As the probability of 2 employees with the same name coinciding in the same company is very small, instead of intervening in the logic for the creation of the employee's directory, we change the name of the employee in the test so that it does not cause the error when executing this module together with dms.
In the hypothetical case of two employees with the same name within the same company, we would have to resort to using other tools, either by creating an additional module to modify the logic and add an employee identifier to the name of the directory.
Another option is to use the dms_field module.

cc @Tecnativa TT52110

@pedrobaeza @victoralmau please review

2024-12-09 16:51:37,466 47 �[1;31m�[1;49mERROR�[0m prod odoo.addons.hr_employee_calendar_planning.tests.test_hr_employee_calendar_planning: ERROR: TestHrEmployeeCalendarPlanning.test_employee_with_calendar_ids
Traceback (most recent call last):
  File "/opt/odoo/auto/addons/hr_employee_calendar_planning/tests/test_hr_employee_calendar_planning.py", line 417, in test_employee_with_calendar_ids
    employee = self.env["hr.employee"].create(
  File "<decorator-gen-428>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 414, in _model_create_multi
    return create(self, [arg])
  File "/opt/odoo/auto/addons/hr_employee_calendar_planning/models/hr_employee.py", line 179, in create
    res = super().create(vals_list)
  File "<decorator-gen-217>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/hr_attendance/models/hr_employee.py", line 61, in create
    return super().create(vals_list)
  File "<decorator-gen-203>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/hr/models/hr_employee.py", line 411, in create
    employee_sudo.work_contact_id.image_1920 = employee_sudo.image_1920
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1322, in __set__
    records.write({self.name: write_value})
  File "/opt/odoo/auto/addons/base_vat/models/res_partner.py", line 789, in write
    res = super().write(values)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/res_partner.py", line 736, in write
    result = result and super(Partner, self).write(vals)
  File "/opt/odoo/auto/addons/mail/models/mail_activity_mixin.py", line 250, in write
    return super(MailActivityMixin, self).write(vals)
  File "/opt/odoo/auto/addons/mail/models/mail_thread.py", line 311, in write
    return super(MailThread, self).write(values)
  File "/opt/odoo/auto/addons/website/models/mixins.py", line 218, in write
    return super(WebsitePublishedMixin, self).write(values)
  File "/opt/odoo/auto/addons/mail_tracking/models/mail_bounced_mixin.py", line 32, in write
    return super().write(vals)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4425, in write
    field.write(self, value)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 2563, in write
    super(Image, self).write(records, new_value)
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 2498, in write
    atts.create([{
  File "<decorator-gen-319>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/dms/models/ir_attachment.py", line 92, in create
    records._dms_operations()
  File "/opt/odoo/auto/addons/dms/models/ir_attachment.py", line 63, in _dms_operations
    attachment._dms_directories_create()
  File "/opt/odoo/auto/addons/dms/models/ir_attachment.py", line 27, in _dms_directories_create
    self.env["dms.directory"].sudo().with_context(check_name=False).create(
  File "<decorator-gen-316>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 414, in _model_create_multi
    return create(self, [arg])
  File "/opt/odoo/auto/addons/dms/models/directory.py", line 669, in create
    res = super(DmsDirectory, self.with_context(**ctx)).create(vals_list)
  File "<decorator-gen-315>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/dms/models/dms_security_mixin.py", line 255, in create
    res = super(DmsSecurityMixin, self.sudo()).create(vals_list)
  File "<decorator-gen-138>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/mail/models/mail_thread.py", line 255, in create
    threads = super(MailThread, self).create(vals_list)
  File "<decorator-gen-136>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/auto/addons/mail/models/mail_alias_mixin_optional.py", line 92, in create
    records = super().create(valid_vals_list)
  File "<decorator-gen-12>", line 2, in create
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 415, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4627, in create
    records = self._create(data_list)
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 4889, in _create
    records._validate_fields(name for data in data_list for name in data['stored'])
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 1463, in _validate_fields
    check(self)
  File "/opt/odoo/auto/addons/dms/models/directory.py", line 581, in _check_name
    raise ValidationError(
odoo.exceptions.ValidationError: A directory with the same name already exists.

This test collides with the dms module. In this test an employee is
being created with a name that already exists in another test.
The employee's file directory is created with the name of this employee.
As there is already an employee with that name, there is already a
directory with that name and this is what causes the error. As the
probability of 2 employees with the same name coinciding in the same
company is very small, instead of intervening in the logic for the
creation of the employee's directory, we change the name of the
employee in the test so that it does not cause the error when
executing this module together with dms.
In the hypothetical case of two employees with the same name within
the same company, we would have to resort to using other tools, either
by creating an additional module to modify the logic and add an employee
identifier to the name of the directory.

TT52110
@OCA-git-bot
Copy link
Contributor

Hi @pedrobaeza, @victoralmau,
some modules you are maintaining are being modified, check this out!

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 17.0-ocabot-merge-pr-1409-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 733a9d9. Thanks a lot for contributing to OCA. ❤️

@OCA-git-bot OCA-git-bot merged commit f129360 into OCA:17.0 Dec 10, 2024
7 checks passed
@pedrobaeza pedrobaeza deleted the 17.0-fix-hr_employee_calendar_planning-test branch December 10, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants