diff --git a/account_payment_promissory_note/README.rst b/account_payment_promissory_note/README.rst new file mode 100644 index 00000000000..8c21f60a2a0 --- /dev/null +++ b/account_payment_promissory_note/README.rst @@ -0,0 +1,91 @@ +=============================== +Account Payment Promissory Note +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:75ac9ad5c25acba585f2ab2391e886b2aca09fdcfe9e7b77e215a1dd00f0efa3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/18.0/account_payment_promissory_note + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-18-0/account-payment-18-0-account_payment_promissory_note + :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/account-payment&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to set a date due in a payment, as promissory +notes require. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to Invoicing > Customers / Vendors > Payments. +2. Create a new one and select the 'Promissory Note' option. +3. Now you can select a date for the due of the promissory note + (Automatically will be selected the lastest due date of the invoices + if any selected). + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Sergio Teruel + - Alexandre Díaz + - Carlos Roca + - César A. Sánchez + +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/account-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_promissory_note/__init__.py b/account_payment_promissory_note/__init__.py new file mode 100644 index 00000000000..9b4296142f4 --- /dev/null +++ b/account_payment_promissory_note/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/account_payment_promissory_note/__manifest__.py b/account_payment_promissory_note/__manifest__.py new file mode 100644 index 00000000000..ccd6ced2adb --- /dev/null +++ b/account_payment_promissory_note/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2018 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Payment Promissory Note", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "category": "Invoicing Management", + "website": "https://github.com/OCA/account-payment", + "depends": ["account"], + "data": [ + "views/account_payment_view.xml", + "views/account_payment_invoice_view.xml", + ], + "installable": True, +} diff --git a/account_payment_promissory_note/i18n/account_payment_promissory_note.pot b/account_payment_promissory_note/i18n/account_payment_promissory_note.pot new file mode 100644 index 00000000000..dd514147054 --- /dev/null +++ b/account_payment_promissory_note/i18n/account_payment_promissory_note.pot @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_promissory_note +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_payment_promissory_note +#: model_terms:ir.ui.view,arch_db:account_payment_promissory_note.view_account_payment_form_multi +msgid "" +"" + +#. module: account_payment_promissory_note +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_payment__date_due +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_payment_register__date_due +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_promissory_note_mixin__date_due +msgid "Due Date" +msgstr "Scadenza" + +#. module: account_payment_promissory_note +#: model:ir.model,name:account_payment_promissory_note.model_account_payment +msgid "Payments" +msgstr "Pagamenti" + +#. module: account_payment_promissory_note +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_payment__promissory_note +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_payment_register__promissory_note +#: model:ir.model.fields,field_description:account_payment_promissory_note.field_account_promissory_note_mixin__promissory_note +#: model_terms:ir.ui.view,arch_db:account_payment_promissory_note.view_account_payment_search +msgid "Promissory Note" +msgstr "Nota promissorio" + +#. module: account_payment_promissory_note +#: model:ir.model,name:account_payment_promissory_note.model_account_promissory_note_mixin +msgid "Promissory Note Mixin" +msgstr "Mixin nota promissorio" + +#. module: account_payment_promissory_note +#: model:ir.model,name:account_payment_promissory_note.model_account_payment_register +msgid "Register Payment" +msgstr "Registra pagamento" diff --git a/account_payment_promissory_note/models/__init__.py b/account_payment_promissory_note/models/__init__.py new file mode 100644 index 00000000000..469bb6de4c9 --- /dev/null +++ b/account_payment_promissory_note/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_abstract_payment +from . import account_payment diff --git a/account_payment_promissory_note/models/account_abstract_payment.py b/account_payment_promissory_note/models/account_abstract_payment.py new file mode 100644 index 00000000000..60d909d1785 --- /dev/null +++ b/account_payment_promissory_note/models/account_abstract_payment.py @@ -0,0 +1,20 @@ +# Copyright 2018 Sergio Teruel +# Copyright 2018 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountAbstractPayment(models.AbstractModel): + _name = "account.promissory.note.mixin" + _description = "Promissory Note Mixin" + + promissory_note = fields.Boolean() + date_due = fields.Date( + string="Due Date", + ) + + @api.onchange("promissory_note") + def _onchange_promissory_note(self): + if not self.promissory_note: + self.date_due = False diff --git a/account_payment_promissory_note/models/account_payment.py b/account_payment_promissory_note/models/account_payment.py new file mode 100644 index 00000000000..f275207764f --- /dev/null +++ b/account_payment_promissory_note/models/account_payment.py @@ -0,0 +1,32 @@ +# Copyright 2018 Sergio Teruel +# Copyright 2018 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountPayment(models.Model): + _name = "account.payment" + _inherit = ["account.payment", "account.promissory.note.mixin"] + + @api.onchange("promissory_note") + def _onchange_promissory_note(self): + result = super()._onchange_promissory_note() + if not self.date_due and self.promissory_note: + invoices = self.reconciled_invoice_ids + same_partner = len(invoices.mapped("partner_id")) == 1 + if invoices and same_partner: + self.date_due = max(invoices.mapped("invoice_date_due")) + return result + + def write(self, vals): + for payment in self: + lines = payment.move_id.line_ids + if "promissory_note" in vals: + if not vals["promissory_note"]: + lines.date_maturity = vals.get("date", payment.date) + elif "date_due" in vals: + lines.date_maturity = vals["date_due"] + elif payment.promissory_note and "date_due" in vals: + lines.date_maturity = vals["date_due"] + return super().write(vals) diff --git a/account_payment_promissory_note/pyproject.toml b/account_payment_promissory_note/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/account_payment_promissory_note/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_payment_promissory_note/readme/CONTRIBUTORS.md b/account_payment_promissory_note/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..4a224c48700 --- /dev/null +++ b/account_payment_promissory_note/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Alexandre Díaz + - Carlos Roca + - César A. Sánchez diff --git a/account_payment_promissory_note/readme/DESCRIPTION.md b/account_payment_promissory_note/readme/DESCRIPTION.md new file mode 100644 index 00000000000..b05403bdfca --- /dev/null +++ b/account_payment_promissory_note/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows you to set a date due in a payment, as promissory +notes require. diff --git a/account_payment_promissory_note/readme/USAGE.md b/account_payment_promissory_note/readme/USAGE.md new file mode 100644 index 00000000000..799722a7c68 --- /dev/null +++ b/account_payment_promissory_note/readme/USAGE.md @@ -0,0 +1,5 @@ +1. Go to Invoicing \> Customers / Vendors \> Payments. +2. Create a new one and select the 'Promissory Note' option. +3. Now you can select a date for the due of the promissory note + (Automatically will be selected the lastest due date of the invoices + if any selected). diff --git a/account_payment_promissory_note/static/description/icon.png b/account_payment_promissory_note/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_payment_promissory_note/static/description/icon.png differ diff --git a/account_payment_promissory_note/static/description/index.html b/account_payment_promissory_note/static/description/index.html new file mode 100644 index 00000000000..94db6694298 --- /dev/null +++ b/account_payment_promissory_note/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Account Payment Promissory Note + + + +
+

