Skip to content

Commit 4678879

Browse files
committed
[MIG] REF l10n_it_account_vat_period_end_settlement
- Remove vat_statement_account_id - Adapt to reverse charge cases - Fix reconciliation process
1 parent b0d7cee commit 4678879

File tree

11 files changed

+104
-91
lines changed

11 files changed

+104
-91
lines changed

l10n_it_account_vat_period_end_settlement/README.rst

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ Configuration
108108
- data iniziale: primo giorno del primo periodo che sarà generato
109109
(tipicamente il primo giorno dell'anno i.e. 01/01/2018)
110110

111-
Per caricare l'importo corretto, un'imposta deve essere associata al
112-
conto utilizzato nella liquidazione:
111+
Per escludere un'imposta dalla liquidazione IVA:
113112

114113
1. aprire l'imposta da Fatturazione > Configurazione > Contabilità >
115114
Imposte,
116-
2. nella scheda 'Opzioni avanzate' selezionare il conto corretto (ad
117-
esempio IVA debito) per il campo 'Conto utilizzato per la
118-
liquidazione IVA'.
115+
2. nella scheda 'Opzioni avanzate' impostare 'Escludere da
116+
liquidazioni IVA'.
119117

120118
Per calcolare gli interessi, è possibile aggiungere le informazioni
121119
da utilizzare (conto e percentuale) nei dati aziendali, nella scheda
@@ -136,13 +134,10 @@ Configuration
136134
- date start: first day of the first period to be generated (usually
137135
the first day of the year e.g. 01/01/2018)
138136

139-
In order to load the correct amount from tax, the tax has to be
140-
associated to the account involved in the Settlement:
137+
In order to exclude a tax from VAT settlement:
141138

142139
1. open a tax in Accounting > Configuration > Accounting > Taxes,
143-
2. in the tab 'Advanced Options' select the correct account (for
144-
instance the account debit VAT) for the field 'Account used for
145-
VAT Settlement'.
140+
2. in the tab 'Advanced Options' set 'Exclude from VAT settlements'.
146141

147142
If you need to calculate interest, you can add default information in
148143
your company data (percentage and account), in the 'VAT Settlement'

l10n_it_account_vat_period_end_settlement/hooks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ def pre_absorb_old_module(env):
1515
],
1616
merge_modules=True,
1717
)
18+
19+
20+
def set_exclude_from_vat_settlements(env):
21+
openupgrade.logged_query(
22+
env.cr,
23+
"""
24+
UPDATE account_tax SET exclude_from_vat_settlement = True
25+
WHERE vat_statement_account_id IS NULL;
26+
""",
27+
)

l10n_it_account_vat_period_end_settlement/migrations/18.0.1.0.0/pre-migrate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from odoo.addons.l10n_it_account_vat_period_end_settlement import hooks
66

77

8-
def migrate(cr, installed_version):
8+
def migrate(env, installed_version):
99
# Used by OpenUpgrade when module is in `apriori`
10-
hooks.migrate_old_module(cr)
10+
hooks.pre_absorb_old_module(env)

l10n_it_account_vat_period_end_settlement/models/account.py

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def _compute_residual(self):
5353
if not statement.move_id.exists():
5454
statement.residual = 0.0
5555
statement.reconciled = False
56+
statement.state = "draft"
5657
continue
5758

5859
residual = 0.0
@@ -63,8 +64,10 @@ def _compute_residual(self):
6364
statement.residual = abs(residual)
6465
if float_is_zero(statement.residual, precision_digits=precision):
6566
statement.reconciled = True
67+
statement.state = "paid"
6668
else:
6769
statement.reconciled = False
70+
statement.state = "confirmed"
6871

6972
@api.depends("move_id.line_ids.amount_residual")
7073
def _compute_lines(self):
@@ -264,9 +267,9 @@ def _get_default_interest_percent(self):
264267
)
265268

266269
def _get_domain_account(self):
267-
domain = [("vat_statement_account_id", "!=", False)]
270+
domain = [("exclude_from_vat_settlements", "=", False)]
268271
tax_ids = self.env["account.tax"].search(domain)
269-
account_ids = tax_ids.mapped("vat_statement_account_id")
272+
account_ids = tax_ids.mapped("repartition_line_ids.account_id")
270273
return [("id", "in", account_ids.ids)]
271274

272275
def unlink(self):
@@ -284,35 +287,13 @@ def set_fiscal_year(self):
284287
date = min([x.date_start for x in statement.date_range_ids])
285288
statement.update({"fiscal_year": date.year})
286289

