From 24141dfc8bc564ca808d55703fe911bf6a8138ff Mon Sep 17 00:00:00 2001 From: AmmarOfficewalaSerpentCS Date: Tue, 6 Jul 2021 14:38:47 +0530 Subject: [PATCH] [14.0][ADD] Added a account_payment_order_partner module. --- account_payment_order_partner/README.rst | 93 ++++ account_payment_order_partner/__init__.py | 5 + account_payment_order_partner/__manifest__.py | 18 + .../models/__init__.py | 5 + .../models/account_move.py | 29 ++ .../models/payment_order.py | 11 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/CREDITS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../readme/INSTALL.rst | 5 + .../readme/USAGE.rst | 1 + .../static/description/index.html | 440 ++++++++++++++++++ .../tests/__init__.py | 4 + .../tests/test_payment_order.py | 99 ++++ .../views/payment_order_view.xml | 21 + .../wizards/__init__.py | 4 + .../account_invoice_payment_line_multi.py | 56 +++ ...ccount_invoice_payment_line_multi_view.xml | 33 ++ .../odoo/addons/account_payment_order_partner | 1 + setup/account_payment_order_partner/setup.py | 6 + 20 files changed, 834 insertions(+) create mode 100644 account_payment_order_partner/README.rst create mode 100644 account_payment_order_partner/__init__.py create mode 100644 account_payment_order_partner/__manifest__.py create mode 100644 account_payment_order_partner/models/__init__.py create mode 100644 account_payment_order_partner/models/account_move.py create mode 100644 account_payment_order_partner/models/payment_order.py create mode 100644 account_payment_order_partner/readme/CONTRIBUTORS.rst create mode 100644 account_payment_order_partner/readme/CREDITS.rst create mode 100644 account_payment_order_partner/readme/DESCRIPTION.rst create mode 100644 account_payment_order_partner/readme/INSTALL.rst create mode 100644 account_payment_order_partner/readme/USAGE.rst create mode 100644 account_payment_order_partner/static/description/index.html create mode 100644 account_payment_order_partner/tests/__init__.py create mode 100644 account_payment_order_partner/tests/test_payment_order.py create mode 100644 account_payment_order_partner/views/payment_order_view.xml create mode 100644 account_payment_order_partner/wizards/__init__.py create mode 100644 account_payment_order_partner/wizards/account_invoice_payment_line_multi.py create mode 100644 account_payment_order_partner/wizards/account_invoice_payment_line_multi_view.xml create mode 120000 setup/account_payment_order_partner/odoo/addons/account_payment_order_partner create mode 100644 setup/account_payment_order_partner/setup.py diff --git a/account_payment_order_partner/README.rst b/account_payment_order_partner/README.rst new file mode 100644 index 000000000000..d1f1a1e034d7 --- /dev/null +++ b/account_payment_order_partner/README.rst @@ -0,0 +1,93 @@ +============================= +Account Payment Order Partner +============================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_partner + :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_partner + :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 adds support for payment orders and debit orders. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on: + +* account_payment_order + +This modules is part of the OCA/bank-payment suite. + +Usage +===== + +You can create a New Payment order if they already another payment already extis. + + +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 +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* Ammar Officewala + +Other credits +~~~~~~~~~~~~~ + +* Open Source Integrators + +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_partner/__init__.py b/account_payment_order_partner/__init__.py new file mode 100644 index 000000000000..887d8d15bea6 --- /dev/null +++ b/account_payment_order_partner/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models +from . import wizards diff --git a/account_payment_order_partner/__manifest__.py b/account_payment_order_partner/__manifest__.py new file mode 100644 index 000000000000..d650bd5e04fe --- /dev/null +++ b/account_payment_order_partner/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Payment Order Partner", + "summary": "Adds partner to payment orders and groups payment orders by partner.", + "version": "14.0.1.0.0", + "category": "Accounting Management", + "website": "https://github.com/OCA/bank-payment", + "author": "Open Source Integrators," "Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["account_payment_order"], + "data": [ + "views/payment_order_view.xml", + "wizards/account_invoice_payment_line_multi_view.xml", + ], + "installable": True, +} diff --git a/account_payment_order_partner/models/__init__.py b/account_payment_order_partner/models/__init__.py new file mode 100644 index 000000000000..33b1387472fa --- /dev/null +++ b/account_payment_order_partner/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import payment_order +from . import account_move diff --git a/account_payment_order_partner/models/account_move.py b/account_payment_order_partner/models/account_move.py new file mode 100644 index 000000000000..314370e26fb6 --- /dev/null +++ b/account_payment_order_partner/models/account_move.py @@ -0,0 +1,29 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _prepare_new_payment_order(self, payment_mode=None): + res = super()._prepare_new_payment_order() + if self._context.get("is_pyo_as_per_customer"): + res.update({"partner_id": self.partner_id.id}) + if self._context.get("is_new_order"): + res.update({"state": "new"}) + return res + + def get_account_payment_domain(self, payment_mode): + domain = [("payment_mode_id", "=", payment_mode.id)] + if self._context.get("is_new_order"): + domain.append(("state", "=", "new")) + else: + domain.append(("state", "=", "draft")) + if self._context.get("is_pyo_as_per_customer"): + domain.append(("partner_id", "=", self.partner_id.id)) + return domain + + def create_account_payment_line_new(self): + return self.create_account_payment_line() diff --git a/account_payment_order_partner/models/payment_order.py b/account_payment_order_partner/models/payment_order.py new file mode 100644 index 000000000000..191c15173a67 --- /dev/null +++ b/account_payment_order_partner/models/payment_order.py @@ -0,0 +1,11 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountPaymentOrder(models.Model): + _inherit = "account.payment.order" + + partner_id = fields.Many2one("res.partner", string="Partner") + state = fields.Selection(selection_add=[("new", "New")]) diff --git a/account_payment_order_partner/readme/CONTRIBUTORS.rst b/account_payment_order_partner/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..066cb0d8e7cc --- /dev/null +++ b/account_payment_order_partner/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Ammar Officewala diff --git a/account_payment_order_partner/readme/CREDITS.rst b/account_payment_order_partner/readme/CREDITS.rst new file mode 100644 index 000000000000..dab2345c97ef --- /dev/null +++ b/account_payment_order_partner/readme/CREDITS.rst @@ -0,0 +1 @@ +* Open Source Integrators diff --git a/account_payment_order_partner/readme/DESCRIPTION.rst b/account_payment_order_partner/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..11a1fe4cd750 --- /dev/null +++ b/account_payment_order_partner/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds support for payment orders and debit orders. diff --git a/account_payment_order_partner/readme/INSTALL.rst b/account_payment_order_partner/readme/INSTALL.rst new file mode 100644 index 000000000000..212936294f38 --- /dev/null +++ b/account_payment_order_partner/readme/INSTALL.rst @@ -0,0 +1,5 @@ +This module depends on: + +* account_payment_order + +This modules is part of the OCA/bank-payment suite. diff --git a/account_payment_order_partner/readme/USAGE.rst b/account_payment_order_partner/readme/USAGE.rst new file mode 100644 index 000000000000..4674d804fad1 --- /dev/null +++ b/account_payment_order_partner/readme/USAGE.rst @@ -0,0 +1 @@ +You can create a New Payment order if they already another payment already extis. diff --git a/account_payment_order_partner/static/description/index.html b/account_payment_order_partner/static/description/index.html new file mode 100644 index 000000000000..1bcdadd0fce2 --- /dev/null +++ b/account_payment_order_partner/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Account Payment Order Partner + + + +
+

