[FIX] hr_contract: fix wrong salary structure in applicant salary conf.

To reproduce (on runbot):

- Enable "debug" mode
- Switch to company "My Begian Company"
- Go to: Payroll / Configuration / Contracts / Template

- Create a new contract template:
   * Name: Student contract template
   * Salary structure: Belgian Student
   * Job position: Student

- Create a new applicant for job position (Student)
  - name: John Doe
  - email: john@example.com

- Click "Generate Offer":
  - Contract Template: Student contract template
  - Click "Save"

- On the offer, click "Salary Configurator"

=> by default student has only 1 benefic in kind (regular pay) but on
the salary configurator you see many more entries listed (ex: 13th Month)
that are coming from another salary structure (Belgian Employee).

During the simulation as no employee exists (it's an applicant), a new
"temporary" employee is created and assignee to the contract; this
update the company which trigger a recomputation of the `structure_type_id`
field (since odoo/odoo@21aca4704) resetting its value to the country's
default.

This commit ensure we only reset that field when the country do change

closes odoo/odoo#147079

Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
Xavier ALT
2023-12-27 14:57:58 +00:00
parent 56a10b4536
commit eb05e4889d
+14 -4
View File
@@ -96,11 +96,21 @@ class Contract(models.Model):
@api.depends('company_id')
def _compute_structure_type_id(self):
structure_type_id = self.env['hr.payroll.structure.type'].search([('country_id', '=', self.company_id.country_id.id)], limit=1)
if not structure_type_id:
structure_type_id = self.env['hr.payroll.structure.type'].search([('country_id', '=', False)], limit=1)
default_structure_by_country = {}
def _default_salary_structure(country_id):
default_structure = default_structure_by_country.get(country_id)
if default_structure is None:
default_structure = default_structure_by_country[country_id] = (
self.env['hr.payroll.structure.type'].search([('country_id', '=', country_id)], limit=1)
or self.env['hr.payroll.structure.type'].search([('country_id', '=', False)], limit=1)
)
return default_structure
for contract in self:
contract.structure_type_id = structure_type_id
if not contract.structure_type_id or contract.structure_type_id.country_id != contract.company_id.country_id:
contract.structure_type_id = _default_salary_structure(contract.company_id.country_id.id)
@api.onchange('structure_type_id')
def _onchange_structure_type_id(self):