Skip to content

Commit

Permalink
Merge PR #3729 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by SirAionTech
  • Loading branch information
OCA-git-bot committed Jun 19, 2024
2 parents 74eaa64 + dafe472 commit 4469bff
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 10 deletions.
4 changes: 4 additions & 0 deletions account_vat_period_end_statement/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ Contributors

- Simone Rubino <[email protected]>

- `Aion Tech <https://aiontech.company/>`__:

- Simone Rubino <[email protected]>

Maintainers
-----------

Expand Down
48 changes: 40 additions & 8 deletions account_vat_period_end_statement/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2015 Associazione Odoo Italia (<http://www.odoo-italia.org>)
# Copyright 2021 Gianmarco Conte - Dinamiche Aziendali Srl (<www.dinamicheaziendali.it>)
# Copyright 2022 Simone Rubino - TAKOBI
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import math
Expand Down Expand Up @@ -455,6 +456,37 @@ def create_move(self):

return True

def _split_vat_data_payment_term(
self,
payment_term,
move,
statement_date,
end_debit_vat_data,
):
self.ensure_one()
company = self.env.company
currency = company.currency_id
tax_amount = tax_amount_currency = self.authority_vat_amount
untaxed_amount = untaxed_amount_currency = 0
sign = 1 if move.is_inbound(include_receipts=True) else -1
due_list = payment_term._compute_terms(
statement_date,
currency,
company,
tax_amount,
tax_amount_currency,
sign,
untaxed_amount,
untaxed_amount_currency,
)
payment_term_lines = []
for term in due_list:
current_line = end_debit_vat_data.copy()
current_line["credit"] = term["company_amount"]
current_line["date_maturity"] = term["date"]
payment_term_lines.append((0, 0, current_line))
return payment_term_lines

def _add_end_debit_vat_data(self, lines_to_create, move, statement, statement_date):
end_debit_vat_data = self._prepare_account_move_line(
name="Tax Authority VAT",
Expand All @@ -466,15 +498,15 @@ def _add_end_debit_vat_data(self, lines_to_create, move, statement, statement_da
)
if statement.authority_vat_amount > 0:
end_debit_vat_data["credit"] = math.fabs(statement.authority_vat_amount)
if statement.payment_term_id:
due_list = statement.payment_term_id.compute(
statement.authority_vat_amount, statement_date
payment_term = statement.payment_term_id
if payment_term:
payment_term_lines = self._split_vat_data_payment_term(
payment_term,
move,
statement_date,
end_debit_vat_data,
)
for term in due_list:
current_line = end_debit_vat_data
current_line["credit"] = term[1]
current_line["date_maturity"] = term[0]
lines_to_create.append((0, 0, current_line))
lines_to_create.extend(payment_term_lines)
else:
lines_to_create.append((0, 0, end_debit_vat_data))
elif statement.authority_vat_amount < 0:
Expand Down
2 changes: 2 additions & 0 deletions account_vat_period_end_statement/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
- Michele Rusticucci \<<[email protected]>\>
- [TAKOBI](https://takobi.online):
- Simone Rubino \<<[email protected]>\>
- [Aion Tech](https://aiontech.company/):
- Simone Rubino \<<[email protected]>\>
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:sir&#64;takobi.online">sir&#64;takobi.online</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
7 changes: 5 additions & 2 deletions account_vat_period_end_statement/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2015 Agile Business Group <http://www.agilebg.com>
# Copyright 2022 Simone Rubino - TAKOBI
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import date, datetime
Expand Down Expand Up @@ -157,16 +158,18 @@ def _create_vendor_bill(self, partner, invoice_date, price_unit, tax):
bill.action_post()
return bill

def _get_statement(self, period, statement_date, accounts):
def _get_statement(self, period, statement_date, accounts, payment_term=None):
"""
Create a VAT Statement in date `statement_date`
for Period `period` and Accounts `accounts`.
"""
if payment_term is None:
payment_term = self.account_payment_term
# Create statement
statement_form = Form(self.vat_statement_model)
statement_form.journal_id = self.general_journal
statement_form.authority_vat_account_id = self.vat_authority
statement_form.payment_term_id = self.account_payment_term
statement_form.payment_term_id = payment_term
statement_form.date = statement_date
statement_form.account_ids.clear()
for account in accounts:
Expand Down
34 changes: 34 additions & 0 deletions account_vat_period_end_statement/tests/test_vat_statement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2015 Agile Business Group <http://www.agilebg.com>
# Copyright 2022 Simone Rubino - TAKOBI
# Copyright 2023 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields
Expand Down Expand Up @@ -225,3 +226,36 @@ def test_different_previous_vat_statements(self):
other_statement.previous_credit_vat_amount,
-other_last_year_statement.authority_vat_amount,
)

def test_create_move_with_payment_term(self):
"""When there is a payment term, the move can be created."""
# Arrange
date_range = self.current_period
out_invoice = self.init_invoice(
"out_invoice",
invoice_date=self.recent_date,
amounts=[
100,
],
taxes=self.account_tax_22,
post=True,
)
statement = self._get_statement(
date_range,
self.last_year_date,
self.env["account.account"].browse(),
payment_term=self.env.ref("account.account_payment_term_advance_60days"),
)
# pre-condition
self.assertTrue(statement.payment_term_id)
self.assertIn(date_range, statement.date_range_ids)
date_range_domain = date_range.get_domain("invoice_date")
date_range_invoices = self.invoice_model.search(date_range_domain)
self.assertIn(out_invoice, date_range_invoices)

# Act
statement.create_move()

# Assert
move = statement.move_id
self.assertEqual(move.amount_total, 22)

0 comments on commit 4469bff

Please sign in to comment.