From 9c8f05cb0641a13750b6f43d5850e495a7284adb Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 19 Mar 2025 16:03:28 +0100 Subject: [PATCH] [IMP] Remove the to pay mark on an invoice when it is fully paid on in payment This way the module is usefull when the register payment wizard is not used. It is a case when you use payment orders or even if you reconcile your invoices from the bank statement for instance Also add a button on form view to be able to mark the invoice as to pay when you are checking what it is exactly --- account_invoice_select_for_payment/README.rst | 9 ++++- .../models/account_move.py | 16 +++++++- .../readme/CONTRIBUTORS.md | 1 + .../readme/DESCRIPTION.md | 2 + .../readme/USAGE.md | 2 + .../static/description/index.html | 9 ++++- ...test_account_invoice_select_for_payment.py | 29 +++++++++++++- .../views/account_move.xml | 39 ++++++++++++++++++- 8 files changed, 99 insertions(+), 8 deletions(-) diff --git a/account_invoice_select_for_payment/README.rst b/account_invoice_select_for_payment/README.rst index 3f06e66589c..7e6e44235bd 100644 --- a/account_invoice_select_for_payment/README.rst +++ b/account_invoice_select_for_payment/README.rst @@ -31,7 +31,9 @@ Account Invoice Select for Payment This module allows to mark invoices as "selected for payment". This can be done in the list view of invoices using a button in the first column of the view which shows the selection status. This selection persists -until a payment is registered. +until a payment is registered. It's also possible to choose if the +invoice is to pay or not directly in the form viex of the invoice. When +it's to pay, a ribbon appears. .. IMPORTANT:: This is an alpha version, the data model and design can change at any time without warning. @@ -48,7 +50,9 @@ Usage To mark an invoice as "selected for payment", click on the button before the Number column. This will change the state and change the way the -button is displayed to a checked box. +button is displayed to a checked box. It's also possible to choose if +the invoice is to pay or not directly in the form viex of the invoice. +When it's to pay, a ribbon appears. When done, use the search filter "Selected for payment", and select all the lines to give access to the Actions menu, in which you can select @@ -81,6 +85,7 @@ Contributors - Alexandre Fayolle - Hiep Nguyen Hoang - Khoi (Kien Kim) +- Florian da Costa Other credits ------------- diff --git a/account_invoice_select_for_payment/models/account_move.py b/account_invoice_select_for_payment/models/account_move.py index 1ed4725e85e..6900ac0856c 100644 --- a/account_invoice_select_for_payment/models/account_move.py +++ b/account_invoice_select_for_payment/models/account_move.py @@ -1,13 +1,19 @@ # Copyright 2020 Camptocamp # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import api, fields, models class AccountMove(models.Model): _inherit = "account.move" - selected_for_payment = fields.Boolean("To Pay") + selected_for_payment = fields.Boolean( + string="To Pay", + compute="_compute_selected_for_payment", + readonly=False, + store=True, + tracking=True, + ) def action_toggle_select_for_payment(self): selected = self.filtered(lambda rec: rec.selected_for_payment) @@ -17,6 +23,12 @@ def action_toggle_select_for_payment(self): if unselected: unselected.write({"selected_for_payment": True}) + @api.depends("payment_state") + def _compute_selected_for_payment(self): + for rec in self: + if rec.payment_state in ("in_payment", "paid", "reversed"): + rec.selected_for_payment = False + def action_register_payment(self): invoices = self.filtered(lambda inv: inv.selected_for_payment) if invoices: diff --git a/account_invoice_select_for_payment/readme/CONTRIBUTORS.md b/account_invoice_select_for_payment/readme/CONTRIBUTORS.md index a504f0d1bc4..1e12757155e 100644 --- a/account_invoice_select_for_payment/readme/CONTRIBUTORS.md +++ b/account_invoice_select_for_payment/readme/CONTRIBUTORS.md @@ -1,3 +1,4 @@ - Alexandre Fayolle \<\> - Hiep Nguyen Hoang \<\> - Khoi (Kien Kim) \<\> +- Florian da Costa \<\> diff --git a/account_invoice_select_for_payment/readme/DESCRIPTION.md b/account_invoice_select_for_payment/readme/DESCRIPTION.md index 3695344999a..63680b10fa2 100644 --- a/account_invoice_select_for_payment/readme/DESCRIPTION.md +++ b/account_invoice_select_for_payment/readme/DESCRIPTION.md @@ -2,3 +2,5 @@ This module allows to mark invoices as "selected for payment". This can be done in the list view of invoices using a button in the first column of the view which shows the selection status. This selection persists until a payment is registered. +It's also possible to choose if the invoice is to pay or not directly in the form viex of the invoice. +When it's to pay, a ribbon appears. diff --git a/account_invoice_select_for_payment/readme/USAGE.md b/account_invoice_select_for_payment/readme/USAGE.md index 34708c44cbe..98abba1d691 100644 --- a/account_invoice_select_for_payment/readme/USAGE.md +++ b/account_invoice_select_for_payment/readme/USAGE.md @@ -1,6 +1,8 @@ To mark an invoice as "selected for payment", click on the button before the Number column. This will change the state and change the way the button is displayed to a checked box. +It's also possible to choose if the invoice is to pay or not directly in the form viex of the invoice. +When it's to pay, a ribbon appears. When done, use the search filter "Selected for payment", and select all the lines to give access to the Actions menu, in which you can select diff --git a/account_invoice_select_for_payment/static/description/index.html b/account_invoice_select_for_payment/static/description/index.html index 4dc17d72815..1fca19d9140 100644 --- a/account_invoice_select_for_payment/static/description/index.html +++ b/account_invoice_select_for_payment/static/description/index.html @@ -373,7 +373,9 @@

