mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
@@ -1,13 +1,16 @@
|
||||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
class TestAccountPayment(SavepointCase):
|
||||
class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAccountPayment, cls).setUpClass()
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
cls.company = cls.company_data["company"]
|
||||
cls.env.user.company_ids += cls.company
|
||||
|
||||
# MODELS
|
||||
cls.account_payment_model = cls.env["account.payment"]
|
||||
@@ -16,17 +19,28 @@ class TestAccountPayment(SavepointCase):
|
||||
|
||||
# INSTANCES
|
||||
# Payment methods
|
||||
(
|
||||
cls.inbound_payment_method_01,
|
||||
cls.inbound_payment_method_02,
|
||||
) = cls.payment_method_model.search([("payment_type", "=", "inbound")], limit=2)
|
||||
cls.outbound_payment_method_01 = cls.payment_method_model.search(
|
||||
[("payment_type", "=", "outbound")], limit=1
|
||||
cls.inbound_payment_method_01 = cls.payment_method_model.create(
|
||||
{
|
||||
"name": "inbound",
|
||||
"code": "IN",
|
||||
"payment_type": "inbound",
|
||||
}
|
||||
)
|
||||
cls.inbound_payment_method_02 = cls.inbound_payment_method_01.copy(
|
||||
{
|
||||
"name": "inbound 2",
|
||||
"code": "IN2",
|
||||
}
|
||||
)
|
||||
cls.outbound_payment_method_01 = cls.payment_method_model.create(
|
||||
{
|
||||
"name": "outbound",
|
||||
"code": "OUT",
|
||||
"payment_type": "outbound",
|
||||
}
|
||||
)
|
||||
# Journals
|
||||
cls.bank_journal = cls.account_journal_model.search(
|
||||
[("type", "=", "bank")], limit=1
|
||||
)
|
||||
cls.bank_journal = cls.company_data["default_journal_bank"]
|
||||
cls.bank_journal.inbound_payment_method_ids = [
|
||||
(
|
||||
6,
|
||||
@@ -62,8 +76,15 @@ class TestAccountPayment(SavepointCase):
|
||||
self.assertFalse(self.inbound_payment_method_01.payment_order_only)
|
||||
self.assertFalse(self.inbound_payment_method_02.payment_order_only)
|
||||
self.assertFalse(self.bank_journal.inbound_payment_order_only)
|
||||
new_account_payment = self.account_payment_model.new(
|
||||
{"journal_id": self.bank_journal.id, "payment_type": "inbound", "amount": 1}
|
||||
new_account_payment = self.account_payment_model.with_context(
|
||||
default_company_id=self.company.id
|
||||
).new(
|
||||
{
|
||||
"journal_id": self.bank_journal.id,
|
||||
"payment_type": "inbound",
|
||||
"amount": 1,
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
# check journals
|
||||
journals = new_account_payment._get_default_journal()
|
||||
|
||||
@@ -6,59 +6,64 @@
|
||||
from datetime import date, timedelta
|
||||
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tests.common import Form, SavepointCase
|
||||
from odoo.tests.common import Form
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
class TestPaymentOrderInboundBase(SavepointCase):
|
||||
class TestPaymentOrderInboundBase(AccountTestInvoicingCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
self = cls
|
||||
super().setUpClass()
|
||||
self.env.user.company_id = self.env.ref("base.main_company").id
|
||||
self.inbound_mode = self.env.ref(
|
||||
"account_payment_mode.payment_mode_inbound_dd1"
|
||||
)
|
||||
self.invoice_line_account = self.env["account.account"].create(
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
cls.company = cls.company_data["company"]
|
||||
cls.env.user.company_id = cls.company.id
|
||||
cls.partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Test account",
|
||||
"code": "TEST1",
|
||||
"user_type_id": self.env.ref("account.data_account_type_revenue").id,
|
||||
"name": "Test Partner",
|
||||
}
|
||||
)
|
||||
self.journal = self.env["account.journal"].search(
|
||||
[("type", "=", "bank"), ("company_id", "=", self.env.user.company_id.id)],
|
||||
limit=1,
|
||||
cls.inbound_mode = cls.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Test Direct Debit of customers",
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_in"
|
||||
).id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
self.inbound_mode.variable_journal_ids = self.journal
|
||||
cls.invoice_line_account = cls.company_data["default_account_revenue"]
|
||||
cls.journal = cls.company_data["default_journal_bank"]
|
||||
cls.inbound_mode.variable_journal_ids = cls.journal
|
||||
# Make sure no others orders are present
|
||||
self.domain = [
|
||||
cls.domain = [
|
||||
("state", "=", "draft"),
|
||||
("payment_type", "=", "inbound"),
|
||||
("company_id", "=", self.env.user.company_id.id),
|
||||
("company_id", "=", cls.env.user.company_id.id),
|
||||
]
|
||||
self.payment_order_obj = self.env["account.payment.order"]
|
||||
self.payment_order_obj.search(self.domain).unlink()
|
||||
cls.payment_order_obj = cls.env["account.payment.order"]
|
||||
cls.payment_order_obj.search(cls.domain).unlink()
|
||||
# Create payment order
|
||||
self.inbound_order = self.env["account.payment.order"].create(
|
||||
cls.inbound_order = cls.env["account.payment.order"].create(
|
||||
{
|
||||
"payment_type": "inbound",
|
||||
"payment_mode_id": self.inbound_mode.id,
|
||||
"journal_id": self.journal.id,
|
||||
"payment_mode_id": cls.inbound_mode.id,
|
||||
"journal_id": cls.journal.id,
|
||||
}
|
||||
)
|
||||
# Open invoice
|
||||
self.invoice = self._create_customer_invoice(self)
|
||||
self.invoice.action_post()
|
||||
cls.invoice = cls._create_customer_invoice(cls)
|
||||
cls.invoice.action_post()
|
||||
# Add to payment order using the wizard
|
||||
self.env["account.invoice.payment.line.multi"].with_context(
|
||||
active_model="account.move", active_ids=self.invoice.ids
|
||||
cls.env["account.invoice.payment.line.multi"].with_context(
|
||||
active_model="account.move", active_ids=cls.invoice.ids
|
||||
).create({}).run()
|
||||
|
||||
def _create_customer_invoice(self):
|
||||
with Form(
|
||||
self.env["account.move"].with_context(default_move_type="out_invoice")
|
||||
) as invoice_form:
|
||||
invoice_form.partner_id = self.env.ref("base.res_partner_4")
|
||||
invoice_form.partner_id = self.partner
|
||||
with invoice_form.invoice_line_ids.new() as invoice_line_form:
|
||||
invoice_line_form.product_id = self.env.ref("product.product_product_4")
|
||||
invoice_line_form.name = "product that cost 100"
|
||||
@@ -87,11 +92,8 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase):
|
||||
def test_creation(self):
|
||||
payment_order = self.inbound_order
|
||||
self.assertEqual(len(payment_order.ids), 1)
|
||||
bank_journal = self.env["account.journal"].search(
|
||||
[("type", "=", "bank")], limit=1
|
||||
)
|
||||
|
||||
payment_order.write({"journal_id": bank_journal.id})
|
||||
payment_order.write({"journal_id": self.journal.id})
|
||||
|
||||
self.assertEqual(len(payment_order.payment_line_ids), 1)
|
||||
self.assertEqual(len(payment_order.bank_line_ids), 0)
|
||||
|
||||
@@ -6,49 +6,65 @@ from datetime import date, datetime, timedelta
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
class TestPaymentOrderOutbound(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestPaymentOrderOutbound, self).setUp()
|
||||
self.env.user.company_id = self.env.ref("base.main_company").id
|
||||
self.journal = self.env["account.journal"].search(
|
||||
[("type", "=", "bank")], limit=1
|
||||
class TestPaymentOrderOutbound(AccountTestInvoicingCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
cls.company = cls.company_data["company"]
|
||||
cls.env.user.company_id = cls.company.id
|
||||
cls.partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Test Partner",
|
||||
}
|
||||
)
|
||||
self.invoice_line_account = self.env["account.account"].create(
|
||||
cls.invoice_line_account = cls.env["account.account"].create(
|
||||
{
|
||||
"name": "Test account",
|
||||
"code": "TEST1",
|
||||
"user_type_id": self.env.ref("account.data_account_type_expenses").id,
|
||||
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
|
||||
}
|
||||
)
|
||||
self.invoice = self._create_supplier_invoice()
|
||||
self.invoice_02 = self._create_supplier_invoice()
|
||||
self.mode = self.env.ref("account_payment_mode.payment_mode_outbound_ct1")
|
||||
self.creation_mode = self.env.ref(
|
||||
"account_payment_mode.payment_mode_outbound_dd1"
|
||||
cls.mode = cls.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Test Credit Transfer to Suppliers",
|
||||
"company_id": cls.company.id,
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_out"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
self.bank_journal = self.env["account.journal"].search(
|
||||
[("type", "=", "bank"), ("company_id", "=", self.env.user.company_id.id)],
|
||||
limit=1,
|
||||
cls.creation_mode = cls.env["account.payment.mode"].create(
|
||||
{
|
||||
"name": "Test Direct Debit of suppliers from Société Générale",
|
||||
"company_id": cls.company.id,
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_out"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
cls.invoice = cls._create_supplier_invoice(cls)
|
||||
cls.invoice_02 = cls._create_supplier_invoice(cls)
|
||||
cls.bank_journal = cls.company_data["default_journal_bank"]
|
||||
# Make sure no other payment orders are in the DB
|
||||
self.domain = [
|
||||
cls.domain = [
|
||||
("state", "=", "draft"),
|
||||
("payment_type", "=", "outbound"),
|
||||
("company_id", "=", self.env.user.company_id.id),
|
||||
("company_id", "=", cls.env.user.company_id.id),
|
||||
]
|
||||
self.env["account.payment.order"].search(self.domain).unlink()
|
||||
cls.env["account.payment.order"].search(cls.domain).unlink()
|
||||
|
||||
def _create_supplier_invoice(self):
|
||||
invoice = self.env["account.move"].create(
|
||||
{
|
||||
"partner_id": self.env.ref("base.res_partner_4").id,
|
||||
"partner_id": self.partner.id,
|
||||
"move_type": "in_invoice",
|
||||
"payment_mode_id": self.env.ref(
|
||||
"account_payment_mode.payment_mode_outbound_ct1"
|
||||
).id,
|
||||
"payment_mode_id": self.mode.id,
|
||||
"invoice_date": fields.Date.today(),
|
||||
"invoice_line_ids": [
|
||||
(
|
||||
@@ -154,11 +170,8 @@ class TestPaymentOrderOutbound(TransactionCase):
|
||||
|
||||
payment_order = self.env["account.payment.order"].search(self.domain)
|
||||
self.assertEqual(len(payment_order), 1)
|
||||
bank_journal = self.env["account.journal"].search(
|
||||
[("type", "=", "bank")], limit=1
|
||||
)
|
||||
|
||||
payment_order.write({"journal_id": bank_journal.id})
|
||||
payment_order.write({"journal_id": self.bank_journal.id})
|
||||
|
||||
self.assertEqual(len(payment_order.payment_line_ids), 1)
|
||||
self.assertEqual(len(payment_order.bank_line_ids), 0)
|
||||
@@ -191,7 +204,7 @@ class TestPaymentOrderOutbound(TransactionCase):
|
||||
{
|
||||
"payment_type": "outbound",
|
||||
"payment_mode_id": self.mode.id,
|
||||
"journal_id": self.journal.id,
|
||||
"journal_id": self.bank_journal.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
|
||||
Reference in New Issue
Block a user