changeset 091d74164946 in modules/account_es:default
details:
https://hg.tryton.org/modules/account_es?cmd=changeset;node=091d74164946
description:
Compute Spanish ECOperation and EC Sales List in company currency
issue9569
review314211002
diffstat:
CHANGELOG | 1 +
reporting_tax.py | 73 ++++++++-----
tests/scenario_reporting_alternate_currency.rst | 121 ++++++++++++++++++++++++
tests/test_account_es.py | 5 +
4 files changed, 171 insertions(+), 29 deletions(-)
diffs (309 lines):
diff -r 370c43645ef4 -r 091d74164946 CHANGELOG
--- a/CHANGELOG Sun Oct 11 23:38:37 2020 +0200
+++ b/CHANGELOG Mon Oct 12 00:25:00 2020 +0200
@@ -1,3 +1,4 @@
+* Compute ES VAT List and EC Operation List in company currency
* Link recargo tax with its related VAT taxes
* Add purchase service tax group
diff -r 370c43645ef4 -r 091d74164946 reporting_tax.py
--- a/reporting_tax.py Sun Oct 11 23:38:37 2020 +0200
+++ b/reporting_tax.py Mon Oct 12 00:25:00 2020 +0200
@@ -8,9 +8,9 @@
from operator import attrgetter
from sql import Cast, Null, Literal
-from sql.aggregate import Count, Max, Min, Sum
+from sql.aggregate import Count, Min, Sum
from sql.conditionals import Case
-from sql.functions import Substring, Position, Extract
+from sql.functions import Substring, Position, Extract, CurrentTimestamp
from sql.operators import Exists
from trytond.i18n import gettext
@@ -423,22 +423,29 @@
@classmethod
def table_query(cls):
pool = Pool()
+ Company = pool.get('company.company')
Invoice = pool.get('account.invoice')
InvoiceTax = pool.get('account.invoice.tax')
+ Move = pool.get('account.move')
+ Line = pool.get('account.move.line')
+ TaxLine = pool.get('account.tax.line')
Tax = pool.get('account.tax')
TaxCode = pool.get('account.tax.code')
TaxCodeLine = pool.get('account.tax.code.line')
Date = pool.get('ir.date')
context = Transaction().context
+ company = Company.__table__()
invoice = Invoice.__table__()
cancel_invoice = Invoice.__table__()
- invoice_tax = InvoiceTax.__table__()
+ move = Move.__table__()
+ line = Line.__table__()
+ tax_line = TaxLine.__table__()
tax = Tax.__table__()
tax_code = TaxCode.__table__()
tax_code_line = TaxCodeLine.__table__()
exclude_invoice_tax = InvoiceTax.__table__()
- amount = invoice_tax.base + invoice_tax.amount
+ amount = tax_line.amount
month = Extract('MONTH', invoice.invoice_date)
excluded_taxes = (tax_code_line
@@ -459,18 +466,20 @@
# Use exists to exclude the full invoice when it has multiple taxes
& ~Exists(exclude_invoice_tax.select(
exclude_invoice_tax.invoice,
- where=((exclude_invoice_tax.invoice == invoice_tax.invoice)
+ where=((exclude_invoice_tax.invoice == invoice.id)
& (exclude_invoice_tax.tax.in_(excluded_taxes))))))
- return (invoice_tax
- .join(invoice,
- condition=invoice_tax.invoice == invoice.id)
- .join(tax, condition=invoice_tax.tax == tax.id)
+ return (tax_line
+ .join(tax, condition=tax_line.tax == tax.id)
+ .join(line, condition=tax_line.move_line == line.id)
+ .join(move, condition=line.move == move.id)
+ .join(invoice, condition=invoice.move == move.id)
+ .join(company, condition=company.id == invoice.company)
.select(
- Max(invoice_tax.id).as_('id'),
+ Min(tax_line.id).as_('id'),
Literal(0).as_('create_uid'),
- Min(invoice_tax.create_date).as_('create_date'),
- Literal(0).as_('write_uid'),
- Max(invoice_tax.write_date).as_('write_date'),
+ CurrentTimestamp().as_('create_date'),
+ cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
+ cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
invoice.tax_identifier.as_('company_tax_identifier'),
invoice.party.as_('party'),
invoice.party_tax_identifier.as_('party_tax_identifier'),
@@ -487,14 +496,14 @@
Sum(amount, filter_=(
(month > Literal(9)) & (month <= Literal(12)))).as_(
'fourth_period_amount'),
- invoice.currency.as_('currency'),
+ company.currency.as_('currency'),
where=where,
group_by=[
invoice.tax_identifier,
invoice.type,
invoice.party,
invoice.party_tax_identifier,
- invoice.currency,
+ company.currency,
tax.es_vat_list_code,
]))
@@ -558,15 +567,19 @@
@classmethod
def table_query(cls):
pool = Pool()
+ Company = pool.get('company.company')
Invoice = pool.get('account.invoice')
- InvoiceTax = pool.get('account.invoice.tax')
Move = pool.get('account.move')
+ Line = pool.get('account.move.line')
+ TaxLine = pool.get('account.tax.line')
Period = pool.get('account.period')
Tax = pool.get('account.tax')
context = Transaction().context
+ company = Company.__table__()
invoice = Invoice.__table__()
- invoice_tax = InvoiceTax.__table__()
move = Move.__table__()
+ line = Line.__table__()
+ tax_line = TaxLine.__table__()
period = Period.__table__()
tax = Tax.__table__()
@@ -579,32 +592,34 @@
where &= (move.date <= context.get('end_date'))
where &= ((tax.es_ec_purchases_list_code != Null)
& (tax.es_ec_purchases_list_code != ''))
+ where &= tax_line.type == 'base'
where &= invoice.type == 'in'
- purchases = (invoice_tax
- .join(invoice,
- condition=invoice_tax.invoice == invoice.id)
- .join(tax, condition=invoice_tax.tax == tax.id)
- .join(move, condition=invoice.move == move.id)
+ purchases = (tax_line
+ .join(tax, condition=tax_line.tax == tax.id)
+ .join(line, condition=tax_line.move_line == line.id)
+ .join(move, condition=line.move == move.id)
.join(period, condition=move.period == period.id)
+ .join(invoice, condition=invoice.move == move.id)
+ .join(company, condition=company.id == invoice.company)
.select(
- Max(invoice_tax.id).as_('id'),
+ Min(tax_line.id).as_('id'),
Literal(0).as_('create_uid'),
- Min(invoice_tax.create_date).as_('create_date'),
- Literal(0).as_('write_uid'),
- Max(invoice_tax.write_date).as_('write_date'),
+ CurrentTimestamp().as_('create_date'),
+ cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
+ cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
invoice.tax_identifier.as_('company_tax_identifier'),
invoice.party.as_('party'),
invoice.party_tax_identifier.as_('party_tax_identifier'),
tax.es_ec_purchases_list_code.as_('code'),
- Sum(invoice_tax.base).as_('amount'),
- invoice.currency.as_('currency'),
+ Sum(tax_line.amount).as_('amount'),
+ company.currency.as_('currency'),
where=where,
group_by=[
invoice.tax_identifier,
invoice.party,
invoice.party_tax_identifier,
tax.es_ec_purchases_list_code,
- invoice.currency,
+ company.currency,
]))
return sales | purchases
diff -r 370c43645ef4 -r 091d74164946
tests/scenario_reporting_alternate_currency.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_reporting_alternate_currency.rst Mon Oct 12 00:25:00
2020 +0200
@@ -0,0 +1,121 @@
+================================================
+Account ES Reporting Alternate Currency Scenario
+================================================
+
+Imports::
+
+ >>> import datetime
+ >>> from decimal import Decimal
+ >>> from proteus import Model
+ >>> from trytond.tests.tools import activate_modules
+ >>> from trytond.modules.currency.tests.tools import get_currency
+ >>> from trytond.modules.company.tests.tools import create_company, \
+ ... get_company
+ >>> from trytond.modules.account.tests.tools import (
+ ... create_chart, get_accounts, create_fiscalyear)
+ >>> from trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
+ >>> today = datetime.date.today()
+
+Activate modules::
+
+ >>> config = activate_modules('account_es')
+
+Create company::
+
+ >>> currency = get_currency('USD')
+ >>> eur = get_currency('EUR')
+ >>> _ = create_company(currency=currency)
+ >>> company = get_company()
+
+Create fiscal year::
+
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+
+Create chart of accounts::
+
+ >>> _ = create_chart(company, 'account_es.pgc_0_pyme')
+ >>> accounts = get_accounts(company)
+ >>> expense = accounts['expense']
+ >>> revenue = accounts['revenue']
+
+Create parties::
+
+ >>> Party = Model.get('party.party')
+ >>> TaxRule = Model.get('account.tax.rule')
+ >>> party = Party(name='Party')
+ >>> tax_identifier = party.identifiers.new()
+ >>> tax_identifier.type = 'eu_vat'
+ >>> tax_identifier.code = 'ES00000000T'
+ >>> party.es_province_code = '25'
+ >>> party.save()
+ >>> supplier = Party(name='Intracomunitary Supplier')
+ >>> supplier.save()
+
+Create invoices::
+
+ >>> Tax = Model.get('account.tax')
+ >>> customer_tax, = Tax.find([
+ ... ('company', '=', company.id),
+ ... ('group.kind', '=', 'sale'),
+ ... ('name', '=', 'IVA 21% (bienes)'),
+ ... ])
+ >>> supplier_tax, = Tax.find([
+ ... ('company', '=', company.id),
+ ... ('group.kind', '=', 'purchase'),
+ ... ('name', '=', 'IVA Intracomunitario (bienes)'),
+ ... ])
+ >>> Invoice = Model.get('account.invoice')
+ >>> invoice = Invoice()
+ >>> invoice.party = party
+ >>> invoice.invoice_date = today
+ >>> invoice.currency = eur
+ >>> line = invoice.lines.new()
+ >>> line.account = revenue
+ >>> line.taxes.append(customer_tax)
+ >>> line.quantity = 5
+ >>> line.unit_price = Decimal('40')
+ >>> invoice.click('post')
+ >>> invoice.total_amount
+ Decimal('242.00')
+ >>> invoice = Invoice()
+ >>> invoice.type = 'in'
+ >>> invoice.party = supplier
+ >>> invoice.currency = eur
+ >>> invoice.invoice_date = today
+ >>> line = invoice.lines.new()
+ >>> line.account = expense
+ >>> line.taxes.append(supplier_tax)
+ >>> line.quantity = 5
+ >>> line.unit_price = Decimal('20')
+ >>> invoice.click('post')
+ >>> invoice.total_amount
+ Decimal('100.00')
+
+EC Operation and VATList report uses company currency::
+
+ >>> VatList = Model.get('account.reporting.vat_list_es')
+ >>> context = {
+ ... 'company': company.id,
+ ... 'date': today,
+ ... }
+ >>> with config.set_context(context):
+ ... record, = VatList.find([])
+ >>> record.party == party
+ True
+ >>> record.amount == Decimal('121.00')
+ True
+ >>> ECOperationList = Model.get('account.reporting.es_ec_operation_list')
+ >>> context = {
+ ... 'company': company.id,
+ ... 'start_date': today,
+ ... 'end_date': today,
+ ... }
+ >>> with config.set_context(context):
+ ... record, = ECOperationList.find([])
+ >>> record.party == supplier
+ True
+ >>> record.amount == Decimal('50.00')
+ True
diff -r 370c43645ef4 -r 091d74164946 tests/test_account_es.py
--- a/tests/test_account_es.py Sun Oct 11 23:38:37 2020 +0200
+++ b/tests/test_account_es.py Mon Oct 12 00:25:00 2020 +0200
@@ -32,4 +32,9 @@
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+ suite.addTests(doctest.DocFileSuite(
+ 'scenario_reporting_alternate_currency.rst',
+ tearDown=doctest_teardown, encoding='utf-8',
+ checker=doctest_checker,
+ optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite