Skip to content
Snippets Groups Projects
Commit 51d0268c authored by Guillaume (guva)'s avatar Guillaume (guva)
Browse files

[FIX] account_check_printing: print check from expense


When printing a check that comes from an expense,
the check has no reference to the move from which
the payment has been created.

The reason is that we filter the move by taking
only outbounds to complete the check informations,
but moves from an expense are of type entry.

With this commit, we allow moves coming from
expense to be taken into account by adding a
check on line_ids.expense_id.

opw-3044141

closes odoo/odoo#104824

X-original-commit: d005fd85
Signed-off-by: default avatarJohn Laterre (jol) <jol@odoo.com>
parent ca5b49de
No related branches found
No related tags found
No related merge requests found
......@@ -228,7 +228,7 @@ class AccountPayment(models.Model):
def prepare_vals(invoice, partials):
number = ' - '.join([invoice.name, invoice.ref] if invoice.ref else [invoice.name])
if invoice.is_outbound():
if invoice.is_outbound() or invoice.move_type == 'entry':
invoice_sign = 1
partial_field = 'debit_amount_currency'
else:
......@@ -249,10 +249,11 @@ class AccountPayment(models.Model):
'currency': invoice.currency_id,
}
# Decode the reconciliation to keep only invoices.
# Decode the reconciliation to keep only bills.
term_lines = self.line_ids.filtered(lambda line: line.account_id.internal_type in ('receivable', 'payable'))
invoices = (term_lines.matched_debit_ids.debit_move_id.move_id + term_lines.matched_credit_ids.credit_move_id.move_id)\
.filtered(lambda x: x.is_outbound())
invoices = (term_lines.matched_debit_ids.debit_move_id.move_id + term_lines.matched_credit_ids.credit_move_id.move_id) \
.filtered(lambda move: move.is_outbound() or move.move_type == 'entry')
invoices = invoices.sorted(lambda x: x.invoice_date_due or x.date)
# Group partials by invoices.
......@@ -279,7 +280,7 @@ class AccountPayment(models.Model):
else:
stub_lines = [prepare_vals(invoice, partials)
for invoice, partials in invoice_map.items()
if invoice.move_type == 'in_invoice']
if invoice.move_type in ('in_invoice', 'entry')]
# Crop the stub lines or split them on multiple pages
if not self.company_id.account_check_printing_multi_stub:
......
......@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
from odoo.tests import tagged, Form
from odoo.tools.misc import formatLang
from odoo import fields
......@@ -378,3 +379,56 @@ class TestExpenses(TestExpenseCommon):
move = self.env['account.payment'].browse(action['res_id']).move_id
self.assertEqual(move.amount_total_signed, 10.0, 'The total amount of the payment move is not correct')
def test_print_expense_check(self):
"""
Test the check content when printing a check
that comes from an expense
"""
sheet = self.env['hr.expense.sheet'].create({
'company_id': self.env.company.id,
'employee_id': self.expense_employee.id,
'name': 'test sheet',
'expense_line_ids': [
(0, 0, {
'name': 'expense_1',
'date': '2016-01-01',
'product_id': self.product_a.id,
'unit_amount': 10.0,
'employee_id': self.expense_employee.id,
}),
(0, 0, {
'name': 'expense_2',
'date': '2016-01-01',
'product_id': self.product_a.id,
'unit_amount': 1.0,
'employee_id': self.expense_employee.id,
}),
],
})
#actions
sheet.action_submit_sheet()
sheet.approve_expense_sheets()
sheet.action_sheet_move_create()
action_data = sheet.action_register_payment()
payment_method_line = self.env.company.bank_journal_ids.outbound_payment_method_line_ids.filtered(lambda m: m.code == 'check_printing')
with Form(self.env[action_data['res_model']].with_context(action_data['context'])) as wiz_form:
wiz_form.payment_method_line_id = payment_method_line
wizard = wiz_form.save()
action = wizard.action_create_payments()
self.assertEqual(sheet.state, 'done', 'all account.move.line linked to expenses must be reconciled after payment')
payment = self.env[action['res_model']].browse(action['res_id'])
pages = payment._check_get_pages()
stub_line = pages[0]['stub_lines'][:1]
self.assertTrue(stub_line)
move = self.env[action_data['context']['active_model']].browse(action_data['context']['active_ids'])
self.assertDictEqual(stub_line[0], {
'due_date': '',
'number': ' - '.join([move.name, move.ref] if move.ref else [move.name]),
'amount_total': formatLang(self.env, 11.0, currency_obj=self.env.company.currency_id),
'amount_residual': '-',
'amount_paid': formatLang(self.env, 11.0, currency_obj=self.env.company.currency_id),
'currency': self.env.company.currency_id
})
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