Skip to content

Commit

Permalink
[IMP] l10n_it_riba: Pay multiple lines at once
Browse files Browse the repository at this point in the history
Also allow to set a date during payment and past due process
  • Loading branch information
SirAionTech authored and odooNextev committed Jan 17, 2025
1 parent 598e993 commit 7a00e93
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 27 deletions.
14 changes: 9 additions & 5 deletions l10n_it_ricevute_bancarie/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ITA - Ricevute bancarie
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:100f1b7d1eb019a23cf3734dd6851726c6bb228961c00615be14977e5c7d470f
!! source digest: sha256:8e70b2caa85bc9320745588e56ff493847d8f8f11304c626249a3544e36cf536
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -108,10 +108,14 @@ esposizione, cioè l'importo dovuto dal cliente a fronte dell'emissione
della RiBa non ancora scaduta.

In maniera predefinita la data delle registrazioni dei pagamenti viene
impostata con la data di scadenza della RiBa, ma è possibile modificarla
successivamente a pagamento effettivamente avvenuto selezionando la
registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data
di pagamento RiBa".
impostata con la data di scadenza della RiBa, ma è possibile modificarla in due momenti:
- durante la creazione del pagamento,
cliccando su "Segna righe come pagate" o su "Segna coma pagata"
o usando l'azione "Registrazione Riba a data di scadenza"
e indicando una data nel campo `Data pagamento`,
- successivamente a pagamento effettivamente avvenuto selezionando la selezionando la
registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data
di pagamento RiBa".

Known issues / Roadmap
======================
Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"views/riba_detail_view.xml",
"views/wizard_presentation.xml",
"views/wizard_due_date_settlement.xml",
"wizard/wizard_riba_multiple_payment_views.xml",
],
"demo": ["demo/riba_demo.xml"],
"installable": True,
Expand Down
51 changes: 44 additions & 7 deletions l10n_it_ricevute_bancarie/models/riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ def _compute_total_amount(self):
)
date_accepted = fields.Date("Acceptance Date")
date_accreditation = fields.Date("Credit Date")
date_paid = fields.Date("Payment Date", readonly=True)
date_paid = fields.Date(
string="Payment Date",
help="Default date for payments.",
readonly=True,
states={
"credited": [
("readonly", False),
],
},
)
date_unsolved = fields.Date("Past Due Date", readonly=True)
company_id = fields.Many2one(
"res.company",
Expand Down Expand Up @@ -187,10 +196,18 @@ def riba_cancel(self):
distinta.state = "cancel"

def settle_all_line(self):
for riba_list in self:
for line in riba_list.line_ids:
if line.state == "accredited":
line.riba_line_settlement()
payment_wizard_action = (
self.env["riba.payment.multiple"]
.with_context(
active_ids=self.ids,
)
.get_formview_action()
)
payment_wizard_action.update(
name=_("Settle lines"),
target="new",
)
return payment_wizard_action

@api.onchange("date_accepted", "date_accreditation")
def _onchange_date(self):
Expand Down Expand Up @@ -475,7 +492,26 @@ def confirm(self):
if not line.distinta_id.date_accepted:
line.distinta_id.date_accepted = fields.Date.context_today(self)

def riba_line_settlement(self):
def button_settle(self):
payment_wizard_action = (
self.env["riba.payment.multiple"]
.with_context(
active_ids=self.slip_id.ids,
default_riba_line_ids=self.ids,
)
.get_formview_action()
)
payment_wizard_action.update(
name=_("Settle line"),
target="new",
)
return payment_wizard_action

def riba_line_settlement(self, date=None):
"""Create payment the acceptance move of each line in `self`.
:param date: The created payment's date.
"""
for riba_line in self:
if not riba_line.distinta_id.config_id.settlement_journal_id:
raise UserError(_("Please define a Settlement Journal."))
Expand All @@ -498,12 +534,13 @@ def riba_line_settlement(self):
riba_line.distinta_id.name,
riba_line.partner_id.name,
)
move_date = date or riba_line.due_date.strftime("%Y-%m-%d")
settlement_move = move_model.create(
{
"journal_id": (
riba_line.distinta_id.config_id.settlement_journal_id.id
),
"date": riba_line.due_date.strftime("%Y-%m-%d"),
"date": move_date,
"ref": move_ref,
}
)
Expand Down
12 changes: 8 additions & 4 deletions l10n_it_ricevute_bancarie/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ esposizione, cioè l'importo dovuto dal cliente a fronte dell'emissione
della RiBa non ancora scaduta.

