Skip to content

Commit

Permalink
[IMP] l10n_it_riba: add sbf_collection_type
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev authored and toita86 committed Nov 26, 2024
1 parent 54262c2 commit 12d0c6d
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 58 deletions.
4 changes: 4 additions & 0 deletions l10n_it_ricevute_bancarie/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Nella configurazione delle Ri.Ba. è possibile specificare se si tratti di
utilizzare al momento dell'accettazione della distinta da parte della banca.
Tale conto deve essere di tipo 'Crediti' (ad esempio "Ri.Ba. all'incasso",
eventualmente da creare).
Selezionando 'Salvo buon fine' è necessario impostare il tipo di
incasso, immediato o a maturazione valuta: questo influisce sulla gestione
degli insoluti perchè solo nel caso di incasso immediato vengono stornate
le registrazioni di presentazione della RiBa.

La configurazione relativa alla fase di accredito, verrà usata nel momento in
cui la banca accredita l'importo della distinta.
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_ricevute_bancarie/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def _compute_is_unsolved(self):
invoice.is_unsolved = True

def _compute_open_amount(self):
today = fields.Date.today()
for invoice in self:
if invoice.is_riba_payment:
today = fields.Date.today()
open_amount_line_ids = invoice.line_ids.filtered(
lambda line, today=today: line.riba
and line.display_type == "payment_term"
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_ricevute_bancarie/models/riba_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class RibaConfiguration(models.Model):
"Issue Mode",
required=True,
)
sbf_collection_type = fields.Selection(
[("immediate", "Immediate"), ("maturation", "At currency maturation")],
"Collection Type",
)
bank_id = fields.Many2one(
"res.partner.bank",
"Bank Account",
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_ricevute_bancarie/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Nella configurazione delle Ri.Ba. è possibile specificare se si tratti di
utilizzare al momento dell'accettazione della distinta da parte della banca.
Tale conto deve essere di tipo 'Crediti' (ad esempio "Ri.Ba. all'incasso",
eventualmente da creare).
Selezionando 'Salvo buon fine' è necessario impostare il tipo di
incasso, immediato o a maturazione valuta: questo influisce sulla gestione
degli insoluti perchè solo nel caso di incasso immediato vengono stornate
le registrazioni di presentazione della RiBa.

La configurazione relativa alla fase di accredito, verrà usata nel momento in
cui la banca accredita l'importo della distinta.
Expand Down
6 changes: 5 additions & 1 deletion l10n_it_ricevute_bancarie/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
‘Salvo buon fine’, è necessario specificare almeno il registro e il conto da
utilizzare al momento dell’accettazione della distinta da parte della banca.
Tale conto deve essere di tipo ‘Crediti’ (ad esempio “Ri.Ba. all’incasso”,
eventualmente da creare).</p>
eventualmente da creare).
Selezionando ‘Salvo buon fine’ è necessario impostare il tipo di
incasso, immediato o a maturazione valuta: questo influisce sulla gestione
degli insoluti perchè solo nel caso di incasso immediato vengono stornate
le registrazioni di presentazione della RiBa.</p>
<p>La configurazione relativa alla fase di accredito, verrà usata nel momento in
cui la banca accredita l’importo della distinta.
È possibile utilizzare un registro creato appositamente, ad esempio “Accredito Ri.Ba.”,
Expand Down
44 changes: 39 additions & 5 deletions l10n_it_ricevute_bancarie/tests/riba_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ def setUp(self):
],
limit=1,
)
self.account_payment_term_riba = self.env.ref(
"l10n_it_ricevute_bancarie.account_payment_term_riba"
)
self.invoice = self._create_invoice()
self.invoice2 = self._create_invoice()
self.invoice_sbf = self._create_sbf_invoice()
self.sbf_effects = self.env["account.account"].create(
{
"code": "STC",
Expand Down Expand Up @@ -100,10 +104,8 @@ def setUp(self):
"company_id": self.company2.id,
}
)
self.riba_config = self.create_config()
self.account_payment_term_riba = self.env.ref(
"l10n_it_ricevute_bancarie.account_payment_term_riba"
)
self.riba_config_sbf_maturation = self.create_config("maturation")
self.riba_config_sbf_immediate = self.create_config("immediate")
self.company_bank.codice_sia = "AA555"

