From a0d61a623eb16926d27d47aa3e3b8985d03930b9 Mon Sep 17 00:00:00 2001 From: FernandoRomera Date: Tue, 28 Mar 2023 07:43:10 +0200 Subject: [PATCH 1/4] [14.0][FIX] multicompanies --- payroll_account/models/__init__.py | 7 + payroll_account/models/hr_contract.py | 17 + payroll_account/models/hr_payslip.py | 398 ++++++++++++++++++ payroll_account/models/hr_payslip_line.py | 36 ++ payroll_account/models/hr_payslip_run.py | 22 + payroll_account/models/hr_salary_rule.py | 34 ++ payroll_account/tests/test_payroll_account.py | 217 ++++++++++ 7 files changed, 731 insertions(+) create mode 100644 payroll_account/models/__init__.py create mode 100644 payroll_account/models/hr_contract.py create mode 100644 payroll_account/models/hr_payslip.py create mode 100644 payroll_account/models/hr_payslip_line.py create mode 100644 payroll_account/models/hr_payslip_run.py create mode 100644 payroll_account/models/hr_salary_rule.py create mode 100644 payroll_account/tests/test_payroll_account.py diff --git a/payroll_account/models/__init__.py b/payroll_account/models/__init__.py new file mode 100644 index 00000000..298cc38f --- /dev/null +++ b/payroll_account/models/__init__.py @@ -0,0 +1,7 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import hr_contract +from . import hr_payslip_line +from . import hr_payslip_run +from . import hr_payslip +from . import hr_salary_rule diff --git a/payroll_account/models/hr_contract.py b/payroll_account/models/hr_contract.py new file mode 100644 index 00000000..aec0c2bd --- /dev/null +++ b/payroll_account/models/hr_contract.py @@ -0,0 +1,17 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import fields, models + +logger = logging.getLogger(__name__) + + +class HrContract(models.Model): + _inherit = "hr.contract" + _description = "Employee Contract" + + analytic_account_id = fields.Many2one( + "account.analytic.account", "Analytic Account" + ) + journal_id = fields.Many2one("account.journal", "Salary Journal") diff --git a/payroll_account/models/hr_payslip.py b/payroll_account/models/hr_payslip.py new file mode 100644 index 00000000..5a3980bc --- /dev/null +++ b/payroll_account/models/hr_payslip.py @@ -0,0 +1,398 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + +logger = logging.getLogger(__name__) + + +class HrPayslip(models.Model): + _inherit = "hr.payslip" + + date = fields.Date( + "Date Account", + states={"draft": [("readonly", False)]}, + readonly=True, + help="Keep empty to use the period of the validation(Payslip) date.", + ) + journal_id = fields.Many2one( + "account.journal", + "Salary Journal", + readonly=True, + required=True, + states={"draft": [("readonly", False)]}, + default=lambda self: self.env["account.journal"].search( + [("type", "=", "general")], limit=1 + ), + ) + move_id = fields.Many2one( + "account.move", "Accounting Entry", readonly=True, copy=False + ) + + @api.model_create_multi + def create(self, vals_list): + if "journal_id" in self.env.context: + for vals in vals_list: + vals["journal_id"] = self.env.context.get("journal_id") + return super(HrPayslip, self).create(vals_list) + + @api.onchange("contract_id") + def onchange_contract(self): + res = super(HrPayslip, self).onchange_contract() + self.journal_id = ( + self.contract_id.journal_id.id + or (not self.contract_id and self.default_get(["journal_id"])["journal_id"]) + or self.journal_id + ) + return res + + def action_payslip_cancel(self): + for payslip in self: + if not payslip.move_id.journal_id.restrict_mode_hash_table: + payslip.move_id.with_context(force_delete=True).button_cancel() + payslip.move_id.with_context(force_delete=True).unlink() + else: + payslip.move_id._reverse_moves() + payslip.move_id = False + return super(HrPayslip, self).action_payslip_cancel() + + def action_payslip_done(self): + res = super(HrPayslip, self).action_payslip_done() + + for slip in self: + line_ids = [] + debit_sum = 0.0 + credit_sum = 0.0 + date = slip.date or slip.date_to + currency = ( + slip.company_id.currency_id or slip.journal_id.company_id.currency_id + ) + + name = _("Payslip of %s") % (slip.employee_id.name) + move_dict = { + "narration": name, + "ref": slip.number, + "journal_id": slip.journal_id.id, + "date": date, + } + for line in slip.line_ids: + amount = currency.round(slip.credit_note and -line.total or line.total) + if currency.is_zero(amount): + continue + debit_account_id = line.salary_rule_id.account_debit.id + credit_account_id = line.salary_rule_id.account_credit.id + account_id = debit_account_id or credit_account_id + analytic_salary_id = line.salary_rule_id.analytic_account_id + move_line_analytic_ids = {} + if slip.contract_id.analytic_account_id: + move_line_analytic_ids.update( + {line.slip_id.contract_id.analytic_account_id.id: 100} + ) + elif analytic_salary_id: + move_line_analytic_ids.update( + {line.salary_rule_id.analytic_account_id.id: 100} + ) + + tax_ids = False + tax_tag_ids = False + if line.salary_rule_id.tax_line_ids: + account_tax_ids = [ + salary_rule_id.account_tax_id.id + for salary_rule_id in line.salary_rule_id.tax_line_ids + ] + tax_ids = [ + (4, account_tax_id, 0) for account_tax_id in account_tax_ids + ] + tax_tag_ids = ( + self.env["account.tax.repartition.line"] + .search( + [ + ("invoice_tax_id", "in", account_tax_ids), + ("repartition_type", "=", "base"), + ] + ) + .tag_ids + ) + + tax_repartition_line_id = False + if line.salary_rule_id.account_tax_id: + tax_repartition_line_id = ( + self.env["account.tax.repartition.line"] + .search( + [ + ( + "invoice_tax_id", + "=", + line.salary_rule_id.account_tax_id.id, + ), + ("account_id", "=", account_id), + ] + ) + .id + ) + tax_tag_ids = ( + self.env["account.tax.repartition.line"] + .search( + [ + ( + "invoice_tax_id", + "=", + line.salary_rule_id.account_tax_id.id, + ), + ("repartition_type", "=", "tax"), + ("account_id", "=", account_id), + ] + ) + .tag_ids + ) + + if debit_account_id: + debit_line = ( + 0, + 0, + { + "name": line.name, + "partner_id": line._get_partner_id(credit_account=False) + or slip.employee_id.address_home_id.id, + "account_id": debit_account_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": amount > 0.0 and amount or 0.0, + "credit": amount < 0.0 and -amount or 0.0, + "analytic_distribution": move_line_analytic_ids, + "tax_line_id": line.salary_rule_id.account_tax_id.id, + "tax_ids": tax_ids, + "tax_repartition_line_id": tax_repartition_line_id, + "tax_tag_ids": tax_tag_ids, + }, + ) + line_ids.append(debit_line) + debit_sum += debit_line[2]["debit"] - debit_line[2]["credit"] + + if credit_account_id: + credit_line = ( + 0, + 0, + { + "name": line.name, + "partner_id": line._get_partner_id(credit_account=True) + or slip.employee_id.address_home_id.id, + "account_id": credit_account_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": amount < 0.0 and -amount or 0.0, + "credit": amount > 0.0 and amount or 0.0, + "analytic_distribution": move_line_analytic_ids, + "tax_line_id": line.salary_rule_id.account_tax_id.id, + "tax_ids": tax_ids, + "tax_repartition_line_id": tax_repartition_line_id, + "tax_tag_ids": tax_tag_ids, + }, + ) + line_ids.append(credit_line) + credit_sum += credit_line[2]["credit"] - credit_line[2]["debit"] + + if currency.compare_amounts(credit_sum, debit_sum) == -1: + acc_id = slip.journal_id.default_account_id.id + if not acc_id: + raise UserError( + _( + 'The Expense Journal "%s" has not properly ' + "configured the Credit Account!" + ) + % (slip.journal_id.name) + ) + adjust_credit = ( + 0, + 0, + { + "name": _("Adjustment Entry"), + "partner_id": False, + "account_id": acc_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": 0.0, + "credit": currency.round(debit_sum - credit_sum), + }, + ) + line_ids.append(adjust_credit) + + elif currency.compare_amounts(debit_sum, credit_sum) == -1: + acc_id = slip.journal_id.default_account_id.id + if not acc_id: + raise UserError( + _( + 'The Expense Journal "%s" has not properly ' + "configured the Debit Account!" + ) + % (slip.journal_id.name) + ) + adjust_debit = ( + 0, + 0, + { + "name": _("Adjustment Entry"), + "partner_id": False, + "account_id": acc_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": currency.round(credit_sum - debit_sum), + "credit": 0.0, + }, + ) + line_ids.append(adjust_debit) + if len(line_ids) > 0: + move_dict["line_ids"] = line_ids + move = self.env["account.move"].create(move_dict) + slip.write({"move_id": move.id, "date": date}) + move.action_post() + else: + logger.warning( + f"Payslip {slip.number} did not generate any account move lines" + ) + return res + + def _prepare_debit_line( + self, + line, + slip, + amount, + date, + debit_account_id, + analytic_salary_id, + tax_ids, + tax_tag_ids, + tax_repartition_line_id, + ): + return { + "name": line.name, + "partner_id": line._get_partner_id(credit_account=False) + or slip.employee_id.address_home_id.id, + "account_id": debit_account_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": amount > 0.0 and amount or 0.0, + "credit": amount < 0.0 and -amount or 0.0, + "analytic_account_id": analytic_salary_id + or slip.contract_id.analytic_account_id.id, + "tax_line_id": line.salary_rule_id.account_tax_id.id, + "tax_ids": tax_ids, + "tax_repartition_line_id": tax_repartition_line_id, + "tax_tag_ids": tax_tag_ids, + } + + def _prepare_credit_line( + self, + line, + slip, + amount, + date, + credit_account_id, + analytic_salary_id, + tax_ids, + tax_tag_ids, + tax_repartition_line_id, + ): + return { + "name": line.name, + "partner_id": line._get_partner_id(credit_account=True) + or slip.employee_id.address_home_id.id, + "account_id": credit_account_id, + "journal_id": slip.journal_id.id, + "date": date, + "debit": amount < 0.0 and -amount or 0.0, + "credit": amount > 0.0 and amount or 0.0, + "analytic_account_id": analytic_salary_id + or slip.contract_id.analytic_account_id.id, + "tax_line_id": line.salary_rule_id.account_tax_id.id, + "tax_ids": tax_ids, + "tax_repartition_line_id": tax_repartition_line_id, + "tax_tag_ids": tax_tag_ids, + } + + def _prepare_adjust_credit_line( + self, currency, credit_sum, debit_sum, journal, date + ): + acc_id = journal.default_account_id.id + return { + "name": _("Adjustment Entry"), + "partner_id": False, + "account_id": acc_id, + "journal_id": journal.id, + "date": date, + "debit": 0.0, + "credit": currency.round(debit_sum - credit_sum), + } + + def _prepare_adjust_debit_line( + self, currency, credit_sum, debit_sum, journal, date + ): + acc_id = journal.default_account_id.id + return { + "name": _("Adjustment Entry"), + "partner_id": False, + "account_id": acc_id, + "journal_id": journal.id, + "date": date, + "debit": currency.round(credit_sum - debit_sum), + "credit": 0.0, + } + + def _get_tax_details(self, line): + tax_ids = False + tax_tag_ids = False + salary_rule = line.salary_rule_id + if salary_rule.tax_line_ids: + account_tax_ids = [ + salary_rule_id.account_tax_id.id + for salary_rule_id in salary_rule.tax_line_ids + ] + tax_ids = [(4, account_tax_id, 0) for account_tax_id in account_tax_ids] + tax_tag_ids = ( + self.env["account.tax.repartition.line"] + .search( + [ + ("invoice_tax_id", "in", account_tax_ids), + ("repartition_type", "=", "base"), + ] + ) + .tag_ids + ) + + tax_repartition_line_id = False + if salary_rule.account_tax_id: + tax_repartition_line_id = ( + self.env["account.tax.repartition.line"] + .search( + [ + ("invoice_tax_id", "=", salary_rule.account_tax_id.id), + ( + "account_id", + "=", + salary_rule.account_debit.id + or salary_rule.account_credit.id, + ), + ] + ) + .id + ) + tax_tag_ids += ( + self.env["account.tax.repartition.line"] + .search( + [ + ("invoice_tax_id", "=", salary_rule.account_tax_id.id), + ("repartition_type", "=", "tax"), + ( + "account_id", + "=", + salary_rule.account_debit.id + or salary_rule.account_credit.id, + ), + ] + ) + .tag_ids + ) + + return tax_ids, tax_tag_ids, tax_repartition_line_id diff --git a/payroll_account/models/hr_payslip_line.py b/payroll_account/models/hr_payslip_line.py new file mode 100644 index 00000000..a889e805 --- /dev/null +++ b/payroll_account/models/hr_payslip_line.py @@ -0,0 +1,36 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import models + +logger = logging.getLogger(__name__) + + +class HrPayslipLine(models.Model): + _inherit = "hr.payslip.line" + + def _get_partner_id(self, credit_account): + """ + Get partner_id of slip line to use in account_move_line + """ + # use partner of salary rule or fallback on employee's address + register_partner_id = self.salary_rule_id.register_id.partner_id + partner_id = ( + register_partner_id.id or self.slip_id.employee_id.address_home_id.id + ) + if credit_account: + if ( + register_partner_id + or self.salary_rule_id.account_credit.internal_type + in ("receivable", "payable") + ): + return partner_id + else: + if ( + register_partner_id + or self.salary_rule_id.account_debit.internal_type + in ("receivable", "payable") + ): + return partner_id + return False diff --git a/payroll_account/models/hr_payslip_run.py b/payroll_account/models/hr_payslip_run.py new file mode 100644 index 00000000..c0beda5b --- /dev/null +++ b/payroll_account/models/hr_payslip_run.py @@ -0,0 +1,22 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import fields, models + +logger = logging.getLogger(__name__) + + +class HrPayslipRun(models.Model): + _inherit = "hr.payslip.run" + + journal_id = fields.Many2one( + "account.journal", + "Salary Journal", + states={"draft": [("readonly", False)]}, + readonly=True, + required=True, + default=lambda self: self.env["account.journal"].search( + [("type", "=", "general")], limit=1 + ), + ) diff --git a/payroll_account/models/hr_salary_rule.py b/payroll_account/models/hr_salary_rule.py new file mode 100644 index 00000000..f43e639c --- /dev/null +++ b/payroll_account/models/hr_salary_rule.py @@ -0,0 +1,34 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import fields, models + +logger = logging.getLogger(__name__) + + +class HrSalaryRule(models.Model): + _inherit = "hr.salary.rule" + + company_id = fields.Many2one( + "res.company", + string="Company", + default=lambda self: self.env.company, + ) + analytic_account_id = fields.Many2one( + "account.analytic.account", "Analytic Account" + ) + account_tax_id = fields.Many2one("account.tax", "Tax") + account_debit = fields.Many2one( + "account.account", + "Debit Account", + domain=[("deprecated", "=", False), ("company_id", "=", company_id)], + ) + account_credit = fields.Many2one( + "account.account", + "Credit Account", + domain=[("deprecated", "=", False), ("company_id", "=", company_id)], + ) + + tax_base_id = fields.Many2one("hr.salary.rule", "Base") + tax_line_ids = fields.One2many("hr.salary.rule", "tax_base_id", string="Tax lines") diff --git a/payroll_account/tests/test_payroll_account.py b/payroll_account/tests/test_payroll_account.py new file mode 100644 index 00000000..a3afa3e8 --- /dev/null +++ b/payroll_account/tests/test_payroll_account.py @@ -0,0 +1,217 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import datetime, timedelta + +from dateutil import relativedelta + +from odoo import fields +from odoo.tests import common + + +class TestPayrollAccount(common.TransactionCase): + def setUp(self): + super().setUp() + + # Activate company currency + self.env.user.company_id.currency_id.active = True + + self.payslip_action_id = self.ref("payroll.hr_payslip_menu") + + self.res_partner_bank = self.env["res.partner.bank"].create( + { + "acc_number": "001-9876543-21", + "partner_id": self.ref("base.res_partner_12"), + "acc_type": "bank", + "bank_id": self.ref("base.res_bank_1"), + } + ) + + self.hr_employee_john = self.env["hr.employee"].create( + { + "address_home_id": self.ref("base.res_partner_address_2"), + "address_id": self.ref("base.res_partner_address_27"), + "birthday": "1984-05-01", + "children": 0.0, + "country_id": self.ref("base.in"), + "department_id": self.ref("hr.dep_rd"), + "gender": "male", + "marital": "single", + "name": "John", + "bank_account_id": self.res_partner_bank.bank_id.id, + } + ) + + self.hr_salary_rule_houserentallowance1 = self.ref( + "payroll.hr_salary_rule_houserentallowance1" + ) + self.account_debit = self.env["account.account"].create( + { + "name": "Debit Account", + "code": "334411", + "account_type": "expense", + "reconcile": True, + } + ) + self.account_credit = self.env["account.account"].create( + { + "name": "Credit Account", + "code": "114433", + "account_type": "expense", + "reconcile": True, + } + ) + + self.hr_structure_softwaredeveloper = self.env["hr.payroll.structure"].create( + { + "name": "Salary Structure for Software Developer", + "code": "SD", + "company_id": self.ref("base.main_company"), + "parent_id": self.ref("payroll.structure_base"), + "rule_ids": [ + ( + 6, + 0, + [ + self.ref("payroll.hr_salary_rule_houserentallowance1"), + self.ref("payroll.hr_salary_rule_convanceallowance1"), + self.ref("payroll.hr_salary_rule_professionaltax1"), + self.ref("payroll.hr_salary_rule_providentfund1"), + self.ref("payroll.hr_salary_rule_meal_voucher"), + self.ref("payroll.hr_salary_rule_sales_commission"), + ], + ) + ], + } + ) + + self.account_journal = self.env["account.journal"].create( + { + "name": "Vendor Bills - Test", + "code": "TEXJ", + "type": "purchase", + "default_account_id": self.account_debit.id, + "refund_sequence": True, + } + ) + + self.hr_contract_john = self.env["hr.contract"].create( + { + "date_end": fields.Date.to_string(datetime.now() + timedelta(days=365)), + "date_start": fields.Date.today(), + "name": "Contract for John", + "wage": 5000.0, + "employee_id": self.hr_employee_john.id, + "struct_id": self.hr_structure_softwaredeveloper.id, + "journal_id": self.account_journal.id, + } + ) + + self.hr_payslip = self.env["hr.payslip"].create( + { + "employee_id": self.hr_employee_john.id, + "journal_id": self.account_journal.id, + } + ) + + def _update_account_in_rule(self, debit, credit): + rule_houserentallowance1 = self.env["hr.salary.rule"].browse( + self.hr_salary_rule_houserentallowance1 + ) + rule_houserentallowance1.write( + {"account_debit": debit, "account_credit": credit} + ) + + def test_00_hr_payslip(self): + """checking the process of payslip.""" + + date_from = datetime.now() + date_to = datetime.now() + relativedelta.relativedelta( + months=+1, day=1, days=-1 + ) + res = self.hr_payslip.get_payslip_vals( + date_from, date_to, self.hr_employee_john.id + ) + vals = { + "struct_id": res["value"]["struct_id"], + "contract_id": res["value"]["contract_id"], + "name": res["value"]["name"], + } + vals["worked_days_line_ids"] = [ + (0, 0, i) for i in res["value"]["worked_days_line_ids"] + ] + vals["input_line_ids"] = [(0, 0, i) for i in res["value"]["input_line_ids"]] + vals.update({"contract_id": self.hr_contract_john.id}) + self.hr_payslip.write(vals) + + # I assign the amount to Input data. + payslip_input = self.env["hr.payslip.input"].search( + [("payslip_id", "=", self.hr_payslip.id)] + ) + payslip_input.write({"amount": 5.0}) + + # I verify the payslip is in draft state. + self.assertEqual(self.hr_payslip.state, "draft", "State not changed!") + + # I click on "Compute Sheet" button. + self.hr_payslip.with_context( + {}, + lang="en_US", + tz=False, + active_model="hr.payslip", + department_id=False, + active_ids=[self.payslip_action_id], + section_id=False, + active_id=self.payslip_action_id, + ).compute_sheet() + + # I want to check cancel button. + # So I first cancel the sheet then make it set to draft. + self.hr_payslip.action_payslip_cancel() + self.assertEqual(self.hr_payslip.state, "cancel", "Payslip is rejected.") + self.hr_payslip.action_payslip_draft() + + self._update_account_in_rule(self.account_debit, self.account_credit) + self.hr_payslip.action_payslip_done() + + # I verify that the Accounting Entries are created. + self.assertTrue( + self.hr_payslip.move_id, "Accounting Entries has not been created" + ) + + # I verify that the payslip is in done state. + self.assertEqual(self.hr_payslip.state, "done", "State not changed!") + + def test_hr_payslip_no_accounts(self): + + date_from = datetime.now() + date_to = datetime.now() + relativedelta.relativedelta( + months=+1, day=1, days=-1 + ) + res = self.hr_payslip.get_payslip_vals( + date_from, date_to, self.hr_employee_john.id + ) + vals = { + "struct_id": res["value"]["struct_id"], + "contract_id": self.hr_contract_john.id, + "name": res["value"]["name"], + } + self.hr_payslip.write(vals) + + # I click on "Compute Sheet" button. + self.hr_payslip.with_context( + {}, + lang="en_US", + tz=False, + active_model="hr.payslip", + department_id=False, + active_ids=[self.payslip_action_id], + section_id=False, + active_id=self.payslip_action_id, + ).compute_sheet() + + # Confirm Payslip (no account moves) + self.hr_payslip.action_payslip_done() + self.assertFalse(self.hr_payslip.move_id, "Accounting Entries has been created") + + # I verify that the payslip is in done state. + self.assertEqual(self.hr_payslip.state, "done", "State not changed!") From 74b7dc54506048261d4b2dd000bcce0748f01dd3 Mon Sep 17 00:00:00 2001 From: FernandoRomera Date: Tue, 28 Mar 2023 10:14:38 +0200 Subject: [PATCH 2/4] [14.0][FIX] payroll_account: Fix multicompanies and refactoring --- payroll_account/models/hr_contract.py | 3 --- payroll_account/models/hr_payslip_line.py | 3 --- payroll_account/models/hr_payslip_run.py | 3 --- payroll_account/models/hr_salary_rule.py | 3 --- 4 files changed, 12 deletions(-) diff --git a/payroll_account/models/hr_contract.py b/payroll_account/models/hr_contract.py index aec0c2bd..794cba8e 100644 --- a/payroll_account/models/hr_contract.py +++ b/payroll_account/models/hr_contract.py @@ -1,11 +1,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging from odoo import fields, models -logger = logging.getLogger(__name__) - class HrContract(models.Model): _inherit = "hr.contract" diff --git a/payroll_account/models/hr_payslip_line.py b/payroll_account/models/hr_payslip_line.py index a889e805..c00fb9d8 100644 --- a/payroll_account/models/hr_payslip_line.py +++ b/payroll_account/models/hr_payslip_line.py @@ -1,11 +1,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging from odoo import models -logger = logging.getLogger(__name__) - class HrPayslipLine(models.Model): _inherit = "hr.payslip.line" diff --git a/payroll_account/models/hr_payslip_run.py b/payroll_account/models/hr_payslip_run.py index c0beda5b..c7791efe 100644 --- a/payroll_account/models/hr_payslip_run.py +++ b/payroll_account/models/hr_payslip_run.py @@ -1,11 +1,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging from odoo import fields, models -logger = logging.getLogger(__name__) - class HrPayslipRun(models.Model): _inherit = "hr.payslip.run" diff --git a/payroll_account/models/hr_salary_rule.py b/payroll_account/models/hr_salary_rule.py index f43e639c..c5913497 100644 --- a/payroll_account/models/hr_salary_rule.py +++ b/payroll_account/models/hr_salary_rule.py @@ -1,11 +1,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging from odoo import fields, models -logger = logging.getLogger(__name__) - class HrSalaryRule(models.Model): _inherit = "hr.salary.rule" From 4b8c2c6c98dd7c2d83818ff14d30b61b4556f3e7 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Mon, 3 Apr 2023 20:09:56 -0300 Subject: [PATCH 3/4] [FIX] payroll_account: fix company_dependent on debit and credit account --- payroll_account/models/hr_salary_rule.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/payroll_account/models/hr_salary_rule.py b/payroll_account/models/hr_salary_rule.py index c5913497..f08abf1b 100644 --- a/payroll_account/models/hr_salary_rule.py +++ b/payroll_account/models/hr_salary_rule.py @@ -10,6 +10,7 @@ class HrSalaryRule(models.Model): company_id = fields.Many2one( "res.company", string="Company", + required=True, default=lambda self: self.env.company, ) analytic_account_id = fields.Many2one( @@ -19,12 +20,14 @@ class HrSalaryRule(models.Model): account_debit = fields.Many2one( "account.account", "Debit Account", - domain=[("deprecated", "=", False), ("company_id", "=", company_id)], + domain=[("deprecated", "=", False)], + company_dependent=True, ) account_credit = fields.Many2one( "account.account", "Credit Account", - domain=[("deprecated", "=", False), ("company_id", "=", company_id)], + domain=[("deprecated", "=", False)], + company_dependent=True, ) tax_base_id = fields.Many2one("hr.salary.rule", "Base") From 4976035bdba12bf68e17b2d8d9865fdbecfc87d4 Mon Sep 17 00:00:00 2001 From: Henrik Norlin Date: Thu, 30 May 2024 10:00:53 +0200 Subject: [PATCH 4/4] [FIX] payroll_account: hr.payslip.line _get_partner_id() --- payroll_account/models/hr_payslip_line.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/payroll_account/models/hr_payslip_line.py b/payroll_account/models/hr_payslip_line.py index c00fb9d8..6a13c622 100644 --- a/payroll_account/models/hr_payslip_line.py +++ b/payroll_account/models/hr_payslip_line.py @@ -16,18 +16,9 @@ def _get_partner_id(self, credit_account): partner_id = ( register_partner_id.id or self.slip_id.employee_id.address_home_id.id ) + acc_type = self.salary_rule_id.account_debit.account_type if credit_account: - if ( - register_partner_id - or self.salary_rule_id.account_credit.internal_type - in ("receivable", "payable") - ): - return partner_id - else: - if ( - register_partner_id - or self.salary_rule_id.account_debit.internal_type - in ("receivable", "payable") - ): - return partner_id + acc_type = self.salary_rule_id.account_credit.account_type + if register_partner_id or acc_type in ("asset_receivable", "liability_payable"): + return partner_id return False