Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0] FIX liquidazione IVA: calcolo credito anno precedente e impostazione del campo corretto in comunicazione #1482

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions account_vat_period_end_statement/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _get_default_interest_percent(self):
'paid': [('readonly', True)],
'draft': [('readonly', False)]
}, digits=dp.get_precision('Account'))
previous_year_credit = fields.Boolean("Previous year credits")
previous_debit_vat_account_id = fields.Many2one(
'account.account', 'Previous Debits VAT',
help='Debit VAT from previous periods',
Expand Down Expand Up @@ -500,6 +501,17 @@ def compute_amounts(self):
statement.write(
{'previous_credit_vat_amount': (
- prev_statement.authority_vat_amount)})
company = statement.company_id or self.env.user.company_id
statement_fiscal_year_dates = (
company.compute_fiscalyear_dates(statement.date))
prev_statement_fiscal_year_dates = (
company.compute_fiscalyear_dates(prev_statement.date))
if (
prev_statement_fiscal_year_dates['date_to'] <
statement_fiscal_year_dates['date_from']
):
statement.write({
'previous_year_credit': True})

credit_line_ids, debit_line_ids = self._get_credit_debit_lines(
statement)
Expand Down
56 changes: 52 additions & 4 deletions account_vat_period_end_statement/tests/test_vat_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase
from datetime import datetime
from datetime import datetime, date
from dateutil.rrule import MONTHLY


Expand All @@ -23,6 +23,14 @@ def setUp(self):
'unit_of_time': MONTHLY,
'count': 12})
generator.action_apply()
prev_year_generator = generator.create({
'date_start': '%s-01-01' % (datetime.now().year - 1),
'name_prefix': '%s-' % (datetime.now().year - 1),
'type_id': self.range_type.id,
'duration_count': 1,
'unit_of_time': MONTHLY,
'count': 12})
prev_year_generator.action_apply()
self.tax_model = self.env['account.tax']
self.account_model = self.env['account.account']
self.term_model = self.env['account.payment.term']
Expand All @@ -34,6 +42,11 @@ def setUp(self):
('date_start', '<=', today),
('date_end', '>=', today)
])
self.last_year_date = date(today.year - 1, today.month, today.day)
self.last_year_period = self.env['date.range'].search([
('date_start', '<=', self.last_year_date),
('date_end', '>=', self.last_year_date)
])
self.vat_statement_model = self.env['account.vat.period.end.statement']
paid_vat_account = self.env['account.account'].search([
(
Expand All @@ -42,7 +55,7 @@ def setUp(self):
'account.data_account_type_current_assets').id
)
], limit=1).id
received_vat_account = self.env['account.account'].search([
self.received_vat_account = self.env['account.account'].search([
(
'user_type_id', '=',
self.env.ref(
Expand All @@ -55,12 +68,15 @@ def setUp(self):
self.recent_date = self.invoice_model.search(
[('date_invoice', '!=', False)], order='date_invoice desc',
limit=1).date_invoice
self.last_year_recent_date = date(
self.recent_date.year - 1, self.recent_date.month,
self.recent_date.day)

self.account_tax_22 = self.tax_model.create({
'name': '22%',
'amount': 22,
'amount_type': 'percent',
'vat_statement_account_id': received_vat_account,
'vat_statement_account_id': self.received_vat_account,
'type_tax_use': 'sale',
})
self.account_tax_22_credit = self.tax_model.create({
Expand Down Expand Up @@ -156,14 +172,46 @@ def test_vat_statement(self):
in_invoice.compute_taxes()
in_invoice.action_invoice_open()

last_year_in_invoice = self.invoice_model.create({
'date_invoice': self.last_year_recent_date,
'account_id': in_invoice_account,
'journal_id': self.purchase_journal.id,
'partner_id': self.env.ref('base.res_partner_4').id,
'type': 'in_invoice',
})
self.invoice_line_model.create({
'invoice_id': last_year_in_invoice.id,
'account_id': in_invoice_line_account,
'name': 'service',
'price_unit': 50,
'quantity': 1,
'invoice_line_tax_ids': [(6, 0, [self.account_tax_22_credit.id])],
})
last_year_in_invoice.compute_taxes()
last_year_in_invoice.action_invoice_open()

self.last_year_vat_statement = self.vat_statement_model.create({
'journal_id': self.general_journal.id,
'authority_vat_account_id': self.vat_authority.id,
'payment_term_id': self.account_payment_term.id,
'date': self.last_year_date,
})
self.last_year_period.vat_statement_id = self.last_year_vat_statement
self.last_year_vat_statement.compute_amounts()

self.vat_statement = self.vat_statement_model.create({
'journal_id': self.general_journal.id,
'authority_vat_account_id': self.vat_authority.id,
'payment_term_id': self.account_payment_term.id,
})
self.current_period.vat_statement_id = self.vat_statement
self.vat_statement.compute_amounts()
self.assertEqual(self.vat_statement.authority_vat_amount, 11)
self.vat_statement.previous_credit_vat_account_id = (
self.received_vat_account)

self.assertEqual(self.vat_statement.previous_credit_vat_amount, 11)
self.assertTrue(self.vat_statement.previous_year_credit)
self.assertEqual(self.vat_statement.authority_vat_amount, 0)
self.assertEqual(self.vat_statement.deductible_vat_amount, 11)
self.assertEqual(self.vat_statement.residual, 0)
self.assertEqual(
Expand Down
1 change: 1 addition & 0 deletions account_vat_period_end_statement/views/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<separator colspan="3" string="Previous Credits VAT"/>
<field name="previous_credit_vat_account_id" attrs="{'required':[('previous_credit_vat_amount','!=',0)]}"/>
<field name="previous_credit_vat_amount" nolabel="1"/>
<field name="previous_year_credit" />
<separator colspan="3" string="Previous Debits VAT"/>
<field name="previous_debit_vat_account_id" attrs="{'required':[('previous_debit_vat_amount','!=',0)]}"/>
<field name="previous_debit_vat_amount" nolabel="1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,12 @@ def compute_from_liquidazioni(self):
# credito/debito periodo precedente
quadro.debito_periodo_precedente =\
liq.previous_debit_vat_amount
quadro.credito_periodo_precedente =\
liq.previous_credit_vat_amount
if liq.previous_year_credit:
quadro.credito_anno_precedente =\
liq.previous_credit_vat_amount
else:
quadro.credito_periodo_precedente =\
liq.previous_credit_vat_amount
# Credito anno precedente (NON GESTITO)
# Versamenti auto UE (NON GESTITO)
# Crediti d’imposta (NON GESTITO)
Expand Down