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 20, 2025
1 parent 598e993 commit 127dc51
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 36 deletions.
15 changes: 10 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:a2cdacea824dfd13ef255fe16ac1579aa27f2f89714ca16d6c947e8eba08bcf4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -108,10 +108,15 @@ 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
53 changes: 45 additions & 8 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 @@ -228,7 +245,7 @@ def action_cancel_draft(self):

def action_open_lines(self):
action = self.env.ref("l10n_it_ricevute_bancarie.detail_riba_action").read()[0]
action["domain"] = [("slip_id", "=", self.id)]
action["domain"] = [("distinta_id", "=", self.id)]
return action


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.distinta_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
13 changes: 9 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,12 @@ 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
27 changes: 16 additions & 11 deletions l10n_it_ricevute_bancarie/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">ITA - Ricevute bancarie</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:100f1b7d1eb019a23cf3734dd6851726c6bb228961c00615be14977e5c7d470f
!! source digest: sha256:a2cdacea824dfd13ef255fe16ac1579aa27f2f89714ca16d6c947e8eba08bcf4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/14.0/l10n_it_ricevute_bancarie"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-14-0/l10n-italy-14-0-l10n_it_ricevute_bancarie"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><strong>Italiano</strong></p>
Expand Down Expand Up @@ -447,10 +446,18 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
esposizione, cioè l’importo dovuto dal cliente a fronte dell’emissione
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
impostata con la data di scadenza della RiBa, ma è possibile modificarla in due momenti:</p>
<blockquote>
<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 <cite>Data pagamento</cite>,</li>
<li>successivamente a pagamento effettivamente avvenuto selezionando la selezionando la
registrazione dalla vista ed elenco ed eseguendo l’azione “Imposta data
di pagamento RiBa”.</p>
di pagamento RiBa”.</li>
</ul>
</blockquote>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
Expand Down Expand Up @@ -497,9 +504,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down
2 changes: 2 additions & 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 All @@ -268,5 +269,6 @@ def create_config(self, sbf_collection_type):
"unsolved_journal_id": self.bank_journal.id,
"overdue_effects_account_id": self.unsolved_account.id,
"protest_charge_account_id": self.expenses_account.id,
"settlement_journal_id": self.bank_journal.id,
}
)
80 changes: 80 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,81 @@ 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_ricevute_bancarie.action_riba_da_emettere"
)
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_ricevute_bancarie.riba_accreditation_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, "accredited")

# 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 127dc51

Please sign in to comment.