Skip to content

Commit

Permalink
[12.0][IMP] Add cig-cup compatibility for riba
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Sep 26, 2020
1 parent db2245b commit bac9078
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 11 deletions.
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/__manifest__.py
Expand Up @@ -19,6 +19,7 @@
'depends': [
'account',
'account_group_menu',
'l10n_it_fatturapa_out',
'l10n_it_fiscalcode',
'base_iban',
'l10n_it_abicab',
Expand Down
17 changes: 17 additions & 0 deletions l10n_it_ricevute_bancarie/models/riba.py
Expand Up @@ -218,6 +218,23 @@ def _compute_line_values(self):
compute='_compute_line_values', string="Invoice Date", size=256)
invoice_number = fields.Char(
compute='_compute_line_values', string="Invoice Number", size=256)
cig = fields.Char(
compute='_get_cig_cup_values', string="CIG", size=256)
cup = fields.Char(
compute='_get_cig_cup_values', string="CUP", size=256)

@api.multi
def _get_cig_cup_values(self):
for line in self:
line.cig = ""
line.cup = ""
for move_line in line.move_line_ids:
for related_document in move_line.move_line_id.invoice_id.\
related_documents:
if related_document.cup:
line.cup = str(related_document.cup)
if related_document.cig:
line.cig = str(related_document.cig)

@api.multi
def move_line_id_payment_get(self):
Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/readme/CONTRIBUTORS.rst
Expand Up @@ -8,3 +8,4 @@
* Marco Calcagni <mcalcagni@dinamicheaziendali.it>
* Sergio Zanchetta <https://github.com/primes2h>
* Simone Vanin <simone.vanin@agilebg.com>
* Sergio Corato <https://github.com/sergiocorato>
2 changes: 2 additions & 0 deletions l10n_it_ricevute_bancarie/tests/riba_common.py
Expand Up @@ -15,6 +15,7 @@ def setUp(self):
self.account_asset_user_type = self.env.ref(
'account.data_account_type_fixed_assets')
self.partner = self.env.ref('base.res_partner_3')
self.partner.vat = 'IT01234567890'
self.product1 = self.env.ref('product.product_product_5')
self.sale_journal = self.env['account.journal'].search(
[('type', '=', 'sale')])[0]
Expand Down Expand Up @@ -70,6 +71,7 @@ def setUp(self):
self.riba_config = self.create_config()
self.account_payment_term_riba = self.env.ref(
'l10n_it_ricevute_bancarie.account_payment_term_riba')
self.company_bank.codice_sia = 'AA555'

def _create_service_due_cost(self):
return self.env['product.product'].create({
Expand Down
138 changes: 138 additions & 0 deletions l10n_it_ricevute_bancarie/tests/test_riba.py
Expand Up @@ -3,6 +3,7 @@
# Copyright (C) 2017 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import base64
import os
from . import riba_common
from odoo.tools import config
Expand Down Expand Up @@ -294,3 +295,140 @@ def test_unsolved_riba(self):
self.assertEqual(riba_list.state, 'accredited')
self.assertEqual(len(riba_list.line_ids), 1)
self.assertEqual(riba_list.line_ids[0].state, 'accredited')

def test_riba_fatturapa(self):
recent_date = self.env['account.invoice'].search(
[('date_invoice', '!=', False)], order='date_invoice desc',
limit=1).date_invoice
invoice = self.env['account.invoice'].create({
'date_invoice': recent_date,
'journal_id': self.sale_journal.id,
'partner_id': self.partner.id,
'payment_term_id': self.account_payment_term_riba.id,
'account_id': self.account_rec1_id.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
}
)],
'related_documents': [(
0, 0, {
'type': 'order',
'name': 'SO1232',
'cig': '7987210EG5',
'cup': 'H71N17000690124',
}
)],
})
invoice.action_invoice_open()
# issue wizard
riba_move_line_id = invoice.move_id.line_ids.filtered(
lambda x: x.account_id == self.account_rec1_id
)
wizard_riba_issue = self.env['riba.issue'].create({
'configuration_id': self.riba_config.id
})
action = wizard_riba_issue.with_context(
{'active_ids': [riba_move_line_id.id]}
).create_list()
riba_list_id = action and action['res_id'] or False
riba_list = self.distinta_model.browse(riba_list_id)
riba_list.confirm()
self.assertEqual(riba_list.line_ids[0].cig, '7987210EG5')
self.assertEqual(riba_list.line_ids[0].cup, 'H71N17000690124')
wizard_riba_export = self.env['riba.file.export'].create({})
wizard_riba_export.with_context(
{'active_ids': [riba_list.id]}
).act_getfile()
riba_txt = base64.decodebytes(wizard_riba_export.riba_txt)
self.assertTrue(
b'CIG: 7987210EG5 CUP: H71N17000690124' in riba_txt
)