In maniera predefinita la data delle registrazioni dei pagamenti viene
impostata con la data di scadenza della RiBa, ma è possibile modificarla
successivamente a pagamento effettivamente avvenuto selezionando la
registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data
di pagamento RiBa".
impostata con la data di scadenza della RiBa, ma è possibile modificarla in due momenti:
- durante la creazione del pagamento,
cliccando su "Segna righe come pagate" o su "Segna coma pagata"
o usando l'azione "Registrazione Riba a data di scadenza"
e indicando una data nel campo `Data pagamento`,
- successivamente a pagamento effettivamente avvenuto selezionando la selezionando la
registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data
di pagamento RiBa".
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ access_riba_file_export,riba_file_export,model_riba_file_export,account.group_ac
access_presentation_riba_issue,access_presentation_riba_issue,model_presentation_riba_issue,account.group_account_invoice,1,1,1,1
access_riba_due_date_settlement,riba_due_date_settlement,model_riba_due_date_settlement,account.group_account_invoice,1,1,1,1
access_riba_payment_date,riba_payment_date,model_riba_payment_date,account.group_account_invoice,1,1,1,1
access_riba_multiple_payment_date,Full access to Pay multiple RiBa lines,model_riba_payment_multiple,account.group_account_invoice,1,1,1,1
13 changes: 10 additions & 3 deletions l10n_it_ricevute_bancarie/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,16 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
della RiBa non ancora scaduta.</p>
<p>In maniera predefinita la data delle registrazioni dei pagamenti viene
impostata con la data di scadenza della RiBa, ma è possibile modificarla
successivamente a pagamento effettivamente avvenuto selezionando la
registrazione dalla vista ed elenco ed eseguendo l’azione “Imposta data
di pagamento RiBa”.</p>
in due momenti:</p>
<ul class="simple">
<li>durante la creazione del pagamento, cliccando su “Segna righe come
pagate” o su “Segna coma pagata” o usando l’azione “Registrazione
Riba a data di scadenza” e indicando una data nel campo
<tt class="docutils literal">Data pagamento</tt>,</li>
<li>successivamente a pagamento effettivamente avvenuto selezionando la
registrazione dalla vista ed elenco ed eseguendo l’azione “Imposta
data di pagamento RiBa”.</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/tests/riba_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def create_config_incasso(self):
"bank_id": self.company_bank.id,
"acceptance_journal_id": self.bank_journal.id,
"acceptance_account_id": self.sbf_effects.id,
"settlement_journal_id": self.bank_journal.id,
}
)

Expand Down
76 changes: 76 additions & 0 deletions l10n_it_ricevute_bancarie/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
import datetime
import os

from odoo.exceptions import UserError
from odoo.fields import first
from odoo.tests import Form
from odoo.tools import config, safe_eval

Expand Down Expand Up @@ -668,3 +670,77 @@ def test_riba_inv_no_bank(self):
self.assertIn("Cannot post invoices", err_msg)
self.assertIn(self.invoice.partner_id.display_name, err_msg)
self.assertIn(str(self.invoice.amount_total), err_msg)

def test_riba_payment_date_multiple_lines(self):
"""A specific date can be set to pay multiple RiBa lines."""
# Arrange
company = self.env.company
payment_date = datetime.date(2020, month=1, day=1)
payment_term = self.payment_term2
riba_configuration = self.riba_config_sbf_immediate
product = self.product1
partner = self.partner
company.due_cost_service_id = self.service_due_cost