287-
def _write(self, vals):
288-
pre_not_reconciled = self.filtered(lambda statement: not statement.reconciled)
289-
pre_reconciled = self - pre_not_reconciled
290-
res = super()._write(vals)
291-
reconciled = self.filtered(lambda statement: statement.reconciled)
292-
not_reconciled = self - reconciled
293-
(reconciled & pre_reconciled).filtered(
294-
lambda statement: statement.state == "confirmed"
295-
).statement_paid()
296-
(not_reconciled & pre_not_reconciled).filtered(
297-
lambda statement: statement.state == "paid"
298-
).statement_confirmed()
299-
return res
300-
301290
def statement_draft(self):
302291
for statement in self:
303292
if statement.move_id:
304293
statement.move_id.button_cancel()
305294
statement.move_id.with_context(force_delete=True).unlink()
306295
statement.state = "draft"
307296

308-
def statement_paid(self):
309-
for statement in self:
310-
statement.state = "paid"
311-
312-
def statement_confirmed(self):
313-
for statement in self:
314-
statement.state = "confirmed"
315-
316297
def _prepare_account_move_line(
317298
self, name, account_id, move_id, statement, statement_date, partner_id=False
318299
):
@@ -335,7 +316,7 @@ def create_move(self):
335316
for statement in self:
336317
statement_date = fields.Date.to_string(statement.date)
337318
move_data = {
338-
"name": self.env._("VAT Settlement") + " - " + statement_date,
319+
"ref": self.env._("VAT Settlement") + " - " + statement_date,
339320
"date": statement_date,
340321
"journal_id": statement.journal_id.id,
341322
}
@@ -664,10 +645,31 @@ def _set_debit_lines(self, debit_tax, debit_line_ids, statement):
664645
"to_date": period.date_end,
665646
"registry_type": "customer",
666647
}
667-
)[3] # position 3 is deductible part
648+
)[5] # position 5 is debit balance
649+
debit_account_id = False
650+
if total:
651+
# For 0% taxes, account is not used
652+
debit_accounts = debit_tax._get_debit_accounts()
653+
if not debit_accounts:
654+
raise UserError(
655+
self.env._(
656+
"The tax %s has no debit account defined. "
657+
"Please define it in the tax form."
658+
)
659+
% debit_tax.name
660+
)
661+
if len(debit_accounts) > 1:
662+
raise UserError(
663+
self.env._(
664+
"The tax %s has more than one debit account defined. "
665+
"Please define only one in the tax form."
666+
)
667+
% debit_tax.name
668+
)
669+
debit_account_id = debit_accounts.id
668670
debit_line_ids.append(
669671
{
670-
"account_id": debit_tax.vat_statement_account_id.id,
672+
"account_id": debit_account_id,
671673
"tax_id": debit_tax.id,
672674
"amount": total,
673675
}
@@ -683,9 +685,29 @@ def _set_credit_lines(self, credit_tax, credit_line_ids, statement):
683685
"registry_type": "supplier",
684686
}
685687
)[3] # position 3 is deductible part
688+
credit_account_id = False
689+
if total:
690+
credit_accounts = credit_tax._get_credit_accounts()
691+
if not credit_accounts:
692+
raise UserError(
693+
self.env._(
694+
"The tax %s has no credit account defined. "
695+
"Please define it in the tax form."
696+
)
697+
% credit_tax.name
698+
)
699+
if len(credit_accounts) > 1:
700+
raise UserError(
701+
self.env._(
702+
"The tax %s has more than one credit account defined. "
703+
"Please define only one in the tax form."
704+
)
705+
% credit_tax.name
706+
)
707+
credit_account_id = credit_accounts.id
686708
credit_line_ids.append(
687709
{
688-
"account_id": credit_tax.vat_statement_account_id.id,
710+
"account_id": credit_account_id,
689711
"tax_id": credit_tax.id,
690712
"amount": total,
691713
}
@@ -697,18 +719,24 @@ def _get_credit_debit_lines(self, statement):
697719
tax_model = self.env["account.tax"]
698720
taxes = tax_model.search(
699721
[
700-
("vat_statement_account_id", "!=", False),
722+
("exclude_from_vat_settlements", "=", False),
701723
("type_tax_use", "in", ["sale", "purchase"]),
702724
]
703725
)
704726
for tax in taxes:
705-
if (
706-
tax.vat_statement_account_id.id in statement.account_ids.ids
707-
or not statement.account_ids
708-
):
709-
if tax.type_tax_use == "sale":
727+
debit_accounts = tax._get_debit_accounts()
728+
credit_accounts = tax._get_credit_accounts()
729+
if debit_accounts:
730+
if (
731+
all(debit_accounts.ids) in statement.account_ids.ids
732+
or not statement.account_ids
733+
):
710734
self._set_debit_lines(tax, debit_line_ids, statement)
711-
elif tax.type_tax_use == "purchase":
735+
if credit_accounts:
736+
if (
737+
all(credit_accounts.ids) in statement.account_ids.ids
738+
or not statement.account_ids
739+
):
712740
self._set_credit_lines(tax, credit_line_ids, statement)
713741

714742
return credit_line_ids, debit_line_ids
@@ -741,7 +769,7 @@ class StatementDebitAccountLine(models.Model):
741769
_name = "statement.debit.account.line"
742770
_description = "VAT Settlement debit account line"
743771

744-
account_id = fields.Many2one("account.account", "Account", required=True)
772+
account_id = fields.Many2one("account.account", "Account", required=False)
745773
tax_id = fields.Many2one("account.tax", "Tax", required=True)
746774
statement_id = fields.Many2one("account.vat.period.end.statement", "VAT Settlement")
747775
amount = fields.Float(required=True, digits="Account")
@@ -751,7 +779,7 @@ class StatementCreditAccountLine(models.Model):
751779
_name = "statement.credit.account.line"
752780
_description = "VAT Settlement credit account line"
753781

754-
account_id = fields.Many2one("account.account", "Account", required=True)
782+
account_id = fields.Many2one("account.account", "Account", required=False)
755783
tax_id = fields.Many2one("account.tax", "Tax", required=True)
756784
statement_id = fields.Many2one("account.vat.period.end.statement", "VAT Settlement")
757785
amount = fields.Float(required=True, digits="Account")
@@ -770,13 +798,6 @@ class StatementGenericAccountLine(models.Model):
770798
class AccountTax(models.Model):
771799
_inherit = "account.tax"
772800
exclude_from_vat_settlements = fields.Boolean(string="Exclude from VAT settlements")
773-
vat_statement_account_id = fields.Many2one(
774-
"account.account",
775-
"Account used for VAT Settlement",
776-
help="The tax balance will be "
777-
"associated to this account after selecting the period in "
778-
"VAT Settlement",
779-
)
780801

781802

782803
class DateRange(models.Model):

l10n_it_account_vat_period_end_settlement/models/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class ResCompany(models.Model):
1111
"Interest on End Vat Settlement", help="Apply interest on end vat settlement"
1212
)
1313
of_account_end_vat_statement_interest_percent = fields.Float(
14-
"Interest on End Vat Settlement - %", help="Apply interest on end vat settlement"
14+
"Interest on End Vat Settlement - %",
15+
help="Apply interest on end vat settlement",
1516
)
1617
of_account_end_vat_statement_interest_account_id = fields.Many2one(
1718
"account.account",

l10n_it_account_vat_period_end_settlement/readme/CONFIGURE.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
> - data iniziale: primo giorno del primo periodo che sarà generato
1414
> (tipicamente il primo giorno dell'anno i.e. 01/01/2018)
1515
>
16-
> Per caricare l'importo corretto, un'imposta deve essere associata al
17-
> conto utilizzato nella liquidazione:
16+
> Per escludere un'imposta dalla liquidazione IVA:
1817
>
1918
> 1. aprire l'imposta da Fatturazione \> Configurazione \> Contabilità
2019
> \> Imposte,
21-
> 2. nella scheda 'Opzioni avanzate' selezionare il conto corretto (ad
22-
> esempio IVA debito) per il campo 'Conto utilizzato per la
23-
> liquidazione IVA'.
20+
> 2. nella scheda 'Opzioni avanzate' impostare 'Escludere da liquidazioni IVA'.
2421
>
2522
> Per calcolare gli interessi, è possibile aggiungere le informazioni da
2623
> utilizzare (conto e percentuale) nei dati aziendali, nella scheda
@@ -41,13 +38,10 @@
4138
> - date start: first day of the first period to be generated (usually
4239
> the first day of the year e.g. 01/01/2018)
4340
>
44-
> In order to load the correct amount from tax, the tax has to be
45-
> associated to the account involved in the Settlement:
41+
> In order to exclude a tax from VAT settlement:
4642
>
4743
> 1. open a tax in Accounting \> Configuration \> Accounting \> Taxes,
48-
> 2. in the tab 'Advanced Options' select the correct account (for
49-
> instance the account debit VAT) for the field 'Account used for
50-
> VAT Settlement'.
44+
> 2. in the tab 'Advanced Options' set 'Exclude from VAT settlements'.
5145
>
5246
> If you need to calculate interest, you can add default information in
5347
> your company data (percentage and account), in the 'VAT Settlement'

l10n_it_account_vat_period_end_settlement/report/vat_statement.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def _get_taxes_amounts(self, period_id, tax_ids=None, registry_type="customer"):
4444

4545
for tax_id in tax_ids:
4646
tax = tax_model.browse(tax_id)
47-
tax_name, base, tax_val, deductible, undeductible = tax._compute_totals_tax(
47+
(
48+
tax_name, base, tax_val, deductible, undeductible,
49+
debit_balance, credit_balance
50+
) = tax._compute_totals_tax(
4851
{
4952
"from_date": date_range.date_start,
5053
"to_date": date_range.date_end,

l10n_it_account_vat_period_end_settlement/static/description/index.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,12 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
449449
<li>data iniziale: primo giorno del primo periodo che sarà generato
450450
(tipicamente il primo giorno dell’anno i.e. 01/01/2018)</li>
451451
</ul>
452-
<p>Per caricare l’importo corretto, un’imposta deve essere associata al
453-
conto utilizzato nella liquidazione:</p>
452+
<p>Per escludere un’imposta dalla liquidazione IVA:</p>
454453
<ol class="arabic simple">
455454
<li>aprire l’imposta da Fatturazione &gt; Configurazione &gt; Contabilità &gt;
456455
Imposte,</li>
457-
<li>nella scheda ‘Opzioni avanzate’ selezionare il conto corretto (ad
458-
esempio IVA debito) per il campo ‘Conto utilizzato per la
459-
liquidazione IVA’.</li>
456+
<li>nella scheda ‘Opzioni avanzate’ impostare ‘Escludere da
457+
liquidazioni IVA’.</li>
460458
</ol>
461459
<p>Per calcolare gli interessi, è possibile aggiungere le informazioni
462460
da utilizzare (conto e percentuale) nei dati aziendali, nella scheda
@@ -477,13 +475,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
477475
<li>date start: first day of the first period to be generated (usually
478476
the first day of the year e.g. 01/01/2018)</li>
479477
</ul>
480-
<p>In order to load the correct amount from tax, the tax has to be
481-
associated to the account involved in the Settlement:</p>
478+
<p>In order to exclude a tax from VAT settlement:</p>
482479
<ol class="arabic simple">
483480
<li>open a tax in Accounting &gt; Configuration &gt; Accounting &gt; Taxes,</li>
484-
<li>in the tab ‘Advanced Options’ select the correct account (for
485-
instance the account debit VAT) for the field ‘Account used for
486-
VAT Settlement’.</li>
481+
<li>in the tab ‘Advanced Options’ set ‘Exclude from VAT settlements’.</li>
487482
</ol>
488483
<p>If you need to calculate interest, you can add default information in
489484
your company data (percentage and account), in the ‘VAT Settlement’

l10n_it_account_vat_period_end_settlement/tests/common.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def setUpClass(
101101
"name": "22%",
102102
"amount": 22,
103103
"amount_type": "percent",
104-
"vat_statement_account_id": cls.received_vat_account,
105104
"type_tax_use": "sale",
106105
}
107106
)
@@ -110,7 +109,6 @@ def setUpClass(
110109
"name": "22% credit",
111110
"amount": 22,
112111
"amount_type": "percent",
113-
"vat_statement_account_id": cls.paid_vat_account,
114112
"type_tax_use": "purchase",
115113
}
116114
)

l10n_it_account_vat_period_end_settlement/tests/test_vat_statement.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_different_previous_vat_statements(self):
151151
# selecting two different Accounts
152152
partner = self.env.ref("base.res_partner_4")
153153
tax = self.account_tax_22_credit
154-
tax_statement_account = tax.vat_statement_account_id
154+
tax_statement_account = tax._get_credit_accounts()[0]
155155
last_year_bill = self._create_vendor_bill(
156156
partner,
157157
self.last_year_recent_date,
@@ -169,11 +169,7 @@ def test_different_previous_vat_statements(self):
169169

170170
# Create another Bill and Statement
171171
other_tax_statement_account = tax_statement_account.copy()
172-
other_tax = tax.copy(
173-
default={
174-
"vat_statement_account_id": other_tax_statement_account.id,
175-
},
176-
)
172+
other_tax = tax.copy()
177173
other_last_year_bill = self._create_vendor_bill(
178174
partner,
179175
self.last_year_recent_date,
@@ -269,7 +265,7 @@ def test_report_multiple_payment_info(self):
269265
"""
270266
# Arrange
271267
tax = self.account_tax_22_credit
272-
tax_statement_account = tax.vat_statement_account_id
268+
tax_statement_account = tax._get_credit_accounts()[0]
273269
last_year_bill = self.init_invoice(
274270
"in_invoice",
275271
invoice_date=self.last_year_recent_date,

0 commit comments

Comments
 (0)