Account Invoice Select for Payment

This module allows to mark invoices as “selected for payment”. This can be done in the list view of invoices using a button in the first column of the view which shows the selection status. This selection persists -until a payment is registered.

+until a payment is registered. It’s also possible to choose if the +invoice is to pay or not directly in the form viex of the invoice. When +it’s to pay, a ribbon appears.

Important

This is an alpha version, the data model and design can change at any time without warning. @@ -398,7 +400,9 @@

Account Invoice Select for Payment

Usage

To mark an invoice as “selected for payment”, click on the button before the Number column. This will change the state and change the way the -button is displayed to a checked box.

+button is displayed to a checked box. It’s also possible to choose if +the invoice is to pay or not directly in the form viex of the invoice. +When it’s to pay, a ribbon appears.

When done, use the search filter “Selected for payment”, and select all the lines to give access to the Actions menu, in which you can select “Register payment” to display the Payment wizard.

@@ -427,6 +431,7 @@

Contributors

  • Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
  • Hiep Nguyen Hoang <hiepnh@trobz.com>
  • Khoi (Kien Kim) <khoikk@trobz.com>
  • +
  • Florian da Costa <florian.dacosta@akretion.com>
  • diff --git a/account_invoice_select_for_payment/tests/test_account_invoice_select_for_payment.py b/account_invoice_select_for_payment/tests/test_account_invoice_select_for_payment.py index 0fd02b0d61e..0a43f4d771c 100644 --- a/account_invoice_select_for_payment/tests/test_account_invoice_select_for_payment.py +++ b/account_invoice_select_for_payment/tests/test_account_invoice_select_for_payment.py @@ -1,3 +1,4 @@ +from odoo import fields from odoo.tests import TransactionCase @@ -26,7 +27,8 @@ def setUpClass(cls): def _create_invoice(cls, partner_id, selected_for_payment): invoice = cls.env["account.move"].create( { - "move_type": "out_invoice", + "invoice_date": fields.Date.today(), + "move_type": "in_invoice", "partner_id": partner_id, "selected_for_payment": selected_for_payment, } @@ -89,3 +91,28 @@ def test_register_payment_with_no_active_ids(self): self.env.invalidate_all() self.assertFalse(self.invoice_1.selected_for_payment) self.assertTrue(self.invoice_2.selected_for_payment) + + def test_to_pay_removal_when_paid(self): + """Test that selected_for_payment is removed when invoice is fully paid""" + # create and reconcile a payment without using the register payment wizard + journal = self.env["account.journal"].search( + [("type", "=", "bank"), ("company_id", "=", self.invoice_2.company_id.id)], + limit=1, + ) + payment = self.env["account.payment"].create( + { + "journal_id": journal.id, + "amount": self.invoice_2.amount_total, + "payment_type": "outbound", + "partner_type": "supplier", + "partner_id": self.invoice_2.partner_id.id, + } + ) + payment.action_post() + _liquidity_line, payable_line, _write_off_line = payment._seek_for_lines() + payable_invoice_line = self.invoice_2.line_ids.filtered( + lambda line: line.account_id.account_type == "liability_payable" + ) + self.assertTrue(self.invoice_2.selected_for_payment) + (payable_line | payable_invoice_line).reconcile() + self.assertFalse(self.invoice_2.selected_for_payment) diff --git a/account_invoice_select_for_payment/views/account_move.xml b/account_invoice_select_for_payment/views/account_move.xml index c93568a4143..91028f4dae4 100644 --- a/account_invoice_select_for_payment/views/account_move.xml +++ b/account_invoice_select_for_payment/views/account_move.xml @@ -1,5 +1,41 @@ + + account.move + + + + + + + + + + + + account.move @@ -7,8 +43,9 @@