From e53f5aec95c997f40bcb7079ce400f94d8cf9f4a Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Tue, 20 Sep 2022 17:47:27 +0200 Subject: [PATCH] [14.0][ADD] account_payment_order_inter_company --- .../README.rst | 77 ++++ .../__init__.py | 1 + .../__manifest__.py | 13 + .../models/__init__.py | 1 + .../models/account_payment_order.py | 99 +++++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 1 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 415 ++++++++++++++++++ .../tests/__init__.py | 1 + ...est_account_payment_order_inter_company.py | 116 +++++ .../account_payment_order_inter_company | 1 + .../setup.py | 6 + 13 files changed, 735 insertions(+) create mode 100644 account_payment_order_inter_company/README.rst create mode 100644 account_payment_order_inter_company/__init__.py create mode 100644 account_payment_order_inter_company/__manifest__.py create mode 100644 account_payment_order_inter_company/models/__init__.py create mode 100644 account_payment_order_inter_company/models/account_payment_order.py create mode 100644 account_payment_order_inter_company/readme/CONTRIBUTORS.rst create mode 100644 account_payment_order_inter_company/readme/DESCRIPTION.rst create mode 100644 account_payment_order_inter_company/security/ir.model.access.csv create mode 100644 account_payment_order_inter_company/static/description/index.html create mode 100644 account_payment_order_inter_company/tests/__init__.py create mode 100644 account_payment_order_inter_company/tests/test_account_payment_order_inter_company.py create mode 120000 setup/account_payment_order_inter_company/odoo/addons/account_payment_order_inter_company create mode 100644 setup/account_payment_order_inter_company/setup.py diff --git a/account_payment_order_inter_company/README.rst b/account_payment_order_inter_company/README.rst new file mode 100644 index 00000000000..c5de90edd2d --- /dev/null +++ b/account_payment_order_inter_company/README.rst @@ -0,0 +1,77 @@ +=================================== +Account Payment Order Inter Company +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/14.0/account_payment_order_inter_company + :alt: OCA/multi-company +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/multi-company-14-0/multi-company-14-0-account_payment_order_inter_company + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/251/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows for an inter-company billing to automatically pay the invoice in Company A as soon as the invoice in Company B is paid. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Sébastien Beau +* Chafique Delli + +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/multi-company `_ 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_inter_company/__init__.py b/account_payment_order_inter_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_payment_order_inter_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_order_inter_company/__manifest__.py b/account_payment_order_inter_company/__manifest__.py new file mode 100644 index 00000000000..8b07dd06e2e --- /dev/null +++ b/account_payment_order_inter_company/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2022 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Account Payment Order Inter Company", + "version": "14.0.1.0.0", + "category": "Accounting & Finance", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/multi-company", + "license": "AGPL-3", + "depends": ["account_invoice_inter_company", "account_payment_order"], + "data": [], + "installable": True, +} diff --git a/account_payment_order_inter_company/models/__init__.py b/account_payment_order_inter_company/models/__init__.py new file mode 100644 index 00000000000..429f03273ec --- /dev/null +++ b/account_payment_order_inter_company/models/__init__.py @@ -0,0 +1 @@ +from . import account_payment_order diff --git a/account_payment_order_inter_company/models/account_payment_order.py b/account_payment_order_inter_company/models/account_payment_order.py new file mode 100644 index 00000000000..4758d391654 --- /dev/null +++ b/account_payment_order_inter_company/models/account_payment_order.py @@ -0,0 +1,99 @@ +# Copyright 2022 Akretion France (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountPaymentOrder(models.Model): + _inherit = "account.payment.order" + + def _prepare_move_line_vals(self, payment_line, invoice, journal, company): + vals_list = [] + vals1 = {} + vals2 = {} + vals = { + "journal_id": journal.id, + "move_id": invoice.id, + "partner_id": invoice.partner_id.id, + "company_id": company.id, + } + if invoice.move_type == "out_invoice": + vals1 = { + "account_id": journal.suspense_account_id.id, + "debit": payment_line.amount_currency, + "credit": 0.0, + } + vals1.update(vals) + vals2 = { + "account_id": invoice.partner_id.with_company( + company.id + ).property_account_receivable_id.id, + "credit": payment_line.amount_currency, + "debit": 0.0, + } + vals2.update(vals) + elif invoice.move_type == "in_invoice": + vals1 = { + "account_id": journal.suspense_account_id.id, + "debit": 0.0, + "credit": payment_line.amount_currency, + } + vals1.update(vals) + vals2 = { + "account_id": invoice.partner_id.with_company( + company.id + ).property_account_payable_id.id, + "credit": 0.0, + "debit": payment_line.amount_currency, + } + vals2.update(vals) + if vals1 and vals2: + vals_list.extend((vals1, vals2)) + return vals_list + + def generate_move(self): + super().generate_move() + for bank_line in self.bank_line_ids: + dest_company = ( + self.env["res.company"] + .sudo() + .search([("partner_id", "=", bank_line.partner_id.id)], limit=1) + ) + if dest_company: + for payment_line in bank_line.payment_line_ids: + orig_invoice = payment_line.move_line_id.move_id + if orig_invoice.auto_generated: + dest_invoice = orig_invoice.auto_invoice_id + else: + dest_invoice = self.env["account.move"].search( + [ + ("auto_invoice_id", "=", orig_invoice.id), + ("company_id", "=", dest_company.id), + ], + limit=1, + ) + if dest_invoice.payment_state != "paid": + dest_journal = self.env["account.journal"].search( + [ + ("company_id", "=", dest_company.id), + ("type", "=", "bank"), + ( + "bank_account_id", + "=", + payment_line.partner_bank_id.id, + ), + ], + limit=1, + ) + vals_list = self._prepare_move_line_vals( + payment_line, dest_invoice, dest_journal, dest_company + ) + for vals in vals_list: + self.env["account.move.line"].with_context( + check_move_validity=False + ).create(vals) + lines_to_reconcile = dest_invoice.line_ids.filtered( + lambda line: line.account_internal_type + in ["receivable", "payable"] + ) + lines_to_reconcile.reconcile() diff --git a/account_payment_order_inter_company/readme/CONTRIBUTORS.rst b/account_payment_order_inter_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..eb429ce8456 --- /dev/null +++ b/account_payment_order_inter_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Sébastien Beau +* Chafique Delli diff --git a/account_payment_order_inter_company/readme/DESCRIPTION.rst b/account_payment_order_inter_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..baf806eb588 --- /dev/null +++ b/account_payment_order_inter_company/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to map tax and account depending of the product. diff --git a/account_payment_order_inter_company/security/ir.model.access.csv b/account_payment_order_inter_company/security/ir.model.access.csv new file mode 100644 index 00000000000..b6a4e89e483 --- /dev/null +++ b/account_payment_order_inter_company/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_fiscal_position_product_rule,access on account.fiscal.position.product.rule,model_account_fiscal_position_product_rule,account.group_account_user,1,1,1,1 diff --git a/account_payment_order_inter_company/static/description/index.html b/account_payment_order_inter_company/static/description/index.html new file mode 100644 index 00000000000..4de4ffc59bc --- /dev/null +++ b/account_payment_order_inter_company/static/description/index.html @@ -0,0 +1,415 @@ + + + + + + +Account Payment Order Inter Company + + + +
+

Account Payment Order Inter Company

+ + +

Beta License: AGPL-3 OCA/multi-company

+

This module allows for an inter-company billing to automatically pay the invoice in Company A as soon as the invoice in Company B is paid.

+

Table of contents

+ +
+

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

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the OCA/multi-company project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/account_payment_order_inter_company/tests/__init__.py b/account_payment_order_inter_company/tests/__init__.py new file mode 100644 index 00000000000..39f5cf9c995 --- /dev/null +++ b/account_payment_order_inter_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_order_inter_company diff --git a/account_payment_order_inter_company/tests/test_account_payment_order_inter_company.py b/account_payment_order_inter_company/tests/test_account_payment_order_inter_company.py new file mode 100644 index 00000000000..e521aebe01a --- /dev/null +++ b/account_payment_order_inter_company/tests/test_account_payment_order_inter_company.py @@ -0,0 +1,116 @@ +# Copyright 2022 Akretion France (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.account_invoice_inter_company.tests.test_inter_company_invoice import ( + TestAccountInvoiceInterCompanyBase, +) + + +class TestAccountPaymentOrderInterCompany(TestAccountInvoiceInterCompanyBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Payment mode in company B + cls.payment_mode_company_b = cls.env["account.payment.mode"].create( + { + "name": "Test Credit Transfer to Suppliers", + "company_id": cls.company_b.id, + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_out" + ).id, + } + ) + # Payment mode in company A + cls.payment_mode_company_a = cls.env["account.payment.mode"].create( + { + "name": "Test Direct Debit of customers", + "company_id": cls.company_a.id, + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_in" + ).id, + } + ) + + def test_customer_invoice_is_paid_in_company_a(self): + # Confirm the customer invoice in company A + self.invoice_company_a.with_user(self.user_company_a.id).with_context( + test_queue_job_no_delay=True + ).action_post() + # Search supplier invoice created in company B + invoice_company_b = self.account_move_obj.with_user( + self.user_company_b.id + ).search( + [ + ("auto_invoice_id", "=", self.invoice_company_a.id), + ("company_id", "=", self.company_b.id), + ], + limit=1, + ) + # Update supplier invoice in company B + invoice_company_b.write({"payment_mode_id": self.payment_mode_company_b.id}) + # Create payment order in company B + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=invoice_company_b.ids + ).create({}).run() + payment_order_company_b = self.env["account.payment.order"].search( + [ + ("state", "=", "draft"), + ("payment_type", "=", "outbound"), + ("company_id", "=", self.company_b.id), + ], + limit=1, + ) + # Update payment order in company B + payment_order_company_b.write({"journal_id": self.bank_journal_company_b.id}) + # Confirm payment order in company B + payment_order_company_b.draft2open() + payment_order_company_b.open2generated() + payment_order_company_b.generated2uploaded() + # Check payment state of supplier invoice in company B + self.assertEqual(invoice_company_b.payment_state, "paid") + # Check payment state of customer invoice in company A + self.assertEqual(self.invoice_company_a.payment_state, "paid") + + def test_supplier_invoice_is_paid_in_company_b(self): + # Confirm the customer invoice in company A + self.invoice_company_a.with_user(self.user_company_a.id).with_context( + test_queue_job_no_delay=True + ).action_post() + # Search supplier invoice created in company B + invoice_company_b = self.account_move_obj.with_user( + self.user_company_b.id + ).search( + [ + ("auto_invoice_id", "=", self.invoice_company_a.id), + ("company_id", "=", self.company_b.id), + ], + limit=1, + ) + # Update supplier invoice in company A + self.invoice_company_a.write( + {"payment_mode_id": self.payment_mode_company_a.id} + ) + # Create payment order in company A + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice_company_a.ids + ).create({}).run() + payment_order_company_a = self.env["account.payment.order"].search( + [ + ("state", "=", "draft"), + ("payment_type", "=", "inbound"), + ("company_id", "=", self.company_a.id), + ], + limit=1, + ) + # Update payment order in company A + payment_order_company_a.write({"journal_id": self.bank_journal_company_a.id}) + # Confirm payment order in company A + payment_order_company_a.draft2open() + payment_order_company_a.open2generated() + payment_order_company_a.generated2uploaded() + # Check payment state of customer invoice in company A + self.assertEqual(self.invoice_company_a.payment_state, "paid") + # Check payment state of supplier invoice in company B + self.assertEqual(invoice_company_b.payment_state, "paid") diff --git a/setup/account_payment_order_inter_company/odoo/addons/account_payment_order_inter_company b/setup/account_payment_order_inter_company/odoo/addons/account_payment_order_inter_company new file mode 120000 index 00000000000..f8a44e83ecc --- /dev/null +++ b/setup/account_payment_order_inter_company/odoo/addons/account_payment_order_inter_company @@ -0,0 +1 @@ +../../../../account_payment_order_inter_company \ No newline at end of file diff --git a/setup/account_payment_order_inter_company/setup.py b/setup/account_payment_order_inter_company/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_payment_order_inter_company/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)