Skip to content

Commit

Permalink
Merge PR #1159 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Oct 17, 2023
2 parents 79d8ff8 + 8691893 commit cdd0ed7
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 112 deletions.
102 changes: 52 additions & 50 deletions account_banking_mandate/tests/test_invoice_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,120 +189,122 @@ def test_invoice_constrains(self):
with self.assertRaises(UserError):
invoice.mandate_id = mandate_2

def _create_res_partner(self, name):
return self.env["res.partner"].create({"name": name})
@classmethod
def _create_res_partner(cls, name):
return cls.env["res.partner"].create({"name": name})

def _create_res_bank(self, name, bic, city, country):
return self.env["res.bank"].create(
@classmethod
def _create_res_bank(cls, name, bic, city, country):
return cls.env["res.bank"].create(
{"name": name, "bic": bic, "city": city, "country": country.id}
)

def setUp(self):
res = super(TestInvoiceMandate, self).setUp()
self.company = self.env.ref("base.main_company")

self.partner = self._create_res_partner("Peter with ACME Bank")
self.acme_bank = self._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", self.env.ref("base.be")
@classmethod
def setUpClass(cls):
res = super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)

bank_account = self.env["res.partner.bank"].create(
cls.company = cls.env.ref("base.main_company")
cls.partner = cls._create_res_partner("Peter with ACME Bank")
cls.acme_bank = cls._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", cls.env.ref("base.be")
)
bank_account = cls.env["res.partner.bank"].create(
{
"acc_number": "0023032234211123",
"partner_id": self.partner.id,
"bank_id": self.acme_bank.id,
"company_id": self.company.id,
"partner_id": cls.partner.id,
"bank_id": cls.acme_bank.id,
"company_id": cls.company.id,
}
)

self.company_2 = self.env["res.company"].create({"name": "Company 2"})

self.mandate = self.env["account.banking.mandate"].create(
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)

self.mandate.validate()

