<commit_before># -*- coding: utf-8 -*-
# © 2017 Open Net Sàrl
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models, api
from odoo.tools.safe_eval import safe_eval


class HrSalaryRule(models.Model):

    _inherit = 'hr.salary.rule'
    name = fields.Char(translate=True)
    note = fields.Char(translate=True)

    percentage = fields.Float(
        compute="_compute_percentage_from_company",
        required=False)
    amount_base = fields.Float(
        required=False)

    @api.multi
    def _compute_percentage_from_company(self):
        list_fields_per = {
            'fadmin_per': ['l10n_ch_hr_payroll.FADMIN'],
            'avs_per': ['l10n_ch_hr_payroll.AVS_C',
                        'l10n_ch_hr_payroll.AVS_E'],
            'laa_per': ['l10n_ch_hr_payroll.LAA_C',
                        'l10n_ch_hr_payroll.LAA_E'],
            'lca_per': ['l10n_ch_hr_payroll.LCA_C',
                        'l10n_ch_hr_payroll.LCA_E'],
            'ac_per_off_limit': ['l10n_ch_hr_payroll.AC_C_SOL',
                                 'l10n_ch_hr_payroll.AC_E_SOL'],
            'ac_per_in_limit': ['l10n_ch_hr_payroll.AC_C',
                                'l10n_ch_hr_payroll.AC_E']
        }

        for rule in self:
            for rule_from, rules_to in list_fields_per.items():
                for rule_to in rules_to:
                    rule_to_modify = rule.env['hr.salary.rule'].search([
                        ('id', '=', rule.env.ref(rule_to).id)
                    ])

                    if rule_to_modify.id == rule.id:
                        rule.percentage = getattr(rule.company_id, rule_from)

    @api.multi
    def compute_rule(self, localdict):
        res = super(HrSalaryRule, self).compute_rule(localdict)

        for rule in self:<commit_msg>Checked if salary rule exists in compute<commit_after># -*- coding: utf-8 -*-
# © 2017 Open Net Sàrl
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models, api
from odoo.tools.safe_eval import safe_eval


class HrSalaryRule(models.Model):

    _inherit = 'hr.salary.rule'
    name = fields.Char(translate=True)
    note = fields.Char(translate=True)

    percentage = fields.Float(
        compute="_compute_percentage_from_company",
        required=False)
    amount_base = fields.Float(
        required=False)

    @api.multi
    def _compute_percentage_from_company(self):
        list_fields_per = {
            'fadmin_per': ['l10n_ch_hr_payroll.FADMIN'],
            'avs_per': ['l10n_ch_hr_payroll.AVS_C',
                        'l10n_ch_hr_payroll.AVS_E'],
            'laa_per': ['l10n_ch_hr_payroll.LAA_C',
                        'l10n_ch_hr_payroll.LAA_E'],
            'lca_per': ['l10n_ch_hr_payroll.LCA_C',
                        'l10n_ch_hr_payroll.LCA_E'],
            'ac_per_off_limit': ['l10n_ch_hr_payroll.AC_C_SOL',
                                 'l10n_ch_hr_payroll.AC_E_SOL'],
            'ac_per_in_limit': ['l10n_ch_hr_payroll.AC_C',
                                'l10n_ch_hr_payroll.AC_E']
        }

        for rule in self:
            for rule_from, rules_to in list_fields_per.items():
                for rule_to in rules_to:
                    data_id = self.env['ir.model.data'].search([
                        ('module', '=', 'l10n_ch_hr_payroll'),
                        ('name', '=', rule_to)
                    ])
                    if len(data_id):
                        rule_to_modify = rule.env['hr.salary.rule'].search([
                            ('id', '=', rule.env.ref(rule_to).id)
                        ])

                        if rule_to_modify.id == rule.id:
                            rule.percentage = \
                                getattr(rule.company_id, rule_from)

    @api.multi
    def compute_rule(self, localdict):
        res = super(HrSalaryRule, self).compute_rule(localdict)

        for rule in self:
{'fraction_non_alphanumeric': 0.11285425101214575, 'fraction_numerical': 0.015182186234817813, 'mean_word_length': 1.797593772116065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4218783', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1314, 'n_words': 199}