Skip to content

Commit

Permalink
[FIX] Include past invoices in report
Browse files Browse the repository at this point in the history
View past invoices moves when country is not NL

[FIX] Sort past invoices by date

[FIX] Domain condition

Update roadmap
  • Loading branch information
astirpe committed Jul 31, 2019
1 parent 83ed91a commit 1c38c60
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion l10n_nl_tax_statement/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Netherlands BTW Statement',
'version': '11.0.2.1.0',
'version': '11.0.2.1.1',
'category': 'Localization',
'license': 'AGPL-3',
'author': 'Onestein, Odoo Community Association (OCA)',
Expand Down
5 changes: 3 additions & 2 deletions l10n_nl_tax_statement/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def get_move_line_partial_domain(self, from_date, to_date, company_id):
if not self.env.context.get('skip_invoice_basis_domain'):
return res

company = self.env['res.company'].browse(company_id)
if company.country_id != self.env.ref('base.nl'):
if not self.env.context.get('unreported_move'):
return res

# Both 'skip_invoice_basis_domain' and 'unreported_move' must be set
# in context, in order to get the domain for the unreported invoices
return expression.AND([
[('company_id', '=', company_id)],
[('l10n_nl_vat_statement_id', '=', False)],
Expand Down
28 changes: 18 additions & 10 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 Onestein (<https://www.onestein.eu>)
# Copyright 2017-2019 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime
Expand Down Expand Up @@ -79,8 +79,9 @@ class VatStatement(models.Model):
def _compute_unreported_move_ids(self):
for statement in self:
domain = statement._get_unreported_move_domain()
move_line_ids = self.env['account.move.line'].search(domain)
statement.unreported_move_ids = move_line_ids.mapped('move_id')
move_lines = self.env['account.move.line'].search(domain)
moves = move_lines.mapped('move_id').sorted('date')
statement.unreported_move_ids = moves

@api.multi
def _get_unreported_move_domain(self):
Expand Down Expand Up @@ -349,7 +350,8 @@ def statement_update(self):
# calculate lines
lines = self._prepare_lines()
taxes = self._compute_taxes()
taxes |= self._compute_past_invoices_taxes()
self._set_statement_lines(lines, taxes)
taxes = self._compute_past_invoices_taxes()
self._set_statement_lines(lines, taxes)
self._finalize_lines(lines)

Expand All @@ -369,15 +371,19 @@ def _compute_past_invoices_taxes(self):
'target_move': self.target_move,
'company_id': self.company_id.id,
'skip_invoice_basis_domain': True,
'unreported_move': True,
'is_invoice_basis': self.is_invoice_basis,
'unreported_move_from_date': self.unreported_move_from_date
}
taxes = self.env['account.tax'].with_context(ctx)
for move in self.unreported_move_ids:
for move_line in move.line_ids:
if move_line.tax_exigible:
if move_line.tax_line_id:
taxes |= move_line.tax_line_id
moves_to_include = self.unreported_move_ids.filtered(
lambda m: m.l10n_nl_vat_statement_include)
for move_line in moves_to_include.mapped('line_ids'):
if move_line.tax_exigible:
if move_line.tax_line_id:
taxes |= move_line.tax_line_id
if move_line.tax_ids:
taxes |= move_line.tax_ids
return taxes

def _compute_taxes(self):
Expand Down Expand Up @@ -432,7 +438,9 @@ def post(self):
'state': 'posted',
'date_posted': fields.Datetime.now()
})
self.unreported_move_ids.write({
self.unreported_move_ids.filtered(
lambda m: m.l10n_nl_vat_statement_include
).write({
'l10n_nl_vat_statement_id': self.id,
})
domain = [
Expand Down
47 changes: 24 additions & 23 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,46 +118,47 @@ def get_lines_action(self, tax_or_base='tax'):
return vals

def _get_move_lines_domain(self, tax_or_base):
if self.statement_id.state == 'draft':
domain = self._get_move_lines_domain_draft(tax_or_base)
statement = self.statement_id
taxes = self._filter_taxes_by_code(statement._compute_taxes())
past_taxes = statement._compute_past_invoices_taxes()
past_taxes = self._filter_taxes_by_code(past_taxes)
if statement.state == 'draft':
domain = self._get_domain_draft(taxes, tax_or_base)
past_domain = self._get_domain_draft(past_taxes, tax_or_base)
else:
domain = self._get_move_lines_domain_posted(tax_or_base)
return domain

def _get_taxes_by_code(self):
domain = self._get_domain_posted(taxes, tax_or_base)
past_domain = self._get_domain_posted(past_taxes, tax_or_base)
curr_amls = self.env['account.move.line'].search(domain)
past_amls = self.env['account.move.line'].search(past_domain)
res = [('id', 'in', past_amls.ids + curr_amls.ids)]
return res

def _filter_taxes_by_code(self, taxes):
self.ensure_one()
tags_map = self.statement_id._get_tags_map()
filtered_taxes = self.env['account.tax']
taxes = self.statement_id._compute_taxes()
taxes |= self.statement_id._compute_past_invoices_taxes()
for tax in taxes:
for tag in tax.tag_ids:
tag_map = tags_map.get(tag.id)
if tag_map and tag_map[0] == self.code:
filtered_taxes |= tax
return filtered_taxes
return filtered_taxes.with_context(taxes.env.context)

def _get_move_lines_domain_draft(self, tax_or_base):
def _get_domain_draft(self, taxes, tax_or_base):
self.ensure_one()
taxes = self._get_taxes_by_code()
statement = self.statement_id
ctx = {
'from_date': statement.from_date,
'to_date': statement.to_date,
'target_move': statement.target_move,
'company_id': statement.company_id.id,
'l10n_nl_statement_tax_ids': taxes.ids,
}
ctx = taxes.env.context.copy()
ctx.update({
'l10n_nl_statement_tax_ids': taxes.ids
})
AccountTax = self.env['account.tax'].with_context(ctx)
return AccountTax.get_move_lines_domain(tax_or_base=tax_or_base)

def _get_move_lines_domain_posted(self, tax_or_base):
def _get_domain_posted(self, taxes, tax_or_base):
self.ensure_one()
taxes = self._get_taxes_by_code()
statement = self.statement_id
domain = [('move_id.l10n_nl_vat_statement_id', '=', statement.id)]
if tax_or_base == 'tax':
tax_domain = [('tax_line_id', '=', taxes.ids)]
tax_domain = [('tax_line_id', 'in', taxes.ids)]
else:
tax_domain = [('tax_ids', '=', taxes.ids)]
tax_domain = [('tax_ids', 'in', taxes.ids)]
return expression.AND([domain, tax_domain])
3 changes: 3 additions & 0 deletions l10n_nl_tax_statement/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* Exporting in SBR/XBLR format not yet available
* Limit invoices to last 5 year based on fiscal year end date (legal requirement)
* When adding invoices automatically recalculate the tax statement (now a manual recalculate is necessary)
* The unreported from date is calculate as 1 quarter, it should take 1 fiscal year based on fiscal year end date

0 comments on commit 1c38c60

Please sign in to comment.