[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 move.move_type. opw-3044141 closes odoo/odoo#105157 X-original-commit: b588329a45633f0dec89fe195cf24a8b3671dedd Signed-off-by: John Laterre (jol) <jol@odoo.com> Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
This commit is contained in:
@@ -237,7 +237,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 == 'in_receipt':
|
||||
invoice_sign = 1
|
||||
partial_field = 'debit_amount_currency'
|
||||
else:
|
||||
@@ -261,7 +261,7 @@ class AccountPayment(models.Model):
|
||||
# Decode the reconciliation to keep only invoices.
|
||||
term_lines = self.line_ids.filtered(lambda line: line.account_id.account_type in ('asset_receivable', 'liability_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())
|
||||
.filtered(lambda x: x.is_outbound() or x.move_type == 'in_receipt')
|
||||
invoices = invoices.sorted(lambda x: x.invoice_date_due or x.date)
|
||||
|
||||
# Group partials by invoices.
|
||||
@@ -288,7 +288,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', 'in_receipt')]
|
||||
|
||||
# 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, Command
|
||||
|
||||
|
||||
@@ -551,3 +552,57 @@ class TestExpenses(TestExpenseCommon):
|
||||
self.assertRecordValues(expense_sheet.account_move_id, [{
|
||||
'partner_id': self.expense_user_employee.partner_id.id,
|
||||
}])
|
||||
|
||||
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')
|
||||
|
||||
payments = self.env[action['res_model']].search(action['domain'])
|
||||
for payment in payments:
|
||||
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': payment.date.strftime("%m/%d/%Y"),
|
||||
'number': ' - '.join([move.name, move.ref] if move.ref else [move.name]),
|
||||
'amount_total': formatLang(self.env, move.amount_total, currency_obj=self.env.company.currency_id),
|
||||
'amount_residual': '-',
|
||||
'amount_paid': formatLang(self.env, payment.amount_total, currency_obj=self.env.company.currency_id),
|
||||
'currency': self.env.company.currency_id
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user