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

[11.0][IMP] l10n_nl_tax_statement: display detailed move lines #212

Merged
merged 1 commit into from
Jan 28, 2019
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
6 changes: 3 additions & 3 deletions l10n_nl_tax_statement/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Netherlands BTW Statement',
'version': '11.0.2.0.0',
'version': '11.0.2.1.0',
'category': 'Localization',
'license': 'AGPL-3',
'author': 'Onestein, Odoo Community Association (OCA)',
Expand Down
24 changes: 24 additions & 0 deletions l10n_nl_tax_statement/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,27 @@ def _get_move_line_tax_date_range_domain(self, from_date):
('date', '>=', unreported_date),
]
return res

def get_balance_domain(self, state_list, type_list):
res = super().get_balance_domain(state_list, type_list)
tax_ids = self.env.context.get('l10n_nl_statement_tax_ids')
if tax_ids:
for item in res:
if item[0] == 'tax_line_id':
res.remove(item)
res.append(
('tax_line_id', 'in', tax_ids)
)
return res

def get_base_balance_domain(self, state_list, type_list):
res = super().get_base_balance_domain(state_list, type_list)
tax_ids = self.env.context.get('l10n_nl_statement_tax_ids')
if tax_ids:
for item in res:
if item[0] == 'tax_ids':
res.remove(item)
res.append(
('tax_ids', 'in', tax_ids)
)
return res
17 changes: 9 additions & 8 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime
from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -348,8 +348,9 @@ def statement_update(self):

# calculate lines
lines = self._prepare_lines()
self._compute_lines(lines)
self._compute_past_invoices_lines(lines)
taxes = self._compute_taxes()
taxes |= self._compute_past_invoices_taxes()
self._set_statement_lines(lines, taxes)
self._finalize_lines(lines)

# create lines
Expand All @@ -360,7 +361,7 @@ def statement_update(self):
)
self.date_update = fields.Datetime.now()

def _compute_past_invoices_lines(self, lines):
def _compute_past_invoices_taxes(self):
self.ensure_one()
ctx = {
'from_date': self.from_date,
Expand All @@ -377,9 +378,9 @@ def _compute_past_invoices_lines(self, lines):
if move_line.tax_exigible:
if move_line.tax_line_id:
taxes |= move_line.tax_line_id
self._set_statement_lines(lines, taxes)
return taxes

def _compute_lines(self, lines):
def _compute_taxes(self):
self.ensure_one()
ctx = {
'from_date': self.from_date,
Expand All @@ -389,7 +390,7 @@ def _compute_lines(self, lines):
}
domain = self._get_taxes_domain()
taxes = self.env['account.tax'].with_context(ctx).search(domain)
self._set_statement_lines(lines, taxes)
return taxes

def _set_statement_lines(self, lines, taxes):
self.ensure_one()
Expand Down
74 changes: 72 additions & 2 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2017 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2017 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.osv import expression
from odoo.exceptions import UserError
from odoo.tools.misc import formatLang

Expand All @@ -27,6 +28,10 @@
'5d', '5e', '5f'
)

TOTAL_DISPLAY = (
'5a', '5c', '5d', '5e', '5f'
)


class VatStatementLine(models.Model):
_name = 'l10n.nl.vat.statement.line'
Expand All @@ -52,6 +57,7 @@ class VatStatementLine(models.Model):
format_btw = fields.Char(compute='_compute_amount_format')

is_group = fields.Boolean(compute='_compute_is_group')
is_total = fields.Boolean(compute='_compute_is_group')
is_readonly = fields.Boolean(compute='_compute_is_readonly')

@api.multi
Expand All @@ -70,6 +76,7 @@ def _compute_amount_format(self):
def _compute_is_group(self):
for line in self:
line.is_group = line.code in GROUP_DISPLAY
line.is_total = line.code in TOTAL_DISPLAY

@api.multi
@api.depends('code')
Expand All @@ -91,3 +98,66 @@ def unlink(self):
raise UserError(
_('You cannot delete lines of a statement set as final!'))
super(VatStatementLine, self).unlink()

@api.multi
def view_tax_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax')

@api.multi
def view_base_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base')

def get_lines_action(self, tax_or_base='tax'):
self.ensure_one()
action = self.env.ref('account.action_account_moves_all_tree')
vals = action.read()[0]
vals['context'] = {}
vals['domain'] = self._get_move_lines_domain(tax_or_base)
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)
else:
domain = self._get_move_lines_domain_posted(tax_or_base)
return domain

def _get_taxes_by_code(self):
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

def _get_move_lines_domain_draft(self, 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,
}
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):
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)]
else:
tax_domain = [('tax_ids', '=', taxes.ids)]
return expression.AND([domain, tax_domain])
6 changes: 6 additions & 0 deletions l10n_nl_tax_statement/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
11.0.2.1.0
~~~~~~~~~~

* Added new feature: allow to see the list of movements from selected lines
https://github.com/OCA/l10n-netherlands/pull/212

11.0.2.0.0
~~~~~~~~~~

Expand Down
Loading