Use date filter in Spanish EC Operation list

issue9198
review313171002
This commit is contained in:
Sergi Almacellas Abellana
2020-04-12 22:08:49 +02:00
parent b9a7543db5
commit b2eca90671
5 changed files with 55 additions and 25 deletions
+1
View File
@@ -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
+47 -19
View File
@@ -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))
+1 -1
View File
@@ -1,2 +1,2 @@
13492018B01000009DUNDER MIFFLIN T000000000 3492018990001 00000000000000A000000001000000000010000000000000000000000000015
13492018B01000009DUNDER MIFFLIN T000000000 3492018010001 000000000000001000000001000000000010000000000000000000000000015
23492018B01000009 BE0897290877 INTRACOMUNITARY SUPPLIER A0000000010000
+2 -1
View File
@@ -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([])
+4 -4
View File
@@ -5,8 +5,8 @@ this repository contains the full copyright notices and license terms. -->
<label name="company"/>
<field name="company"/>
<newline/>
<label name="fiscalyear"/>
<field name="fiscalyear"/>
<label name="period"/>
<field name="period"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
</form>