[FIX] hr_expense: Fix payment method line flow
The payment method line set on the expense sheet isn't the one used on the payment. The 'print check' payment method test, requiring the 'account_check_printing' installation and that module not being in hr_expense dependencies would fail if both weren't installed. A new and more method-agnostic test replaces it Task-3498991 closes odoo/odoo#145017 X-original-commit: c9554cb Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Julien Alardot (jual) <jual@odoo.com>
This commit is contained in:
@@ -726,11 +726,7 @@ class HrExpense(models.Model):
|
||||
self.ensure_one()
|
||||
|
||||
journal = self.sheet_id.journal_id
|
||||
payment_method_line = self.env['account.payment.method.line'].search(
|
||||
[('payment_type', '=', 'outbound'),
|
||||
('journal_id', '=', journal.id),
|
||||
('code', '=', 'manual'),
|
||||
('company_id', '=', self.company_id.id)], limit=1)
|
||||
payment_method_line = self.sheet_id.payment_method_line_id
|
||||
if not payment_method_line:
|
||||
raise UserError(_("You need to add a manual payment method on the journal (%s)", journal.name))
|
||||
move_lines = []
|
||||
|
||||
@@ -260,7 +260,7 @@ class HrExpenseSheet(models.Model):
|
||||
@api.depends('selectable_payment_method_line_ids')
|
||||
def _compute_payment_method_line_id(self):
|
||||
for sheet in self:
|
||||
sheet.payment_method_line_id = sheet.selectable_payment_method_line_ids._origin[:1]
|
||||
sheet.payment_method_line_id = sheet.selectable_payment_method_line_ids[:1]
|
||||
|
||||
@api.depends('employee_journal_id', 'payment_method_line_id')
|
||||
def _compute_journal_id(self):
|
||||
|
||||
@@ -693,3 +693,38 @@ class TestExpenses(TestExpenseCommon):
|
||||
'res_model': 'account.move',
|
||||
'res_id': expense_sheet.account_move_ids[1].id
|
||||
}])
|
||||
|
||||
def test_expense_payment_method(self):
|
||||
default_payment_method_line = self.company_data['default_journal_bank'].outbound_payment_method_line_ids[0]
|
||||
check_method = self.env['account.payment.method'].sudo().create({
|
||||
'name': 'Print checks',
|
||||
'code': 'check_printing_expense_test',
|
||||
'payment_type': 'outbound',
|
||||
})
|
||||
new_payment_method_line = self.env['account.payment.method.line'].create({
|
||||
'name': 'Check',
|
||||
'payment_method_id': check_method.id,
|
||||
'journal_id': self.company_data['default_journal_bank'].id,
|
||||
})
|
||||
|
||||
expense_sheet = self.env['hr.expense.sheet'].create({
|
||||
'name': 'Sheet test',
|
||||
'employee_id': self.expense_employee.id,
|
||||
'payment_method_line_id': default_payment_method_line.id,
|
||||
'expense_line_ids': [Command.create({
|
||||
'name': 'test payment_mode',
|
||||
'employee_id': self.expense_employee.id,
|
||||
'product_id': self.product_c.id,
|
||||
'payment_mode': 'company_account',
|
||||
'total_amount': 60,
|
||||
'tax_ids': [self.tax_purchase_a.id, self.tax_purchase_b.id],
|
||||
})],
|
||||
})
|
||||
|
||||
self.assertRecordValues(expense_sheet, [{'payment_method_line_id': default_payment_method_line.id}])
|
||||
expense_sheet.payment_method_line_id = new_payment_method_line
|
||||
|
||||
expense_sheet.action_submit_sheet()
|
||||
expense_sheet.action_approve_expense_sheets()
|
||||
expense_sheet.action_sheet_move_create()
|
||||
self.assertRecordValues(expense_sheet.account_move_ids.payment_id, [{'payment_method_line_id': new_payment_method_line.id}])
|
||||
|
||||
Reference in New Issue
Block a user