Skip to content

Commit

Permalink
Merge e6100a4 into 6901d5d
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Jul 29, 2019
2 parents 6901d5d + e6100a4 commit 799f52d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 68 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': '12.0.1.0.0',
'version': '12.0.1.0.1',
'category': 'Localization',
'license': 'AGPL-3',
'author': 'Onestein, Odoo Community Association (OCA)',
Expand Down
19 changes: 13 additions & 6 deletions l10n_nl_tax_statement/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ class AccountMove(models.Model):
'Include in VAT Statement'
)

def add_move_in_statement(self):
for move in self:
move.l10n_nl_vat_statement_include = True
def l10n_nl_add_move_in_statement(self):
self.write({'l10n_nl_vat_statement_include': True})
self._l10n_nl_statement_update()

def unlink_move_from_statement(self):
for move in self:
move.l10n_nl_vat_statement_include = False
def l10n_nl_unlink_move_from_statement(self):
self.write({'l10n_nl_vat_statement_include': False})
self._l10n_nl_statement_update()

def _l10n_nl_statement_update(self):
model = self.env.context.get('params', {}).get('model', '')
obj_id = self.env.context.get('params', {}).get('id')
if model == 'l10n.nl.vat.statement' and isinstance(obj_id, int):
statement = self.env['l10n.nl.vat.statement'].browse(obj_id)
statement.statement_update()
7 changes: 4 additions & 3 deletions l10n_nl_tax_statement/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AccountTax(models.Model):
_inherit = 'account.tax'

def get_move_line_partial_domain(self, from_date, to_date, company_id):
res = super(AccountTax, self).get_move_line_partial_domain(
res = super().get_move_line_partial_domain(
from_date,
to_date,
company_id
Expand All @@ -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
39 changes: 20 additions & 19 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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 @@ -152,7 +153,7 @@ def _compute_amount_format_btw_total(self):

@api.model
def default_get(self, fields_list):
defaults = super(VatStatement, self).default_get(fields_list)
defaults = super().default_get(fields_list)
company = self.env.user.company_id
fy_dates = company.compute_fiscalyear_dates(datetime.now())
from_date = fields.Date.to_string(fy_dates['date_from'])
Expand Down Expand Up @@ -339,25 +340,23 @@ def statement_update(self):
self.ensure_one()

if self.state in ['posted', 'final']:
raise UserError(
_('You cannot modify a posted statement!'))
raise UserError(_('You cannot modify a posted statement!'))

# clean old lines
self.line_ids.unlink()

# 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)

# create lines
for line in lines:
lines[line].update({'statement_id': self.id})
self.env['l10n.nl.vat.statement.line'].create(
lines[line]
)
self.env['l10n.nl.vat.statement.line'].create(lines[line])
self.date_update = fields.Datetime.now()

def _compute_past_invoices_taxes(self):
Expand All @@ -368,15 +367,16 @@ 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
move_lines = self.unreported_move_ids.mapped('line_ids').filtered(
lambda m: m.l10n_nl_vat_statement_include)
for move_line in move_lines:
if move_line.tax_exigible and move_line.tax_line_id:
taxes |= move_line.tax_line_id
return taxes

def _compute_taxes(self):
Expand All @@ -398,8 +398,7 @@ def _set_statement_lines(self, lines, taxes):
for tag in tax.tag_ids:
tag_map = tags_map.get(tag.id)
if tag_map:
column = tag_map[1]
code = tag_map[0]
code, column = tag_map
if column == 'omzet':
lines[code][column] += tax.base_balance
else:
Expand Down Expand Up @@ -431,7 +430,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 Expand Up @@ -493,7 +494,7 @@ def write(self, values):
raise UserError(
_('You cannot modify a posted statement! '
'Reset the statement to draft first.'))
return super(VatStatement, self).write(values)
return super().write(values)

@api.multi
def unlink(self):
Expand All @@ -505,7 +506,7 @@ def unlink(self):
if statement.state == 'final':
raise UserError(
_('You cannot delete a statement set as final!'))
super(VatStatement, self).unlink()
super().unlink()

@api.depends('line_ids.btw')
def _compute_btw_total(self):
Expand Down
51 changes: 26 additions & 25 deletions l10n_nl_tax_statement/models/l10n_nl_vat_statement_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2018 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 odoo import _, api, fields, models
Expand Down Expand Up @@ -97,7 +97,7 @@ def unlink(self):
if line.statement_id.state == 'final':
raise UserError(
_('You cannot delete lines of a statement set as final!'))
super(VatStatementLine, self).unlink()
super().unlink()

@api.multi
def view_tax_lines(self):
Expand All @@ -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])
2 changes: 2 additions & 0 deletions l10n_nl_tax_statement/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* Exporting in SBR/XBLR format not yet available
* Limit invoices to last 5 year based on fiscal year end date (legal requirement)
* The unreported from date is calculate as 1 quarter, it should take 1 fiscal year based on fiscal year end date
16 changes: 11 additions & 5 deletions l10n_nl_tax_statement/tests/test_l10n_nl_vat_statement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2018 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).