Account Payment Promissory Note

+ + +

Beta License: AGPL-3 OCA/account-payment Translate me on Weblate Try me on Runboat

+

This module allows you to set a date due in a payment, as promissory +notes require.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Invoicing > Customers / Vendors > Payments.
  2. +
  3. Create a new one and select the ‘Promissory Note’ option.
  4. +
  5. Now you can select a date for the due of the promissory note +(Automatically will be selected the lastest due date of the invoices +if any selected).
  6. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Sergio Teruel
    • +
    • Alexandre Díaz
    • +
    • Carlos Roca
    • +
    • César A. Sánchez
    • +
    +
  • +
+
+
+

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/account-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_promissory_note/tests/__init__.py b/account_payment_promissory_note/tests/__init__.py new file mode 100644 index 00000000000..227c4a785bb --- /dev/null +++ b/account_payment_promissory_note/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_promissory_note diff --git a/account_payment_promissory_note/tests/test_account_payment_promissory_note.py b/account_payment_promissory_note/tests/test_account_payment_promissory_note.py new file mode 100644 index 00000000000..95d3164ddef --- /dev/null +++ b/account_payment_promissory_note/tests/test_account_payment_promissory_note.py @@ -0,0 +1,98 @@ +# Copyright 2020 Tecnativa - Carlos Roca. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import datetime + +from odoo.tests import Form, tagged +from odoo.tests.common import TransactionCase + + +@tagged("-at_install", "post_install") +class TestAccountPaymentPromissoryNote(TransactionCase): + def setUp(self): + super().setUp() + self.company = self.env.user.company_id + self.default_journal_cash = self.env["account.journal"].search( + [("company_id", "=", self.company.id), ("type", "=", "cash")], limit=1 + ) + self.inbound_payment_method_line = ( + self.default_journal_cash.inbound_payment_method_line_ids[0] + ) + self.company = self.env.ref("base.main_company") + partner = self.env.ref("base.partner_demo") + self.invoice_1 = self.env["account.move"].create( + { + "company_id": self.company.id, + "partner_id": partner.id, + "invoice_date": "2020-09-14", + "invoice_date_due": "2020-09-23", + "move_type": "out_invoice", + "invoice_line_ids": [(0, 0, {"name": "Test", "price_unit": 20})], + } + ) + self.invoice_1.action_post() + self.invoice_2 = self.env["account.move"].create( + { + "company_id": self.company.id, + "partner_id": partner.id, + "invoice_date": "2020-09-14", + "invoice_date_due": "2020-09-22", + "move_type": "out_invoice", + "invoice_line_ids": [(0, 0, {"name": "Test", "price_unit": 20})], + } + ) + self.invoice_2.action_post() + + def test_1_onchange_promissory_note_without_invoices(self): + payment = self.env["account.payment"].create( + { + "payment_type": "inbound", + "payment_method_line_id": self.inbound_payment_method_line.id, + "amount": 50.00, + "journal_id": self.default_journal_cash.id, + } + ) + payment.date_due = "2020-09-21" + payment._onchange_promissory_note() + self.assertFalse(payment.date_due) + payment.promissory_note = True + payment.date_due = "2020-09-21" + payment._onchange_promissory_note() + self.assertEqual( + payment.date_due, + datetime.datetime.strptime("2020-09-21", "%Y-%m-%d").date(), + ) + + def test_2_onchange_promissory_note_with_invoices(self): + wiz_form = Form( + self.env["account.payment.register"].with_context( + active_model="account.move", + active_ids=[self.invoice_1.id, self.invoice_2.id], + ) + ) + wiz_form.group_payment = True + wiz = wiz_form.save() + payment = wiz._create_payments() + payment.date_due = "2020-09-21" + payment._onchange_promissory_note() + self.assertFalse(payment.date_due) + payment.promissory_note = True + payment._onchange_promissory_note() + self.assertEqual( + payment.date_due, + datetime.datetime.strptime("2020-09-23", "%Y-%m-%d").date(), + ) + + def test_3_due_date_propagation(self): + wiz_form = Form( + self.env["account.payment.register"].with_context( + active_model="account.move", + active_ids=[self.invoice_1.id, self.invoice_2.id], + ) + ) + wiz_form.promissory_note = True + wiz_form.group_payment = True + wiz_form.date_due = datetime.datetime.strptime("2020-09-23", "%Y-%m-%d").date() + wiz = wiz_form.save() + payment = wiz._create_payments() + for line in payment.move_id.line_ids: + self.assertEqual(line.date_maturity, payment.date_due) diff --git a/account_payment_promissory_note/views/account_payment_invoice_view.xml b/account_payment_promissory_note/views/account_payment_invoice_view.xml new file mode 100644 index 00000000000..39aca4706bb --- /dev/null +++ b/account_payment_promissory_note/views/account_payment_invoice_view.xml @@ -0,0 +1,16 @@ + + + + account.payment.register + + + + + + + Set date due to all payments or empty to select last date due of each partner invoices group + + + + + diff --git a/account_payment_promissory_note/views/account_payment_view.xml b/account_payment_promissory_note/views/account_payment_view.xml new file mode 100644 index 00000000000..375b299b7d2 --- /dev/null +++ b/account_payment_promissory_note/views/account_payment_view.xml @@ -0,0 +1,30 @@ + + + + account.payment + + + + + + + + + + account.payment + + + + + + + + diff --git a/account_payment_promissory_note/wizard/__init__.py b/account_payment_promissory_note/wizard/__init__.py new file mode 100644 index 00000000000..76cc7bd6abc --- /dev/null +++ b/account_payment_promissory_note/wizard/__init__.py @@ -0,0 +1 @@ +from . import account_register_payments diff --git a/account_payment_promissory_note/wizard/account_register_payments.py b/account_payment_promissory_note/wizard/account_register_payments.py new file mode 100644 index 00000000000..4b9db8698ec --- /dev/null +++ b/account_payment_promissory_note/wizard/account_register_payments.py @@ -0,0 +1,35 @@ +# Copyright 2018 Sergio Teruel +# Copyright 2018 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountRegisterPayments(models.TransientModel): + _name = "account.payment.register" + _inherit = ["account.payment.register", "account.promissory.note.mixin"] + + def _create_payments(self): + payments = super()._create_payments() + for payment in payments: + if not self.date_due: + invoices = payment.reconciled_invoice_ids + if invoices: + max_date = max(invoices.mapped("invoice_date_due")) + payment.promissory_note = self.promissory_note + payment.date_due = max_date + else: + payment.promissory_note = self.promissory_note + payment.date_due = self.date_due + return payments + + @api.onchange("promissory_note") + def _onchange_promissory_note(self): + result = super()._onchange_promissory_note() + if not self.date_due and self.promissory_note: + active_ids = self.env.context.get("active_ids") + invoice_lines = self.env["account.move.line"].browse(active_ids) + same_partner = len(invoice_lines.move_id.partner_id) == 1 + if invoice_lines and self.group_payment and same_partner: + self.date_due = max(invoice_lines.move_id.mapped("invoice_date_due")) + return result