diff --git a/CHANGELOG b/CHANGELOG index 0952839ff3..25f5224024 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Add VAT customer list +* Add support for EC Sales List + Version 4.4.0 - 2017-05-01 * Bug fixes (see mercurial logs for details) diff --git a/MANIFEST.in b/MANIFEST.in index f858323ca5..4cf163414d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,4 +5,5 @@ include CHANGELOG include LICENSE include tryton.cfg include *.xml +include view/*.xml include locale/*.po diff --git a/__init__.py b/__init__.py index 6c102cc2ae..ab705ab9b9 100644 --- a/__init__.py +++ b/__init__.py @@ -2,10 +2,12 @@ # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -from .account import * +from . import account def register(): Pool.register( - AccountTemplate, + account.AccountTemplate, + account.BEVATCustomer, + account.BEVATCustomerContext, module='account_be', type_='model') diff --git a/account.py b/account.py index a534d435d8..edb6cc4350 100644 --- a/account.py +++ b/account.py @@ -1,9 +1,13 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from sql import Literal +from sql.aggregate import Max, Min, Sum from sql.operators import Concat from sql.functions import Position +from trytond.model import ModelSQL, ModelView, fields from trytond.pool import Pool, PoolMeta +from trytond.pyson import Eval from trytond.transaction import Transaction __all__ = ['AccountTemplate'] @@ -32,3 +36,121 @@ class AccountTemplate: & (model_data.module == 'account_be')))) super(AccountTemplate, cls).__register__(module_name) + + +class BEVATCustomer(ModelSQL, ModelView): + "Belgium VAT Customer" + __name__ = 'account.be.vat_customer' + + company_tax_identifier = fields.Many2One( + 'party.identifier', "Company Tax Identifier") + party_tax_identifier = fields.Many2One( + 'party.identifier', "Party Tax Identifier") + turnover = fields.Numeric( + "Turnover", digits=(16, Eval('currency_digits', 2)), + depends=['currency_digits']) + vat = fields.Numeric( + "VAT", digits=(16, Eval('currency_digits', 2)), + depends=['currency_digits']) + currency = fields.Many2One('currency.currency', "Currency") + currency_digits = fields.Function( + fields.Integer("Currency Digits"), 'get_currency_digits') + + def get_currency_digits(self, name): + return self.currency.digits + + @classmethod + def tax_groups(cls): + for group in ['group_tva_vente_biens', 'group_tva_vente_services', + 'tva_vente_biens_coco', 'tva_vente_services_coco']: + for lang in ['fr', 'nl']: + yield 'account_be', '%s_%s' % (group, lang) + + @classmethod + def table_query(cls): + pool = Pool() + Identifier = pool.get('party.identifier') + Invoice = pool.get('account.invoice') + InvoiceTax = pool.get('account.invoice.tax') + ModelData = pool.get('ir.model.data') + Move = pool.get('account.move') + Period = pool.get('account.period') + Tax = pool.get('account.tax') + context = Transaction().context + company_identifier = Identifier.__table__() + party_identifier = Identifier.__table__() + invoice = Invoice.__table__() + invoice_tax = InvoiceTax.__table__() + move = Move.__table__() + period = Period.__table__() + tax = Tax.__table__() + + groups = [] + for module, fs_id in cls.tax_groups(): + try: + groups.append(ModelData.get_id(module, fs_id)) + except KeyError: + # table_query can be called before the XML is loaded + continue + + where = ((invoice.company == context.get('company')) + & (period.fiscalyear == context.get('fiscalyear'))) + where &= invoice.type == 'out' + where &= (company_identifier.code.ilike('BE%') + & (company_identifier.type == 'eu_vat')) + where &= (party_identifier.code.ilike('BE%') + & (party_identifier.type == 'eu_vat')) + where &= tax.group.in_(groups) + return (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) + .join(period, condition=move.period == period.id) + .join(company_identifier, + condition=invoice.tax_identifier == company_identifier.id) + .join(party_identifier, + condition=invoice.party_tax_identifier == party_identifier.id) + .select( + Max(invoice_tax.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'), + invoice.tax_identifier.as_('company_tax_identifier'), + invoice.party_tax_identifier.as_('party_tax_identifier'), + Sum(invoice_tax.base).as_('turnover'), + Sum(invoice_tax.amount).as_('vat'), + invoice.currency.as_('currency'), + where=where, + group_by=[ + invoice.tax_identifier, + invoice.party_tax_identifier, + invoice.currency, + ])) + + +class BEVATCustomerContext(ModelView): + "Belgium VAT Customer Context" + __name__ = 'account.be.vat_customer.context' + + company = fields.Many2One('company.company', "Company", required=True) + fiscalyear = fields.Many2One( + 'account.fiscalyear', "Fiscal Year", required=True, + domain=[ + ('company', '=', Eval('company')), + ], + depends=['company']) + + @classmethod + def default_company(cls): + return Transaction().context.get('company') + + @classmethod + def default_fiscalyear(cls): + pool = Pool() + FiscalYear = pool.get('account.fiscalyear') + context = Transaction().context + return context.get( + 'fiscalyear', + FiscalYear.find(context.get('company'), exception=False)) diff --git a/account.xml b/account.xml new file mode 100644 index 0000000000..c8d7670b98 --- /dev/null +++ b/account.xml @@ -0,0 +1,33 @@ + + + + + + account.be.vat_customer + tree + vat_customer_list + + + + Belgium VAT Customer + account.be.vat_customer + account.be.vat_customer.context + + + + + + + + + + account.be.vat_customer.context + form + vat_customer_context_form + + + + diff --git a/setup.py b/setup.py index e77063a17a..a2a2693ab4 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ setup(name=name, ], package_data={ 'trytond.modules.account_be': (info.get('xml', []) - + ['tryton.cfg']), + + ['tryton.cfg', 'view/*.xml', 'locale/*.po']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tax_be.xml b/tax_be.xml index 525f5f192e..d715aa5a01 100644 --- a/tax_be.xml +++ b/tax_be.xml @@ -363,6 +363,7 @@ this repository contains the full copyright notices and license terms. --> + L @@ -467,6 +468,7 @@ this repository contains the full copyright notices and license terms. --> + S diff --git a/tax_be_fr.xml b/tax_be_fr.xml index 46b7fed02b..d706cbbe3f 100644 --- a/tax_be_fr.xml +++ b/tax_be_fr.xml @@ -363,6 +363,7 @@ this repository contains the full copyright notices and license terms. --> + L @@ -467,6 +468,7 @@ this repository contains the full copyright notices and license terms. --> + S diff --git a/tax_be_nl.xml b/tax_be_nl.xml index a62c365f61..42b8d8a407 100644 --- a/tax_be_nl.xml +++ b/tax_be_nl.xml @@ -363,6 +363,7 @@ this repository contains the full copyright notices and license terms. --> + L @@ -467,6 +468,7 @@ this repository contains the full copyright notices and license terms. --> + S diff --git a/tryton.cfg b/tryton.cfg index b2b47197fc..5db229fba0 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -2,7 +2,9 @@ version=4.5.0 depends: account + account_eu xml: + account.xml account_be_fr.xml tax_be_fr.xml account_be_nl.xml diff --git a/view/vat_customer_context_form.xml b/view/vat_customer_context_form.xml new file mode 100644 index 0000000000..36028cb0a5 --- /dev/null +++ b/view/vat_customer_context_form.xml @@ -0,0 +1,9 @@ + + +
+