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 committed Sep 26, 2024
1 parent 232beba commit 8f57dfc
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 23 deletions.
12 changes: 9 additions & 3 deletions l10n_it_riba/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ 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".
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
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_riba/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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_riba/models/riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ def _compute_total_amount(self):
)
date_accepted = fields.Date("Acceptance Date")
date_credited = 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_past_due = fields.Date("Past Due Date", readonly=True)
company_id = fields.Many2one(
"res.company",
Expand Down Expand Up @@ -186,10 +195,18 @@ def riba_cancel(self):
slip.state = "cancel"

def settle_all_line(self):
for riba_list in self:
for line in riba_list.line_ids:
if line.state == "credited":
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_credited")
def _onchange_date(self):
Expand Down Expand Up @@ -468,7 +485,26 @@ def confirm(self):
if not line.slip_id.date_accepted:
line.slip_id.date_accepted = fields.Date.context_today(self)

def riba_line_settlement(self):
def button_settle(self):
payment_wizard_action = (

Check warning on line 489 in l10n_it_riba/models/riba.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_riba/models/riba.py#L489

Added line #L489 was not covered by tests
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(

Check warning on line 497 in l10n_it_riba/models/riba.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_riba/models/riba.py#L497

Added line #L497 was not covered by tests
name=_("Settle line"),
target="new",
)
return payment_wizard_action

Check warning on line 501 in l10n_it_riba/models/riba.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_riba/models/riba.py#L501

Added line #L501 was not covered by tests

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.slip_id.config_id.settlement_journal_id:
raise UserError(_("Please define a Settlement Journal."))
Expand All @@ -491,12 +527,13 @@ def riba_line_settlement(self):
riba_line.slip_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.slip_id.config_id.settlement_journal_id.id
),
"date": riba_line.due_date.strftime("%Y-%m-%d"),
"date": move_date,
"ref": move_ref,
}
)
Expand Down
8 changes: 6 additions & 2 deletions l10n_it_riba/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
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
registrazione dalla vista ed elenco ed eseguendo l'azione "Imposta data
di pagamento RiBa".
1 change: 1 addition & 0 deletions l10n_it_riba/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_riba/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,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_riba/tests/riba_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def create_config(self, sbf_collection_type):
"past_due_journal_id": self.bank_journal.id,
"overdue_effects_account_id": self.past_due_account.id,
"protest_charge_account_id": self.expenses_account.id,
"settlement_journal_id": self.bank_journal.id,
}
)

Expand Down
75 changes: 75 additions & 0 deletions l10n_it_riba/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
import datetime
import os

from odoo.exceptions import UserError
Expand Down Expand Up @@ -764,3 +765,77 @@ def test_riba_inv_no_bank(self):
),
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_riba/views/riba_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<button
name="settle_all_line"
type='object'
string="Mark All as Settled"
string="Mark lines as Settled"
class="oe_highlight"
attrs="{'invisible':[('state','!=','credited')]}"
/>
Expand Down Expand Up @@ -209,7 +209,7 @@
icon="fa-exclamation-triangle"
/>
<button
name="riba_line_settlement"
name="button_settle"
type='object'
attrs="{'invisible':['|',('type','=','incasso'),('state','!=','credited')]}"
string="Mark as Settled"
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_riba/views/wizard_due_date_settlement.xml
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_riba/views/wizard_past_due.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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_riba/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
from . import wizard_credit
from . import wizard_past_due
from . import wizard_presentation_riba
from . import wizard_riba_multiple_payment
from . import wizard_due_date_settlement
10 changes: 6 additions & 4 deletions l10n_it_riba/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.slip"].browse(active_ids)
riba_lines = riba_ids.mapped("line_ids").filtered(
lambda rl: rl.state == "credited" 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(

Check warning on line 22 in l10n_it_riba/wizard/wizard_due_date_settlement.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_riba/wizard/wizard_due_date_settlement.py#L22

Added line #L22 was not covered by tests
date=self.payment_date,
)
riba_lines.riba_line_settlement()
10 changes: 8 additions & 2 deletions l10n_it_riba/wizard/wizard_past_due.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def _get_bank_expense_account_id(self):
"account.account", "Bank Fees Account", default=_get_bank_expense_account_id
)
expense_amount = fields.Float("Fees Amount")
date = fields.Date(
help="If empty, the due date in the line will be used.",
readonly=False,
)

def skip(self):
active_id = self.env.context.get("active_id")
Expand Down Expand Up @@ -122,6 +126,8 @@ def create_move(self):
or not wizard.bank_expense_account_id
):
raise UserError(_("Every account is mandatory."))

date = self.date or slip_line.due_date
line_ids = [
(
0,
Expand All @@ -132,7 +138,7 @@ def create_move(self):
"debit": wizard.overdue_effects_amount,
"credit": 0.0,
"partner_id": slip_line.partner_id.id,
"date_maturity": slip_line.due_date,
"date_maturity": date,
},
),
(
Expand Down Expand Up @@ -177,7 +183,7 @@ def create_move(self):
"sequence": slip_line.sequence,
},
"journal_id": wizard.past_due_journal_id.id,
"date": slip_line.due_date,
"date": date,
"line_ids": line_ids,
}

Expand Down
Loading

0 comments on commit 8f57dfc

Please sign in to comment.