Skip to content

[IMP] Remove the to pay mark on an invoice when it is fully paid on in payment #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions account_invoice_select_for_payment/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -78,21 +82,22 @@ Authors
Contributors
------------

- Alexandre Fayolle <[email protected]>
- Hiep Nguyen Hoang <[email protected]>
- Khoi (Kien Kim) <[email protected]>
- Alexandre Fayolle <[email protected]>
- Hiep Nguyen Hoang <[email protected]>
- Khoi (Kien Kim) <[email protected]>
- Florian da Costa <[email protected]>

Other credits
-------------

The development of this module has been financially supported by:

- Camptocamp
- Camptocamp

The migration of this module from 14.0 to 18.0 was financially supported
by:

- Camptocamp
- Camptocamp

Maintainers
-----------
Expand Down
16 changes: 14 additions & 2 deletions account_invoice_select_for_payment/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions account_invoice_select_for_payment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Alexandre Fayolle \<<[email protected]>\>
- Hiep Nguyen Hoang \<<[email protected]>\>
- Khoi (Kien Kim) \<<[email protected]>\>
- Florian da Costa \<<[email protected]>\>
2 changes: 2 additions & 0 deletions account_invoice_select_for_payment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions account_invoice_select_for_payment/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ <h1 class="title">Account Invoice Select for Payment</h1>
<p>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.</p>
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.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Expand All @@ -398,7 +400,9 @@ <h1 class="title">Account Invoice Select for Payment</h1>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>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.</p>
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.</p>
<p>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.</p>
Expand Down Expand Up @@ -427,6 +431,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Alexandre Fayolle &lt;<a class="reference external" href="mailto:alexandre.fayolle&#64;camptocamp.com">alexandre.fayolle&#64;camptocamp.com</a>&gt;</li>
<li>Hiep Nguyen Hoang &lt;<a class="reference external" href="mailto:hiepnh&#64;trobz.com">hiepnh&#64;trobz.com</a>&gt;</li>
<li>Khoi (Kien Kim) &lt;<a class="reference external" href="mailto:khoikk&#64;trobz.com">khoikk&#64;trobz.com</a>&gt;</li>
<li>Florian da Costa &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from odoo import fields
from odoo.tests import TransactionCase


Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
39 changes: 38 additions & 1 deletion account_invoice_select_for_payment/views/account_move.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_move_form" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<button name="button_draft" position="after">
<button
name="action_toggle_select_for_payment"
string="To Pay"
type="object"
invisible="selected_for_payment == True or payment_state not in ('not_paid', 'partial') or move_type not in ('in_invoice', 'out_refund')"
class="btn-primary"
style="background-color:green"
/>
<button
name="action_toggle_select_for_payment"
string="Not To Pay"
type="object"
invisible="selected_for_payment == False or payment_state not in ('not_paid', 'partial') or move_type not in ('in_invoice', 'out_refund')"
class="btn-primary"
style="background-color:grey"
/>
</button>
<xpath expr="//sheet/widget[5]" position="after">
<widget
name="web_ribbon"
title="To Pay"
bg_color="bg-info"
invisible="selected_for_payment == False or payment_state != 'not_paid' or move_type not in ('in_invoice', 'out_refund')"
/>
</xpath>
<field name="partner_bank_id" position="after">
<field name="selected_for_payment" invisible="1" />
</field>
</field>
</record>

<record id="view_invoice_tree" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree" />
<field name="arch" type="xml">
<field name="name" position="before">
<field
name="selected_for_payment"
invisible="payment_state not in ('not_paid', 'partial')"
invisible="payment_state not in ('not_paid', 'partial') or move_type not in ('in_invoice', 'out_refund')"
widget="boolean_toggle"
optional="show"
/>
</field>
</field>
Expand Down