def _create_service_due_cost(self):
Expand Down Expand Up @@ -157,6 +159,37 @@ def _create_invoice(self):
}
)

def _create_sbf_invoice(self):
self.partner.property_account_receivable_id = self.account_rec1_id.id
recent_date = (
self.env["account.move"]
.search([("invoice_date", "!=", False)], order="invoice_date desc", limit=1)
.invoice_date
)
return self.env["account.move"].create(
{
"invoice_date": recent_date,
"move_type": "out_invoice",
"journal_id": self.sale_journal.id,
"partner_id": self.partner.id,
"invoice_payment_term_id": self.account_payment_term_riba.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "product1",
"product_id": self.product1.id,
"quantity": 1.0,
"price_unit": 450.00,
"account_id": self.sale_account.id,
"tax_ids": [[6, 0, []]],
},
)
],
}
)

def _create_pterm(self):
return self.env["account.payment.term"].create(
{
Expand Down Expand Up @@ -207,11 +240,12 @@ def _create_pterm2(self):
}
)

def create_config(self):
def create_config(self, sbf_collection_type):
return self.env["riba.configuration"].create(
{
"name": "Subject To Collection",
"type": "sbf",
"sbf_collection_type": sbf_collection_type,
"bank_id": self.company_bank.id,
"acceptance_journal_id": self.bank_journal.id,
"accreditation_journal_id": self.bank_journal.id,
Expand Down
98 changes: 64 additions & 34 deletions l10n_it_ricevute_bancarie/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,8 @@ def test_delete_due_cost_line(self):
# Collection fees line has been unlink
self.assertEqual(len(self.invoice.invoice_line_ids), 1)

def test_riba_flow(self):
self.partner.property_account_receivable_id = self.account_rec1_id.id
recent_date = (
self.env["account.move"]
.search([("invoice_date", "!=", False)], order="invoice_date desc", limit=1)
.invoice_date
)
invoice = self.env["account.move"].create(
{
"invoice_date": recent_date,
"move_type": "out_invoice",
"journal_id": self.sale_journal.id,
"partner_id": self.partner.id,
"invoice_payment_term_id": self.account_payment_term_riba.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "product1",
"product_id": self.product1.id,
"quantity": 1.0,
"price_unit": 450.00,
"account_id": self.sale_account.id,
},
)
],
}
)
def riba_sbf_common(self, configuration_id):
invoice = self._create_sbf_invoice()
invoice._onchange_riba_partner_bank_id()
invoice.action_post()
riba_move_line_id = False
Expand All @@ -121,7 +94,7 @@ def test_riba_flow(self):