invoice_form = Form(
self.env["account.move"].with_context(
default_move_type="out_invoice",
default_name="Test invoice",
)
)
invoice_form.partner_id = partner
invoice_form.invoice_payment_term_id = payment_term
invoice_form.riba_partner_bank_id = first(partner.bank_ids)
with invoice_form.invoice_line_ids.new() as line:
line.product_id = product
invoice = invoice_form.save()
invoice.action_post()

to_issue_action = self.env.ref("l10n_it_riba.action_riba_to_issue")
to_issue_records = self.env[to_issue_action.res_model].search(
safe_eval.safe_eval(to_issue_action.domain)
)
invoice_to_issue_records = to_issue_records & invoice.line_ids
self.assertTrue(invoice_to_issue_records)

issue_wizard_model = self.env["riba.issue"].with_context(
active_model=invoice_to_issue_records._name,
active_ids=invoice_to_issue_records.ids,
)
issue_wizard_form = Form(issue_wizard_model)
issue_wizard_form.configuration_id = riba_configuration
issue_wizard = issue_wizard_form.save()
issue_result = issue_wizard.create_list()
slip = self.env[issue_result["res_model"]].browse(issue_result["res_id"])

slip.confirm()
self.assertEqual(slip.state, "accepted")

credit_wizard_action = self.env.ref("l10n_it_riba.riba_credit_action")
credit_wizard = (
self.env[credit_wizard_action["res_model"]]
.with_context(active_id=slip.id)
.create(
{
"bank_amount": invoice.amount_total,
}
)
)
credit_wizard.create_move()
self.assertEqual(slip.state, "credited")

# Act
payment_wizard_action = slip.settle_all_line()
payment_wizard_form = Form(
self.env[payment_wizard_action["res_model"]].with_context(
**payment_wizard_action["context"]
)
)
payment_wizard_form.payment_date = payment_date
payment_wizard = payment_wizard_form.save()
payment_wizard.pay()

# Assert
self.assertEqual(slip.state, "paid")
payment_move = slip.payment_ids.move_id
self.assertEqual(payment_move.date, payment_date)
4 changes: 2 additions & 2 deletions l10n_it_ricevute_bancarie/views/riba_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<button
name="settle_all_line"
type='object'
string="Mark All as Settled"
string="Mark lines as Settled"
class="oe_highlight"
attrs="{'invisible':[('state','!=','accredited')]}"
/>
Expand Down Expand Up @@ -206,7 +206,7 @@
icon="fa-exclamation-triangle"
/>
<button
name="riba_line_settlement"
name="button_settle"
type='object'
attrs="{'invisible':['|',('type','=','incasso'),('state','!=','accredited')]}"
string="Mark as Settled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/>
<group>
<field name="due_date" />
<field name="riba_ids" invisible="True" />
<field name="payment_date" />
</group>
<footer>
<button
Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/views/wizard_unsolved.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<field name="bank_amount" />
<field name="bank_expense_account_id" />
<field name="expense_amount" />
<field name="date" />
</group>
<footer>
<button
Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
from . import wizard_accreditation
from . import wizard_unsolved
from . import wizard_presentation_riba
from . import wizard_riba_multiple_payment
from . import wizard_due_date_settlement
from . import wizard_riba_payment_date
10 changes: 6 additions & 4 deletions l10n_it_ricevute_bancarie/wizard/wizard_due_date_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class RibaDueDateSettlement(models.TransientModel):
_name = "riba.due.date.settlement"
_inherit = "riba.payment.multiple"
_description = "Riba Due Date Settlement"

due_date = fields.Date()
Expand All @@ -15,8 +16,9 @@ def due_date_settlement_confirm(self):
active_ids = self.env.context.get("active_ids", False)
if not active_ids:
raise UserError(_("No active ID found."))
riba_ids = self.env["riba.distinta"].browse(active_ids)
riba_lines = riba_ids.mapped("line_ids").filtered(
lambda rl: rl.state == "accredited" and rl.due_date == self.due_date
riba_lines = self.riba_line_ids.filtered(
lambda rl: rl.due_date == self.due_date
)
riba_lines.riba_line_settlement(
date=self.payment_date,
)
riba_lines.riba_line_settlement()
Loading

0 comments on commit 7a00e93

Please sign in to comment.