self.mode_inbound_acme = self.env["account.payment.mode"].create(
cls.mandate.validate()
cls.mode_inbound_acme = cls.env["account.payment.mode"].create(
{
"name": "Inbound Credit ACME Bank",
"company_id": self.company.id,
"company_id": cls.company.id,
"bank_account_link": "variable",
"payment_method_id": self.env.ref(
"payment_method_id": cls.env.ref(
"account.account_payment_method_manual_in"
).id,
}
)
bank_journal = self.env["account.journal"].search(
bank_journal = cls.env["account.journal"].search(
[
("type", "=", "bank"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
self.mode_inbound_acme.variable_journal_ids = bank_journal
self.mode_inbound_acme.payment_method_id.mandate_required = True
self.mode_inbound_acme.payment_order_ok = True

self.partner.customer_payment_mode_id = self.mode_inbound_acme

self.invoice_account = self.env["account.account"].search(
cls.mode_inbound_acme.variable_journal_ids = bank_journal
cls.mode_inbound_acme.payment_method_id.mandate_required = True
cls.mode_inbound_acme.payment_order_ok = True
cls.partner.customer_payment_mode_id = cls.mode_inbound_acme
cls.invoice_account = cls.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_receivable").id,
cls.env.ref("account.data_account_type_receivable").id,
),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
invoice_line_account = (
self.env["account.account"]
cls.env["account.account"]
.search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_expenses").id,
cls.env.ref("account.data_account_type_expenses").id,
),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
.id
)

invoice_vals = [
(
0,
0,
{
"product_id": self.env.ref("product.product_product_4").id,
"product_id": cls.env.ref("product.product_product_4").id,
"quantity": 1.0,
"account_id": invoice_line_account,
"price_unit": 200.00,
},
)
]

self.invoice = self.env["account.move"].create(
cls.invoice = cls.env["account.move"].create(
{
"partner_id": self.partner.id,
"partner_id": cls.partner.id,
"move_type": "out_invoice",
"company_id": self.company.id,
"journal_id": self.env["account.journal"]
"company_id": cls.company.id,
"journal_id": cls.env["account.journal"]
.search(
[("type", "=", "sale"), ("company_id", "=", self.company.id)],
[("type", "=", "sale"), ("company_id", "=", cls.company.id)],
limit=1,
)
.id,
"invoice_line_ids": invoice_vals,
}
)

return res
20 changes: 16 additions & 4 deletions account_banking_mandate/tests/test_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,23 @@ def test_mandate_reference_06(self):
)
self.assertTrue(mandate.unique_mandate_reference)

def setUp(self):
res = super(TestMandate, self).setUp()
@classmethod
def setUpClass(cls):
res = super(TestMandate, cls).setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)

# Company
self.company = self.env.ref("base.main_company")
cls.company = cls.env.ref("base.main_company")

# Company 2
self.company_2 = self.env["res.company"].create({"name": "Company 2"})
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
return res
83 changes: 49 additions & 34 deletions account_banking_mandate_contact/tests/test_account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,64 @@


class TestAccountPaymentOrder(TransactionCase):
def setUp(self):
super().setUp()
self.partner = self.env["res.partner"].create({"name": "Test Partner"})
self.product = self.env["product.product"].create({"name": "Test product"})
self.partner_bank_core = self._create_res_partner_bank("N-CORE")
self.mandate_core = self._create_mandate(self.partner_bank_core, "CORE")
self.partner_bank_b2b = self._create_res_partner_bank("N-B2B")
self.mandate_b2b = self._create_mandate(self.partner_bank_b2b, "B2B")
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.partner_bank_core = cls._create_res_partner_bank("N-CORE")
cls.mandate_core = cls._create_mandate(cls.partner_bank_core, "CORE")
cls.partner_bank_b2b = cls._create_res_partner_bank("N-B2B")
cls.mandate_b2b = cls._create_mandate(cls.partner_bank_b2b, "B2B")
payment_method_vals = {
"name": "SEPA",
"code": "sepa_direct_debit",
"payment_type": "inbound",
"bank_account_required": True,
}
self.method_sepa = self._create_multi_bank_payment_method(payment_method_vals)
self.journal_bank = self.env["account.journal"].create(
cls.method_sepa = cls._create_multi_bank_payment_method(payment_method_vals)
cls.journal_bank = cls.env["account.journal"].create(
{"name": "BANK", "type": "bank", "code": "bank"}
)
payment_form = Form(self.env["account.payment.mode"])
payment_form = Form(cls.env["account.payment.mode"])
payment_form.name = "SEPA (CORE)"
payment_form.payment_method_id = self.method_sepa
payment_form.payment_method_id = cls.method_sepa
payment_form.bank_account_link = "fixed"
payment_form.fixed_journal_id = self.journal_bank
payment_form.fixed_journal_id = cls.journal_bank
payment_form.payment_order_ok = True
self.payment_core = payment_form.save()
self.payment_b2b = self.payment_core.copy({"name": "SEPA B2B"})
self.partner.customer_payment_mode_id = self.payment_core.id
self.env["account.journal"].create(
cls.payment_core = payment_form.save()
cls.payment_b2b = cls.payment_core.copy({"name": "SEPA B2B"})
cls.partner.customer_payment_mode_id = cls.payment_core.id
cls.env["account.journal"].create(
{"name": "SALE", "type": "sale", "code": "sale"}
)
self.invoice = self._create_invoice()
cls.invoice = cls._create_invoice()
payment_order_form = Form(
self.env["account.payment.order"].with_context(
cls.env["account.payment.order"].with_context(
default_payment_type="inbound"
)
)
payment_order_form.payment_mode_id = self.payment_core
self.payment_order = payment_order_form.save()
payment_order_form.payment_mode_id = cls.payment_core
cls.payment_order = payment_order_form.save()

def _create_multi_bank_payment_method(self, payment_method_vals):
@classmethod
def _create_multi_bank_payment_method(cls, payment_method_vals):
method_get_payment_method_information = (
AccountPaymentMethod._get_payment_method_information
)

def _get_payment_method_information(self):
res = method_get_payment_method_information(self)
def _get_payment_method_information(cls):
res = method_get_payment_method_information(cls)
res[payment_method_vals["code"]] = {
"mode": "multi",
"domain": [("type", "=", "bank")],
Expand All @@ -67,30 +79,33 @@ def _get_payment_method_information(self):
"_get_payment_method_information",
_get_payment_method_information,
):
return self.env["account.payment.method"].create(payment_method_vals)
return cls.env["account.payment.method"].create(payment_method_vals)

def _create_res_partner_bank(self, acc_number):
res_partner_bank_form = Form(self.env["res.partner.bank"])
res_partner_bank_form.partner_id = self.partner
@classmethod
def _create_res_partner_bank(cls, acc_number):
res_partner_bank_form = Form(cls.env["res.partner.bank"])
res_partner_bank_form.partner_id = cls.partner
res_partner_bank_form.acc_number = acc_number
return res_partner_bank_form.save()

def _create_mandate(self, partner_bank, scheme):
mandate_form = Form(self.env["account.banking.mandate"])
@classmethod
def _create_mandate(cls, partner_bank, scheme):
mandate_form = Form(cls.env["account.banking.mandate"])
mandate_form.partner_bank_id = partner_bank
mandate_form.signature_date = fields.Date.from_string("2021-01-01")
mandate = mandate_form.save()
mandate.validate()
return mandate

def _create_invoice(self):
@classmethod
def _create_invoice(cls):
invoice_form = Form(
self.env["account.move"].with_context(default_move_type="out_invoice")
cls.env["account.move"].with_context(default_move_type="out_invoice")
)
invoice_form.partner_id = self.partner
invoice_form.partner_id = cls.partner
invoice_form.invoice_date = fields.Date.from_string("2021-01-01")
with invoice_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product
line_form.product_id = cls.product
line_form.quantity = 1
line_form.price_unit = 30
line_form.tax_ids.clear()
Expand Down
10 changes: 10 additions & 0 deletions account_banking_sepa_credit_transfer/tests/test_sct.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class TestSCT(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.account_model = cls.env["account.account"]
cls.move_model = cls.env["account.move"]
cls.journal_model = cls.env["account.journal"]
Expand Down
21 changes: 16 additions & 5 deletions account_banking_sepa_direct_debit/tests/test_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ def test_expire(self):
self.env["account.banking.mandate"]._sdd_mandate_set_state_to_expired()
self.assertEqual(self.mandate.state, "expired")

def setUp(self):
res = super().setUp()
self.partner = self.env.ref("base.res_partner_12")
bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
self.mandate = self.env["account.banking.mandate"].create(
@classmethod
def setUpClass(cls):
res = super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.partner = cls.env.ref("base.res_partner_12")
bank_account = cls.env.ref("account_payment_mode.res_partner_12_iban")
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": bank_account.id,
"format": "sepa",
Expand Down
10 changes: 10 additions & 0 deletions account_banking_sepa_direct_debit/tests/test_sdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class TestSDDBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.company_B = cls.env["res.company"].create({"name": "Company B"})
user_type_payable = cls.env.ref("account.data_account_type_payable")
cls.account_payable_company_B = cls.env["account.account"].create(
Expand Down
Loading

0 comments on commit cdd0ed7

Please sign in to comment.