diff --git a/odex30_base/sale_amount_payment_link/README.rst b/odex30_base/sale_amount_payment_link/README.rst new file mode 100644 index 0000000..6c7f6b2 --- /dev/null +++ b/odex30_base/sale_amount_payment_link/README.rst @@ -0,0 +1,83 @@ +======================== +Sale Amount Payment Link +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8f4e4e56256b840b6f3a94d8ac03f0b77e456772bb6a863b54a7f02c5854d390 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/14.0/sale_amount_payment_link + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_amount_payment_link + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Reduce Amount to be paid while Payment Link is generated on Sale Order, depending on done Transactions. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Add Product to Order Lines after first Transaction is made and Generate a Payment Link + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp `__: + + * Maksym Yankin + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/odex30_base/sale_amount_payment_link/__init__.py b/odex30_base/sale_amount_payment_link/__init__.py new file mode 100644 index 0000000..70b9c4e --- /dev/null +++ b/odex30_base/sale_amount_payment_link/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizards diff --git a/odex30_base/sale_amount_payment_link/__manifest__.py b/odex30_base/sale_amount_payment_link/__manifest__.py new file mode 100644 index 0000000..b0d3062 --- /dev/null +++ b/odex30_base/sale_amount_payment_link/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Amount Payment Link", + "summary": "Reduce Amount to be paid " + "while Payment Link is generated " + "on Sale Order, depending on done Transactions.", + "version": "18.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Sale", + "depends": ["sale", "account"], + "website": "https://github.com/OCA/sale-workflow", + "installable": True, +} diff --git a/odex30_base/sale_amount_payment_link/i18n/es.po b/odex30_base/sale_amount_payment_link/i18n/es.po new file mode 100644 index 0000000..cee45fe --- /dev/null +++ b/odex30_base/sale_amount_payment_link/i18n/es.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_amount_payment_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-28 14:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: sale_amount_payment_link +#: model:ir.model.fields,field_description:sale_amount_payment_link.field_payment_link_wizard__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: sale_amount_payment_link +#: model:ir.model,name:sale_amount_payment_link.model_payment_link_wizard +msgid "Generate Sales Payment Link" +msgstr "Generar Enlace de Pago de Ventas" + +#. module: sale_amount_payment_link +#: model:ir.model.fields,field_description:sale_amount_payment_link.field_payment_link_wizard__id +msgid "ID" +msgstr "ID" + +#. module: sale_amount_payment_link +#: model:ir.model.fields,field_description:sale_amount_payment_link.field_payment_link_wizard____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" diff --git a/odex30_base/sale_amount_payment_link/readme/CONTRIBUTORS.rst b/odex30_base/sale_amount_payment_link/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..cd1be5e --- /dev/null +++ b/odex30_base/sale_amount_payment_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Camptocamp `__: + + * Maksym Yankin diff --git a/odex30_base/sale_amount_payment_link/readme/DESCRIPTION.rst b/odex30_base/sale_amount_payment_link/readme/DESCRIPTION.rst new file mode 100644 index 0000000..1ce3c7f --- /dev/null +++ b/odex30_base/sale_amount_payment_link/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Reduce Amount to be paid while Payment Link is generated on Sale Order, depending on done Transactions. diff --git a/odex30_base/sale_amount_payment_link/readme/USAGE.rst b/odex30_base/sale_amount_payment_link/readme/USAGE.rst new file mode 100644 index 0000000..7e6e18c --- /dev/null +++ b/odex30_base/sale_amount_payment_link/readme/USAGE.rst @@ -0,0 +1 @@ +Add Product to Order Lines after first Transaction is made and Generate a Payment Link diff --git a/odex30_base/sale_amount_payment_link/static/description/icon.png b/odex30_base/sale_amount_payment_link/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/odex30_base/sale_amount_payment_link/static/description/icon.png differ diff --git a/odex30_base/sale_amount_payment_link/static/description/index.html b/odex30_base/sale_amount_payment_link/static/description/index.html new file mode 100644 index 0000000..c7259cc --- /dev/null +++ b/odex30_base/sale_amount_payment_link/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Sale Amount Payment Link + + + + + + diff --git a/odex30_base/sale_amount_payment_link/tests/__init__.py b/odex30_base/sale_amount_payment_link/tests/__init__.py new file mode 100644 index 0000000..293018f --- /dev/null +++ b/odex30_base/sale_amount_payment_link/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_sale_amount_payment_link diff --git a/odex30_base/sale_amount_payment_link/tests/test_sale_amount_payment_link.py b/odex30_base/sale_amount_payment_link/tests/test_sale_amount_payment_link.py new file mode 100644 index 0000000..a1ff11b --- /dev/null +++ b/odex30_base/sale_amount_payment_link/tests/test_sale_amount_payment_link.py @@ -0,0 +1,70 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import tagged +from odoo.tests.common import Form + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install") +class TestSaleAmountPaymentLink(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + + cls.company_data["company"].country_id = cls.env.ref("base.us") + + cls.order = cls.env["sale.order"].create( + { + "partner_id": cls.partner_a.id, + "order_line": [ + ( + 0, + False, + { + "product_id": cls.product_a.id, + "name": "1 Product", + "price_unit": 100.0, + }, + ) + ], + } + ) + cls.env.ref("payment.payment_acquirer_transfer").journal_id = cls.company_data[ + "default_journal_cash" + ] + + cls.transaction = cls.order._create_payment_transaction( + {"acquirer_id": cls.env.ref("payment.payment_acquirer_transfer").id} + ) + + def test_sale_reduce_amount(self): + """Test the following scenario: + - Create a sale order + - Create a transaction for the sale order. + - Confirm the transaction. + - Add more products to Order Lines. + => The Amount on Generate Payment Link wizard must be reduced accordingly. + """ + self.transaction._set_transaction_done() + self.transaction._post_process_after_done() + self.order.write( + { + "order_line": [ + ( + 0, + False, + { + "product_id": self.product_a.id, + "name": "1 Product", + "price_unit": 100.0, + }, + ) + ] + } + ) + ctx = {"active_model": "sale.order", "active_id": self.order.id} + f = Form(self.env["payment.link.wizard"].with_context(ctx)) + # this should be amount reduced with amount already paid by transaction + self.assertEqual(f.amount, 115) diff --git a/odex30_base/sale_amount_payment_link/wizards/__init__.py b/odex30_base/sale_amount_payment_link/wizards/__init__.py new file mode 100644 index 0000000..f330877 --- /dev/null +++ b/odex30_base/sale_amount_payment_link/wizards/__init__.py @@ -0,0 +1 @@ +from . import sale_amount_payment_link diff --git a/odex30_base/sale_amount_payment_link/wizards/sale_amount_payment_link.py b/odex30_base/sale_amount_payment_link/wizards/sale_amount_payment_link.py new file mode 100644 index 0000000..bcd38dd --- /dev/null +++ b/odex30_base/sale_amount_payment_link/wizards/sale_amount_payment_link.py @@ -0,0 +1,28 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, models + + +class SalePaymentLink(models.TransientModel): + _inherit = "payment.link.wizard" + + @api.model + def default_get(self, fields): + res = super().default_get(fields) + if res["res_id"] and res["res_model"] == "sale.order": + record = self.env[res["res_model"]].browse(res["res_id"]) + transactions = record.transaction_ids.filtered(lambda x: x.state == "done") + if transactions and not record.invoice_ids: + payments = [transac.payment_id.id for transac in transactions] + invoice_ids = self.env["account.move"].search( + [("payment_id", "in", payments)] + ) + paid_amount = sum( + invoice_ids.filtered(lambda x: x.state != "cancel").mapped( + "amount_total" + ) + ) + res.update({"amount": record.amount_total - paid_amount}) + return res