def test_riba_fatturapa_group(self):
self.partner.group_riba = True
recent_date = self.env['account.invoice'].search(
[('date_invoice', '!=', False)], order='date_invoice desc',
limit=1).date_invoice
invoice = self.env['account.invoice'].create({
'date_invoice': recent_date,
'journal_id': self.sale_journal.id,
'partner_id': self.partner.id,
'payment_term_id': self.account_payment_term_riba.id,
'account_id': self.account_rec1_id.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
}
)],
'related_documents': [(
0, 0, {
'type': 'order',
'name': 'SO1232',
'cig': '7987210EG5',
'cup': 'H71N17000690124',
}
)],
})
invoice.action_invoice_open()
invoice1 = self.env['account.invoice'].create({
'date_invoice': recent_date,
'journal_id': self.sale_journal.id,
'partner_id': self.partner.id,
'payment_term_id': self.account_payment_term_riba.id,
'account_id': self.account_rec1_id.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
}
)],
'related_documents': [(
0, 0, {
'type': 'order',
'name': 'SO1232',
'cig': '7987210EG5',
'cup': 'H71N17000690125',
}
)],
})
invoice1.action_invoice_open()
# issue wizard
riba_move_line_id = invoice.move_id.line_ids.filtered(
lambda x: x.account_id == self.account_rec1_id
)
riba_move_line1_id = invoice1.move_id.line_ids.filtered(
lambda x: x.account_id == self.account_rec1_id
)
wizard_riba_issue = self.env['riba.issue'].create({
'configuration_id': self.riba_config.id
})
action = wizard_riba_issue.with_context(
{'active_ids': [riba_move_line_id.id, riba_move_line1_id.id]}
).create_list()
riba_list_id = action and action['res_id'] or False
riba_list = self.distinta_model.browse(riba_list_id)
riba_list.confirm()
self.assertTrue(len(riba_list.line_ids), 2)
wizard_riba_export = self.env['riba.file.export'].create({})
wizard_riba_export.with_context(
{'active_ids': [riba_list.id]}
).act_getfile()
riba_txt = base64.decodebytes(wizard_riba_export.riba_txt)
self.assertTrue(
b'CIG: 7987210EG5 CUP: H71N17000690124' in riba_txt
)
self.assertTrue(
b'CIG: 7987210EG5 CUP: H71N17000690125' in riba_txt
)
2 changes: 2 additions & 0 deletions l10n_it_ricevute_bancarie/views/riba_detail_view.xml
Expand Up @@ -33,6 +33,8 @@
<field name="sequence"/>
<field name="invoice_number"/>
<field name="invoice_date"/>
<field name="cig"/>
<field name="cup"/>
<field name="partner_id"/>
<field name="iban"/>
<field name="amount" sum="Amount"/>
Expand Down
11 changes: 8 additions & 3 deletions l10n_it_ricevute_bancarie/wizard/wizard_riba_file_export.py
Expand Up @@ -130,9 +130,10 @@ def _Record40(
descrizione_domiciliataria.ljust(50)[0:50] + "\r\n")

def _Record50(
self, importo_debito, invoice_ref, data_invoice, partita_iva_creditore
self, importo_debito, invoice_ref, data_invoice, partita_iva_creditore,
cig, cup
):
self._descrizione = 'PER LA FATTURA N. ' + invoice_ref + \
self._descrizione = cig + cup + 'PER LA FATTURA N. ' + invoice_ref + \
' DEL ' + data_invoice + ' IMP ' + str(importo_debito)
return (
" 50" + str(self._progressivo).rjust(7, '0') +
Expand Down Expand Up @@ -176,7 +177,9 @@ def _creaFile(self, intestazione, ricevute_bancarie):
value[5], value[6], value[7], value[8], value[11])
accumulatore = accumulatore + \
self._Record50(
value[2], value[13], value[14], intestazione[11])
value[2], value[13], value[14], intestazione[11],
value[15], value[16]
)
accumulatore = accumulatore + self._Record51(value[0])
accumulatore = accumulatore + self._Record70()
accumulatore = accumulatore + self._RecordEF()
Expand Down Expand Up @@ -278,6 +281,8 @@ def act_getfile(self):
line.partner_id.ref and line.partner_id.ref[:16] or '',
line.invoice_number[:40],
line.invoice_date,
'CIG: %s ' % line.cig if line.cig else '',
'CUP: %s ' % line.cup if line.cup else '',
]
arrayRiba.append(Riba)

Expand Down
21 changes: 13 additions & 8 deletions l10n_it_ricevute_bancarie/wizard/wizard_riba_issue.py
Expand Up @@ -55,14 +55,19 @@ def create_rdl(countme, bank_id, rd_id, date_maturity, partner_id,
grouped_lines = {}
move_lines = move_line_obj.search(
[('id', 'in', self._context['active_ids'])])
for move_line in move_lines:
if move_line.partner_id.group_riba:
if not grouped_lines.get((move_line.partner_id.id,
move_line.date_maturity), False):
do_group_riba = True
if len(set(['%s%s' % (x.cig, x.cup) for x in
move_lines.mapped('invoice_id.related_documents')])) > 1:
do_group_riba = False
if do_group_riba:
for move_line in move_lines:
if move_line.partner_id.group_riba:
if not grouped_lines.get((move_line.partner_id.id,
move_line.date_maturity), False):
grouped_lines[(move_line.partner_id.id,
move_line.date_maturity)] = []
grouped_lines[(move_line.partner_id.id,
move_line.date_maturity)] = []
grouped_lines[(move_line.partner_id.id,
move_line.date_maturity)].append(move_line)
move_line.date_maturity)].append(move_line)

# create lines
countme = 1
Expand All @@ -74,7 +79,7 @@ def create_rdl(countme, bank_id, rd_id, date_maturity, partner_id,
raise exceptions.Warning(
_('No bank has been specified for partner %s!') %
move_line.partner_id.name)
if move_line.partner_id.group_riba:
if move_line.partner_id.group_riba and do_group_riba:
for key in grouped_lines:
if (key[0] == move_line.partner_id.id and
key[1] == move_line.date_maturity):
Expand Down

0 comments on commit bac9078

Please sign in to comment.