import datetime
Expand Down Expand Up @@ -299,14 +299,20 @@ def test_11_wizard_execute(self):
def test_12_undeclared_invoice(self):
self.invoice_1._onchange_invoice_line_ids()
self.invoice_1.action_invoice_open()
self.invoice_1.move_id.add_move_in_statement()
move = self.invoice_1.move_id
move.with_context(params={
'model': 'l10n.nl.vat.statement',
'id': self.statement_1.id
}).l10n_nl_add_move_in_statement()
for line in self.invoice_1.move_id.line_ids:
self.assertTrue(line.l10n_nl_vat_statement_include)
self.invoice_1.move_id.unlink_move_from_statement()
move.with_context(params={
'model': 'l10n.nl.vat.statement',
'id': self.statement_1.id
}).l10n_nl_unlink_move_from_statement()
for line in self.invoice_1.move_id.line_ids:
self.assertFalse(line.l10n_nl_vat_statement_include)

self.statement_1.statement_update()
self.assertEqual(len(self.statement_1.line_ids.ids), 22)

for line in self.statement_1.line_ids:
Expand Down Expand Up @@ -403,7 +409,7 @@ def test_15_invoice_basis_undeclared_invoice(self):
self.statement_1.company_id.country_id = self.env.ref('base.nl')

invoice2 = self.invoice_1.copy()
old_date = fields.Date.today() + relativedelta(months=-4, day=1)
old_date = fields.Date.from_string('2018-12-07')
invoice2.date_invoice = old_date
invoice2.action_invoice_open()

Expand Down
8 changes: 2 additions & 6 deletions l10n_nl_tax_statement/views/l10n_nl_vat_statement_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@
</group>
<group>
</group>
<div>Add/Remove the Undeclared Invoices listed below. Afterwards press the Update button in order to recompute the statement lines!</div>
<div class="oe_button_box" name="button_box">
<button name="statement_update" string="Update" states="draft" type="object" class="oe_stat_button" icon="fa-repeat"/>
</div>
</group>
<field name="unreported_move_ids">
<tree editable="bottom" create="false" delete="false" decoration-muted="l10n_nl_vat_statement_include != True">
Expand All @@ -99,8 +95,8 @@
<field name="partner_id" readonly="1"/>
<field name="amount" readonly="1"/>
<field name="l10n_nl_vat_statement_include" invisible="1"/>
<button name="add_move_in_statement" icon="fa fa-play" string="Add Invoice" type="object" attrs="{'invisible': [('l10n_nl_vat_statement_include', '=', True)]}"/>
<button name="unlink_move_from_statement" icon="fa fa-remove" string="Remove Invoice" type="object" attrs="{'invisible': [('l10n_nl_vat_statement_include', '!=', True)]}"/>
<button name="l10n_nl_add_move_in_statement" icon="fa-play" string="Add Invoice" type="object" attrs="{'invisible': [('l10n_nl_vat_statement_include', '=', True)]}"/>
<button name="l10n_nl_unlink_move_from_statement" icon="fa-remove" string="Remove Invoice" type="object" attrs="{'invisible': [('l10n_nl_vat_statement_include', '!=', True)]}"/>
</tree>
</field>
</page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VatStatementConfigWizard(models.TransientModel):

@api.model
def default_get(self, fields_list):
defv = super(VatStatementConfigWizard, self).default_get(fields_list)
defv = super().default_get(fields_list)

company_id = self.env.user.company_id.id
config = self.env['l10n.nl.vat.statement.config'].search([
Expand Down Expand Up @@ -86,9 +86,9 @@ def default_get(self, fields_list):
return defv

def _is_l10n_nl_coa(self):
is_l10n_nl_coa = self.env.ref('l10n_nl.l10nnl_chart_template', False)
l10n_nl_coa = self.env.ref('l10n_nl.l10nnl_chart_template', False)
company_coa = self.env.user.company_id.chart_template_id
return company_coa == is_l10n_nl_coa
return company_coa == l10n_nl_coa

@api.multi
def execute(self):
Expand Down

0 comments on commit 799f52d

Please sign in to comment.