Account Payment Order Partner

+ + +

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

+

This module adds support for payment orders and debit orders.

+

Table of contents

+ +
+

Installation

+

This module depends on:

+
    +
  • account_payment_order
  • +
+

This modules is part of the OCA/bank-payment suite.

+
+
+

Usage

+

You can create a New Payment order if they already another payment already extis.

+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+ +
+

Other credits

+ +
+
+

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_partner/tests/__init__.py b/account_payment_order_partner/tests/__init__.py new file mode 100644 index 000000000000..9d65f01d4d47 --- /dev/null +++ b/account_payment_order_partner/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_payment_order diff --git a/account_payment_order_partner/tests/test_payment_order.py b/account_payment_order_partner/tests/test_payment_order.py new file mode 100644 index 000000000000..2239c7181ef4 --- /dev/null +++ b/account_payment_order_partner/tests/test_payment_order.py @@ -0,0 +1,99 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import Form, SavepointCase + + +class TestPaymentOrderInboundBase(SavepointCase): + @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( + { + "name": "Test account", + "code": "TEST1", + "user_type_id": self.env.ref("account.data_account_type_revenue").id, + } + ) + self.journal = self.env["account.journal"].search( + [("type", "=", "bank"), ("company_id", "=", self.env.user.company_id.id)], + limit=1, + ) + self.inbound_mode.variable_journal_ids = self.journal + # Make sure no others orders are present + self.domain = [ + ("state", "=", "draft"), + ("payment_type", "=", "inbound"), + ("company_id", "=", self.env.user.company_id.id), + ] + self.payment_order_obj = self.env["account.payment.order"] + self.payment_order_obj.search(self.domain).unlink() + # Create payment order + self.inbound_order = ( + self.env["account.payment.order"] + .with_context(is_pyo_as_per_customer=True) + .create( + { + "payment_type": "inbound", + "payment_mode_id": self.inbound_mode.id, + "journal_id": self.journal.id, + "state": "draft", + } + ) + ) + # Open invoice + self.invoice = self._create_customer_invoice(self) + self.invoice.action_post() + + def test_multi_link(self): + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).run() + + def test_multi_new_link(self): + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).run() + + def test_new_link(self): + self.invoice = self._create_customer_invoice() + self.invoice.action_post() + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).create_new_orders() + + def test_new_link_without_paymentorder(self): + self.invoice = self._create_customer_invoice() + self.invoice.action_post() + domain = [ + ("state", "=", "draft"), + ("payment_type", "=", "inbound"), + ("company_id", "=", self.env.user.company_id.id), + ] + self.payment_order_obj.search(domain).unlink() + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).create_new_orders() + + 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") + 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" + invoice_line_form.quantity = 1 + invoice_line_form.price_unit = 100.0 + invoice_line_form.account_id = self.invoice_line_account + invoice_line_form.tax_ids.clear() + invoice = invoice_form.save() + invoice_form = Form(invoice) + invoice_form.payment_mode_id = self.inbound_mode + return invoice_form.save() diff --git a/account_payment_order_partner/views/payment_order_view.xml b/account_payment_order_partner/views/payment_order_view.xml new file mode 100644 index 000000000000..d6ddf907ee44 --- /dev/null +++ b/account_payment_order_partner/views/payment_order_view.xml @@ -0,0 +1,21 @@ + + + + + account.payment.order.form.inherit + account.payment.order + + + + + + + + + + diff --git a/account_payment_order_partner/wizards/__init__.py b/account_payment_order_partner/wizards/__init__.py new file mode 100644 index 000000000000..e43adfca63c7 --- /dev/null +++ b/account_payment_order_partner/wizards/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_invoice_payment_line_multi diff --git a/account_payment_order_partner/wizards/account_invoice_payment_line_multi.py b/account_payment_order_partner/wizards/account_invoice_payment_line_multi.py new file mode 100644 index 000000000000..d664cb4e2f70 --- /dev/null +++ b/account_payment_order_partner/wizards/account_invoice_payment_line_multi.py @@ -0,0 +1,56 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountInvoicePaymentLineMulti(models.TransientModel): + _inherit = "account.invoice.payment.line.multi" + + draft_orders = fields.Boolean(string="is Draft Payments available") + info_message = fields.Html(string="INFO") + is_pyo_as_per_customer = fields.Boolean(string="As Per customer", default=True) + + @api.model + def default_get(self, field_list): + res = super(AccountInvoicePaymentLineMulti, self).default_get(field_list) + account_payment_order_obj = self.env["account.payment.order"] + account_payment_order = account_payment_order_obj.search( + [("state", "=", "draft")] + ) + if not account_payment_order: + res.update({"draft_orders": True}) + invoices = self.env["account.move"].browse(self._context["active_ids"]) + for invoice in invoices: + no_draft_account_payment_order = account_payment_order_obj.search( + [("partner_id", "=", invoice.partner_id.id), ("state", "=", "draft")] + ) + if not no_draft_account_payment_order: + res.update( + { + "info_message": """

