Files
bank-payment/account_banking_mandate/tests/test_mandate.py
Pedro M. Baeza 9e10cee711 [FIX] account_banking_sepa_direct_debit:
* Fix tests due to upstream change

  Odoo has added a constraint for avoiding a company currency change if there
  are move lines, making these tests to fail, as the currency is changed to EUR.

  With this commit, we create a new company with EUR currency for avoiding the
  problem.

  This commit also changes account_banking_mandate for not duplicating mandate
  number, as it was detected during the test creation.

  Similar to 1f8e345469695d1fb1a2ba2109ddea3adbdf1f78
* Avoid errors in tests when run with other modules
* More adaptations to make tests to work properly

  All these problems comes from using demo data.
2023-03-13 08:58:32 +01:00

136 lines
5.0 KiB
Python

# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from odoo import fields
from odoo.exceptions import UserError, ValidationError
from datetime import timedelta
class TestMandate(TransactionCase):
def test_mandate_01(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
self.assertEqual(mandate.state, 'draft')
mandate.validate()
self.assertEqual(mandate.state, 'valid')
mandate.cancel()
self.assertEqual(mandate.state, 'cancel')
mandate.back2draft()
self.assertEqual(mandate.state, 'draft')
def test_mandate_02(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
with self.assertRaises(UserError):
mandate.back2draft()
def test_mandate_03(self):
bank_account = self.env.ref(
'account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
mandate.validate()
with self.assertRaises(UserError):
mandate.validate()
def test_mandate_04(self):
bank_account = self.env.ref(
'account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
mandate.validate()
mandate.cancel()
with self.assertRaises(UserError):
mandate.cancel()
def test_onchange_methods(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].new({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
bank_account_2 = self.env.ref(
'account_payment_mode.res_partner_2_iban')
mandate.partner_bank_id = bank_account_2
mandate.mandate_partner_bank_change()
self.assertEquals(mandate.partner_id, bank_account_2.partner_id)
def test_constrains_01(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
mandate.validate()
with self.assertRaises(ValidationError):
mandate.signature_date = fields.Date.to_string(
fields.Date.from_string(
fields.Date.context_today(mandate)) + timedelta(days=1))
def test_constrains_02(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
with self.assertRaises(ValidationError):
mandate.company_id = self.company_2
def test_constrains_03(self):
bank_account = self.env.ref('account_payment_mode.res_partner_12_iban')
mandate = self.env['account.banking.mandate'].create({
'partner_bank_id': bank_account.id,
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
bank_account_2 = self.env['res.partner.bank'].create({
'acc_number': '1234',
'company_id': self.company_2.id,
})
with self.assertRaises(ValidationError):
mandate.partner_bank_id = bank_account_2
def test_constrains_04(self):
mandate = self.env['account.banking.mandate'].create({
'signature_date': '2015-01-01',
'company_id': self.company.id,
})
bank_account = self.env['res.partner.bank'].create({
'acc_number': '1234',
'company_id': self.company_2.id,
})
with self.assertRaises(ValidationError):
bank_account.mandate_ids += mandate
def setUp(self):
res = super(TestMandate, self).setUp()
# Company
self.company = self.env.ref('base.main_company')
# Company 2
self.company_2 = self.env['res.company'].create({
'name': 'Company 2',
})
return res