# issue wizard
wizard_riba_issue = self.env["riba.issue"].create(
{"configuration_id": self.riba_config.id}
{"configuration_id": configuration_id}
)
action = wizard_riba_issue.with_context(
{"active_ids": [riba_move_line_id]}
Expand All @@ -137,7 +110,7 @@ def test_riba_flow(self):
self.assertEqual(len(riba_list.acceptance_move_ids), 1)
self.assertEqual(len(riba_list.payment_ids), 0)

# I print the C/O slip report
# I print the C/O distinta report
docargs = {
"doc_ids": riba_list.ids,
"doc_model": "riba.distinta",
Expand Down Expand Up @@ -169,6 +142,10 @@ def test_riba_flow(self):
)
wiz_accreditation.create_move()
self.assertEqual(riba_list.state, "accredited")
return invoice, riba_list

def test_riba_sbf_maturation_flow(self):
invoice, riba_list = self.riba_sbf_common(self.riba_config_sbf_maturation.id)

bank_accreditation_line = False
for accr_line in riba_list.accreditation_move_id.line_ids:
Expand Down Expand Up @@ -241,6 +218,59 @@ def test_riba_flow(self):
self.assertEqual(riba_list.state, "accredited")
self.assertEqual(riba_list.line_ids[0].state, "accredited")

def test_riba_sbf_immediate_flow(self):
invoice, riba_list = self.riba_sbf_common(self.riba_config_sbf_immediate.id)

# past due wizard
unsolved_wizard = (
self.env["riba.unsolved"]
.with_context(
active_model="riba.distinta.line",
active_ids=[riba_list.line_ids[0].id],
active_id=riba_list.line_ids[0].id,
)
.create(
{
"bank_amount": 455,
"expense_amount": 5,
}
)
)
unsolved_wizard.create_move()
self.assertEqual(riba_list.state, "unsolved")
self.assertEqual(len(riba_list.line_ids), 1)
self.assertEqual(riba_list.line_ids[0].state, "unsolved")
self.assertTrue(invoice.unsolved_move_line_ids)

# Verifica storno registrazioni di presentazione della RiBa
unsolved_line_ids = riba_list.line_ids.unsolved_move_id.line_ids
unsolved_line_id_bills = unsolved_line_ids.filtered(
lambda line: line.name == "Bills"
)
self.assertEqual(len(unsolved_line_id_bills), 1)
self.assertEqual(
unsolved_line_id_bills.account_id, unsolved_wizard.effects_account_id
)
self.assertEqual(unsolved_line_id_bills.credit, unsolved_wizard.effects_amount)
unsolved_line_id_riba = unsolved_line_ids.filtered(
lambda line: line.name == "C/O"
)
self.assertEqual(len(unsolved_line_id_riba), 1)
self.assertEqual(
unsolved_line_id_riba.account_id, unsolved_wizard.riba_bank_account_id
)
self.assertEqual(unsolved_line_id_riba.debit, unsolved_wizard.riba_bank_amount)

# Se la compute non viene invocata il test fallisce
riba_list._compute_unsolved_move_ids()
self.assertEqual(len(riba_list.unsolved_move_ids), 1)
bank_unsolved_line = False
for unsolved_line in riba_list.unsolved_move_ids[0].line_ids:
if unsolved_line.account_id.id == self.bank_account.id:
bank_unsolved_line = unsolved_line
break
self.assertTrue(bank_unsolved_line)

def test_unsolved_riba(self):
# create another invoice to test past due C/O
self.partner.property_account_receivable_id = self.account_rec1_id.id
Expand Down Expand Up @@ -278,7 +308,7 @@ def test_unsolved_riba(self):
riba_move_line_id = move_line.id
# issue wizard
wizard_riba_issue = self.env["riba.issue"].create(
{"configuration_id": self.riba_config.id}
{"configuration_id": self.riba_config_sbf_maturation.id}
)
action = wizard_riba_issue.with_context(
{"active_ids": [riba_move_line_id]}
Expand Down Expand Up @@ -404,7 +434,7 @@ def test_riba_fatturapa(self):
lambda x: x.account_id == self.account_rec1_id
)
wizard_riba_issue = self.env["riba.issue"].create(
{"configuration_id": self.riba_config.id}
{"configuration_id": self.riba_config_sbf_maturation.id}
)
action = wizard_riba_issue.with_context(
{"active_ids": [riba_move_line_id.id]}
Expand Down Expand Up @@ -507,7 +537,7 @@ def test_riba_fatturapa_group(self):
lambda x: x.account_id == self.account_rec1_id
)
wizard_riba_issue = self.env["riba.issue"].create(
{"configuration_id": self.riba_config.id}
{"configuration_id": self.riba_config_sbf_maturation.id}
)
action = wizard_riba_issue.with_context(
{"active_ids": [riba_move_line_id.id, riba_move_line1_id.id]}
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_ricevute_bancarie/views/configuration_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<group>
<field name="name" />
<field name="type" />
<field
name="sbf_collection_type"
attrs="{'required': [('type','=','sbf')], 'invisible': [('type','!=','sbf')]}"
/>
<field
name="bank_id"
domain="[('partner_id.ref_company_ids', 'in', [company_id])]"
Expand Down
Loading

0 comments on commit 12d0c6d

Please sign in to comment.