Skip to content
Snippets Groups Projects
Commit 09274db1 authored by MerlinGuillaume's avatar MerlinGuillaume
Browse files

[FIX] hr_expense: post expense paid by company


It is not possible to post the journal entries related to an expense
paid by the company

Steps to reproduce:
1. Install Expense
2. Create an expense payable to company
3. Set an amount
4. Create report
5. Submit report
6. Approve report
7. Attempt to post
8. An error is thrown

Solution:
Relax the constraint on account.move.line linked to an expense paid by
the company

Problem:
The constraint `_check_payable_receivable` in the account module forbids
to post the journal entries even though they are correct

opw-3038648

closes odoo/odoo#105850

Signed-off-by: default avatarWilliam André (wan) <wan@odoo.com>
parent c6ee7a99
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import api, fields, models
from odoo.tools.misc import frozendict
......@@ -10,6 +10,10 @@ class AccountMoveLine(models.Model):
expense_id = fields.Many2one('hr.expense', string='Expense', copy=False)
@api.constrains('account_id', 'display_type')
def _check_payable_receivable(self):
super(AccountMoveLine, self.filtered(lambda line: not line.expense_id or line.expense_id.payment_mode != 'company_account'))._check_payable_receivable()
def reconcile(self):
# OVERRIDE
not_paid_expenses = self.expense_id.filtered(lambda expense: expense.state != 'done')
......
......@@ -231,6 +231,28 @@ class TestExpenses(TestExpenseCommon):
},
])
def test_expense_company_account(self):
""" Create an expense with payment mode 'Company' and post it (it should not fail) """
with Form(self.env['hr.expense']) as expense_form:
expense_form.name = 'Company expense'
expense_form.date = '2022-11-17'
expense_form.total_amount = 1000.0
expense_form.payment_mode = 'company_account'
expense_form.employee_id = self.expense_employee
expense_form.product_id = self.product_a
expense = expense_form.save()
with Form(self.env['hr.expense.sheet']) as expense_sheet_form:
# Use same values that will be used by action_submit_expenses
expense_sheet_form.employee_id = expense.employee_id
expense_sheet_form.name = expense.name
expense_sheet_form.expense_line_ids.add(expense)
expense_sheet = expense_sheet_form.save()
expense_sheet.action_submit_sheet()
expense_sheet.approve_expense_sheets()
expense_sheet.action_sheet_move_create()
def test_account_entry_multi_currency(self):
""" Checking accounting move entries and analytic entries when submitting expense. With
multi-currency. And taxes. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment