[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#106266

X-original-commit: 09274db12a25c178974dc20c4d669134e21cddbe
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
MerlinGuillaume
2022-11-22 17:09:27 +01:00
parent 0e3d496936
commit a3d4d2dd7f
2 changed files with 27 additions and 1 deletions
@@ -1,7 +1,7 @@
# -*- 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')
+22
View File
@@ -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. """