diff --git a/account_payment_order_transfer_journal/README.rst b/account_payment_order_transfer_journal/README.rst new file mode 100644 index 000000000..2a16d2735 --- /dev/null +++ b/account_payment_order_transfer_journal/README.rst @@ -0,0 +1,78 @@ +======================================= +Account Payement Order Transfer Journal +======================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github + :target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_transfer_journal + :alt: OCA/bank-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_order_transfer_journal + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/173/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allow to generate payment order entries on a transfer journal + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Set transfer jounrnal directly on the bank journal. If there is no transfer journal, the bank journal itself will be used. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Adrien Peiffer (https://acsone.eu) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/bank-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_order_transfer_journal/__init__.py b/account_payment_order_transfer_journal/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_payment_order_transfer_journal/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_order_transfer_journal/__manifest__.py b/account_payment_order_transfer_journal/__manifest__.py new file mode 100644 index 000000000..ec4fc1a6e --- /dev/null +++ b/account_payment_order_transfer_journal/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Payement Order Transfer Journal", + "summary": """ + Add the possibility to book payement order operations on a transfert journal.""", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/bank-payment", + "depends": ["account_payment_order"], + "data": [ + "views/account_journal.xml", + ], + "demo": [], +} diff --git a/account_payment_order_transfer_journal/models/__init__.py b/account_payment_order_transfer_journal/models/__init__.py new file mode 100644 index 000000000..eb04dbf35 --- /dev/null +++ b/account_payment_order_transfer_journal/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_journal +from . import account_payment_order diff --git a/account_payment_order_transfer_journal/models/account_journal.py b/account_payment_order_transfer_journal/models/account_journal.py new file mode 100644 index 000000000..466f8c5b5 --- /dev/null +++ b/account_payment_order_transfer_journal/models/account_journal.py @@ -0,0 +1,15 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountJournal(models.Model): + + _inherit = "account.journal" + + transfer_journal_id = fields.Many2one( + comodel_name="account.journal", + string="Transfer journal on payment/debit orders", + help="Journal to write payment entries when confirming payment/debit orders", + ) diff --git a/account_payment_order_transfer_journal/models/account_payment_order.py b/account_payment_order_transfer_journal/models/account_payment_order.py new file mode 100644 index 000000000..9a20cbac7 --- /dev/null +++ b/account_payment_order_transfer_journal/models/account_payment_order.py @@ -0,0 +1,15 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountPaymentOrder(models.Model): + + _inherit = "account.payment.order" + + def _prepare_move(self, bank_lines=None): + res = super()._prepare_move(bank_lines=bank_lines) + if self.journal_id.transfer_journal_id: + res["journal_id"] = self.journal_id.transfer_journal_id.id + return res diff --git a/account_payment_order_transfer_journal/readme/CONTRIBUTORS.rst b/account_payment_order_transfer_journal/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..94a5ccf20 --- /dev/null +++ b/account_payment_order_transfer_journal/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Adrien Peiffer (https://acsone.eu) diff --git a/account_payment_order_transfer_journal/readme/DESCRIPTION.rst b/account_payment_order_transfer_journal/readme/DESCRIPTION.rst new file mode 100644 index 000000000..048a922ee --- /dev/null +++ b/account_payment_order_transfer_journal/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allow to generate payment order entries on a transfer journal diff --git a/account_payment_order_transfer_journal/readme/USAGE.rst b/account_payment_order_transfer_journal/readme/USAGE.rst new file mode 100644 index 000000000..ae1960c78 --- /dev/null +++ b/account_payment_order_transfer_journal/readme/USAGE.rst @@ -0,0 +1 @@ +Set transfer jounrnal directly on the bank journal. If there is no transfer journal, the bank journal itself will be used. diff --git a/account_payment_order_transfer_journal/static/description/icon.png b/account_payment_order_transfer_journal/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_payment_order_transfer_journal/static/description/icon.png differ diff --git a/account_payment_order_transfer_journal/static/description/index.html b/account_payment_order_transfer_journal/static/description/index.html new file mode 100644 index 000000000..2c5ec388b --- /dev/null +++ b/account_payment_order_transfer_journal/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Account Payement Order Transfer Journal + + + +
+

Account Payement Order Transfer Journal

+ + +

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

+

This module allow to generate payment order entries on a transfer journal

+

Table of contents

+ +
+

Usage

+

Set transfer jounrnal directly on the bank journal. If there is no transfer journal, the bank journal itself will be used.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/bank-payment project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_payment_order_transfer_journal/tests/__init__.py b/account_payment_order_transfer_journal/tests/__init__.py new file mode 100644 index 000000000..528bf2960 --- /dev/null +++ b/account_payment_order_transfer_journal/tests/__init__.py @@ -0,0 +1 @@ +from . import test_payment_order diff --git a/account_payment_order_transfer_journal/tests/test_payment_order.py b/account_payment_order_transfer_journal/tests/test_payment_order.py new file mode 100644 index 000000000..aa4c1309c --- /dev/null +++ b/account_payment_order_transfer_journal/tests/test_payment_order.py @@ -0,0 +1,118 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime, timedelta + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestPaymentOrder(TransactionCase): + def setUp(self): + super().setUp() + self.company = self.env.ref("base.main_company") + self.env.user.company_id = self.company.id + self.partner = self.env["res.partner"].create( + { + "name": "Test Partner", + } + ) + self.product = self.env["product.product"].create({"name": "Test"}) + self.invoice_line_account = self.env["account.account"].create( + { + "name": "Test account", + "code": "TEST1", + "user_type_id": self.env.ref("account.data_account_type_expenses").id, + } + ) + self.bank_journal = self.env["account.journal"].search( + [("company_id", "=", self.company.id), ("type", "=", "bank")], limit=1 + ) + self.transfer_journal = self.env["account.journal"].search( + [("company_id", "=", self.company.id), ("type", "=", "general")], + limit=1, + ) + + self.mode = self.env["account.payment.mode"].create( + { + "name": "Test Credit Transfer to Suppliers", + "company_id": self.company.id, + "payment_method_id": self.env.ref( + "account.account_payment_method_manual_out" + ).id, + "fixed_journal_id": self.bank_journal.id, + "bank_account_link": "fixed", + } + ) + self.invoice = self._create_supplier_invoice("F1242") + # Make sure no other payment orders are in the DB + self.domain = [ + ("state", "=", "draft"), + ("payment_type", "=", "outbound"), + ("company_id", "=", self.env.user.company_id.id), + ] + self.env["account.payment.order"].search(self.domain).unlink() + + def _create_supplier_invoice(self, ref): + invoice = self.env["account.move"].create( + { + "partner_id": self.partner.id, + "move_type": "in_invoice", + "ref": ref, + "payment_mode_id": self.mode.id, + "invoice_date": fields.Date.today(), + "invoice_line_ids": [ + ( + 0, + None, + { + "product_id": self.product.id, + "quantity": 1.0, + "price_unit": 100.0, + "name": "product that cost 100", + "account_id": self.invoice_line_account.id, + }, + ) + ], + } + ) + + return invoice + + def test_payment_order_transfer_jounral(self): + self.invoice.action_post() + self.bank_journal.transfer_journal_id = self.transfer_journal + order_vals = { + "payment_type": "outbound", + "payment_mode_id": self.mode.id, + } + order = self.env["account.payment.order"].create(order_vals) + order.payment_mode_id = self.mode.id + order.payment_mode_id_change() + self.assertEqual(order.journal_id.id, self.bank_journal.id) + + self.assertEqual(len(order.payment_line_ids), 0) + line_create = ( + self.env["account.payment.line.create"] + .with_context(active_model="account.payment.order", active_id=order.id) + .create( + {"date_type": "move", "move_date": datetime.now() + timedelta(days=1)} + ) + ) + line_create.payment_mode = "any" + line_create.move_line_filters_change() + line_create.populate() + line_create.create_payment_lines() + line_created_due = ( + self.env["account.payment.line.create"] + .with_context(active_model="account.payment.order", active_id=order.id) + .create( + {"date_type": "due", "due_date": datetime.now() + timedelta(days=1)} + ) + ) + line_created_due.populate() + line_created_due.create_payment_lines() + order.draft2open() + order.open2generated() + order.generated2uploaded() + self.assertEqual(order.move_ids[0].journal_id, self.transfer_journal) diff --git a/account_payment_order_transfer_journal/views/account_journal.xml b/account_payment_order_transfer_journal/views/account_journal.xml new file mode 100644 index 000000000..c23e15953 --- /dev/null +++ b/account_payment_order_transfer_journal/views/account_journal.xml @@ -0,0 +1,21 @@ + + + + + + account.journal.form (in account_payment_order_transfer_journal) + account.journal + + + + + + + + + + +