This Partner has + no draft Invoice

""" + } + ) + return res + + def create_new_orders(self): + self.ensure_one() + assert ( + self._context["active_model"] == "account.move" + ), "Active model should be account.move" + invoices = self.env["account.move"].browse(self._context["active_ids"]) + action = invoices.with_context( + is_pyo_as_per_customer=self.is_pyo_as_per_customer + ).create_account_payment_line_new() + self.env[action.get("res_model")].search([("state", "=", "new")]).write( + {"state": "draft"} + ) + return action + + def run(self): + self.ensure_one() + return super( + AccountInvoicePaymentLineMulti, + self.with_context(is_pyo_as_per_customer=self.is_pyo_as_per_customer), + ).run() diff --git a/account_payment_order_partner/wizards/account_invoice_payment_line_multi_view.xml b/account_payment_order_partner/wizards/account_invoice_payment_line_multi_view.xml new file mode 100644 index 000000000000..87fc01e145a7 --- /dev/null +++ b/account_payment_order_partner/wizards/account_invoice_payment_line_multi_view.xml @@ -0,0 +1,33 @@ + + + + account_invoice_payment_line_multi.form.inherit + account.invoice.payment.line.multi + + + + + + + + Link to Draft Order(s) + {'invisible': [('draft_orders', '=', True)]} + + +