From b2eca90671e7e4e7175466fd01c000ce40618f9e Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sun, 12 Apr 2020 22:08:49 +0200 Subject: [PATCH] Use date filter in Spanish EC Operation list issue9198 review313171002 --- CHANGELOG | 1 + reporting_tax.py | 66 +++++++++++++++------- tests/349.txt | 2 +- tests/scenario_reporting.rst | 3 +- view/es_ec_operation_list_context_form.xml | 8 +-- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0d10517064..d2ef3127a0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Use date filter in Spanish EC Operation list * Add Regimen especial agricultura, ganaderia y pesca tax rules * Allow requests for advancements on SEPA payments * Exclude taxes from other reports on Spanish VAT List diff --git a/reporting_tax.py b/reporting_tax.py index 38a46df49a..08a2c37981 100644 --- a/reporting_tax.py +++ b/reporting_tax.py @@ -1,7 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import unicodedata + from collections import defaultdict +from dateutil.relativedelta import relativedelta from decimal import Decimal from operator import attrgetter @@ -15,7 +17,7 @@ from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, fields from trytond.model.modelsql import convert_from from trytond.pool import Pool -from trytond.pyson import Eval +from trytond.pyson import Eval, If from trytond.report import Report from trytond.transaction import Transaction from trytond.wizard import Wizard, StateView, StateTransition, StateReport, \ @@ -570,10 +572,11 @@ class ECOperationList(ECSalesList): sales = super().table_query() - where = ((invoice.company == context.get('company')) - & (period.fiscalyear == context.get('fiscalyear'))) - if context.get('period'): - where &= (period.id == context.get('period')) + where = invoice.company == context.get('company') + if context.get('start_date'): + where &= (move.date >= context.get('start_date')) + if context.get('end_date'): + where &= (move.date <= context.get('end_date')) where &= ((tax.es_ec_purchases_list_code != Null) & (tax.es_ec_purchases_list_code != '')) where &= invoice.type == 'in' @@ -610,6 +613,35 @@ class ECOperationListContext(ECSalesListContext): "EC Operation List Context" __name__ = 'account.reporting.es_ec_operation_list.context' + start_date = fields.Date("Start Date", + domain=[ + If(Eval('end_date'), + ('start_date', '<=', Eval('end_date')), + (), + ), + ], + depends=['end_date']) + end_date = fields.Date("End Date", + domain=[ + If(Eval('start_date'), + ('end_date', '>=', Eval('start_date')), + (), + ), + ], + depends=['start_date']) + + @classmethod + def default_start_date(cls): + pool = Pool() + Date = pool.get('ir.date') + return Date.today() - relativedelta(months=1, day=1) + + @classmethod + def default_end_date(cls): + pool = Pool() + Date = pool.get('ir.date') + return Date.today() - relativedelta(months=1, day=31) + class AEAT349(Report): __name__ = 'account.reporting.aeat349' @@ -617,27 +649,23 @@ class AEAT349(Report): @classmethod def get_context(cls, records, data): pool = Pool() - Period = pool.get('account.period') - Fiscalyear = pool.get('account.fiscalyear') + Company = pool.get('company.company') t_context = Transaction().context context = super().get_context(records, data) - fiscalyear = Fiscalyear(t_context['fiscalyear']) - context['year'] = str(fiscalyear.start_date.year) - context['company'] = fiscalyear.company + context['company'] = Company(t_context['company']) context['records_amount'] = sum( (r.amount for r in records), Decimal(0)) - period_id = t_context.get('period') - if not period_id: - # Yearly - context['period'] = '0A' - context['period_number'] = '99' - else: - period = Period(period_id) - start_month = period.start_date.month - end_month = period.end_date.month + start_date = t_context.get('start_date') + end_date = t_context.get('end_date') + if start_date or end_date: + date = start_date or end_date + context['year'] = str(date.year) + if start_date and end_date: + start_month = start_date.month + end_month = end_date.month if end_month - start_month > 0: context['period'] = str(end_month // 3) + 'T' context['period_number'] = str(20 + (end_month // 3)) diff --git a/tests/349.txt b/tests/349.txt index 9a771350e5..441e54aad6 100644 --- a/tests/349.txt +++ b/tests/349.txt @@ -1,2 +1,2 @@ -13492018B01000009DUNDER MIFFLIN T000000000 3492018990001 00000000000000A000000001000000000010000000000000000000000000015 +13492018B01000009DUNDER MIFFLIN T000000000 3492018010001 000000000000001000000001000000000010000000000000000000000000015 23492018B01000009 BE0897290877 INTRACOMUNITARY SUPPLIER A0000000010000 diff --git a/tests/scenario_reporting.rst b/tests/scenario_reporting.rst index ffb9612f1d..17a5126ec1 100644 --- a/tests/scenario_reporting.rst +++ b/tests/scenario_reporting.rst @@ -218,7 +218,8 @@ Generate aeat reports:: >>> ECOperationList = Model.get('account.reporting.es_ec_operation_list') >>> context = { ... 'company': company.id, - ... 'fiscalyear': fiscalyear.id, + ... 'start_date': period.start_date, + ... 'end_date': period.end_date, ... } >>> with config.set_context(context): ... records = ECOperationList.find([]) diff --git a/view/es_ec_operation_list_context_form.xml b/view/es_ec_operation_list_context_form.xml index 09174f09b5..797162ea54 100644 --- a/view/es_ec_operation_list_context_form.xml +++ b/view/es_ec_operation_list_context_form.xml @@ -5,8 +5,8 @@ this repository contains the full copyright notices and license terms. -->