Complete change of design for intrastat_type ! Now that report_intrastat_product/service object is stored in database, we don't need the legal_intrastat state on invoices any more, because we will be able to create entry lines for DEB for a repair of equipment under warranty without using a legal_intrastat. Report_intrastat_type is now only required for DEB -> object moved to module l10n_fr_intrastat_product. For DEB, the button "regenerate lines" only regenerate DEB lines related to invoices.

Renamed intrastat base module, because it doesn't have France-specific parameters any more.

Add demo data.
This commit is contained in:
Alexis de Lattre
2011-04-05 00:57:21 +02:00
committed by Alexis de Lattre
parent 0e8a20924f
commit b16731c379
12 changed files with 503 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Report intrastat base module for OpenERP
# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import country
import product
import partner_address
import intrastat_common

View File

@@ -0,0 +1,53 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Report intrastat base module for OpenERP
# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Base module for Intrastat reporting',
'version': '1.1',
'category': 'Localisation/Report Intrastat',
'license': 'AGPL-3',
'description': """This module contains the common functions for 2 other modules :
- l10n_fr_intrastat_service : the module for the "Déclaration Européenne des Services" (DES)
- l10n_fr_intrastat_product : the module for the "Déclaration d'Echange de Biens" (DEB)
This module is not usefull if it's not used together with one of those 2 modules.
This module doesn't have any France-specific stuff. So it can be used as a basis for other intrastat modules for other EU countries.
WARNING : this module conflicts with the module "report_intrastat" from the addons. If you have already installed the module "report_intrastat", you should uninstall it first before installing this module.
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for any help or question about this module.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['account'],
'init_xml': ['country_data.xml'],
'update_xml': [
'security/ir.model.access.csv',
'product_view.xml',
'country_view.xml',
'intrastat_menu.xml',
],
'demo_xml': ['product_demo.xml'],
'installable': True,
'active': False,
}

33
intrastat_base/country.py Normal file
View File

@@ -0,0 +1,33 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (http://tiny.be). All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
class res_country(osv.osv):
_inherit = 'res.country'
_columns = {
'intrastat': fields.boolean('Intrastat member'),
}
_defaults = {
'intrastat': lambda *a: False,
}
res_country()

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="base.de" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.at" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.cy" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.dk" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.es" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.ee" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.fi" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.gr" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.hu" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.ie" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.it" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.lv" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.lt" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.lu" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.mt" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.nl" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.pl" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.pt" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.sk" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.cz" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.uk" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.si" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.se" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.ro" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.bg" model="res.country">
<field eval="True" name="intrastat"/>
</record>
<record id="base.be" model="res.country">
<field eval="True" name="intrastat"/>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>)
The licence is in the file __terp__.py
-->
<openerp>
<data>
<!-- Add intrastat field on res_country -->
<record id="intrastat_base_country_tree" model="ir.ui.view">
<field name="name">intrastat.base.country.tree</field>
<field name="model">res.country</field>
<field name="inherit_id" ref="base.view_country_tree" />
<field name="arch" type="xml">
<field name="code" position="after">
<field name="intrastat" />
</field>
</field>
</record>
<record id="intrastat_base_country_form" model="ir.ui.view">
<field name="name">intrastat.base.country.form</field>
<field name="model">res.country</field>
<field name="inherit_id" ref="base.view_country_form" />
<field name="arch" type="xml">
<field name="code" position="after">
<field name="intrastat" select="1" />
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,111 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Report intrastat base module for OpenERP
# Copyright (C) 2010-2011 Akretion (http://www.akretion.com/). All rights reserved.
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from tools.translate import _
class report_intrastat_common(osv.osv_memory):
_name = "report.intrastat.common"
_description = "Common functions for intrastat reports for products and services"
def _compute_numbers(self, cr, uid, ids, object, context=None):
result = {}
for intrastat in object.browse(cr, uid, ids, context=context):
total_amount = 0.0
num_lines = 0
for line in intrastat.intrastat_line_ids:
total_amount += line.amount_company_currency
num_lines += 1
result[intrastat.id] = {'num_lines': num_lines, 'total_amount': total_amount}
return result
def _compute_end_date(self, cr, uid, ids, object, context=None):
result = {}
for intrastat in object.browse(cr, uid, ids, context=context):
start_date_datetime = datetime.strptime(intrastat.start_date, '%Y-%m-%d')
end_date_str = datetime.strftime(start_date_datetime + relativedelta(day=31), '%Y-%m-%d')
result[intrastat.id] = end_date_str
return result
def _check_start_date(self, cr, uid, ids, object, context=None):
'''Check that the start date if the first day of the month'''
for date_to_check in object.read(cr, uid, ids, ['start_date'], context=context):
datetime_to_check = datetime.strptime(date_to_check['start_date'], '%Y-%m-%d')
if datetime_to_check.day != 1:
return False
return True
def _check_generate_lines(self, cr, uid, ids, intrastat, context=None):
if len(ids) != 1:
raise osv.except_osv(_('Error :'), 'Hara kiri in generate_lines')
if not intrastat.company_id.currency_id.code:
raise osv.except_osv(_('Error :'), _('The currency code is not set on the currency "%s".'%intrastat.company_id.currency_id.name))
if not intrastat.currency_id.code == 'EUR':
raise osv.except_osv(_('Error :'), _('The company currency must be "EUR", but is currently "%s".'%intrastat.currency_id.code))
return None
def _check_generate_xml(self, cr, uid, ids, intrastat, context=None):
if len(ids) != 1:
raise osv.except_osv(_('Error :'), 'Hara kiri in generate_xml')
if not intrastat.company_id.partner_id.vat:
raise osv.except_osv(_('Error :'), _('The VAT number is not set for the partner "%s".'%intrastat.company_id.partner_id.name))
if not intrastat.company_id.partner_id.vat[0:2] == 'FR':
raise osv.except_osv(_('Error :'), _("The company '%s' should have a VAT number starting with 'FR' on it's related partner. Its current VAT number is '%s'."%(intrastat.company_id.name, intrastat.company_id.partner_id.vat)))
return None
def _check_xml_schema(self, cr, uid, xml_root, xml_string, xsd, context=None):
from lxml import etree
official_des_xml_schema = etree.XMLSchema(etree.fromstring(xsd))
try: official_des_xml_schema.assertValid(xml_root)
except Exception, e: # if the validation of the XSD fails, we arrive here
import netsvc
logger = netsvc.Logger()
logger.notifyChannel('intrastat', netsvc.LOG_WARNING, "The XML file is invalid against the XSD")
logger.notifyChannel('intrastat', netsvc.LOG_WARNING, xml_string)
logger.notifyChannel('intrastat', netsvc.LOG_WARNING, e)
raise osv.except_osv(_('Error :'), _('The generated XML file is not valid against the official XML schema. The generated XML file and the full error have been written in the server logs. Here is the exact error, which may give you an idea of the cause of the problem : ' + str(e)))
return None
def _attach_xml_file(self, cr, uid, ids, object, xml_string, start_date_datetime, declaration_name, context=None):
'''Attach the XML file to the intrastat_xxx object'''
import base64
if len(ids) != 1:
raise osv.except_osv(_('Error :'), 'Hara kiri in attach_xml_file')
filename = datetime.strftime(start_date_datetime, '%Y-%m') + '_' + declaration_name + '.xml'
attach_name = declaration_name.upper() + ' ' + datetime.strftime(start_date_datetime, '%Y-%m')
attach_obj = self.pool.get('ir.attachment')
if not context:
context = {}
context.update({'default_res_id' : ids[0], 'default_res_model': object._name})
attach_id = attach_obj.create(cr, uid, {'name': attach_name, 'datas': base64.encodestring(xml_string), 'datas_fname': filename}, context=context)
return None
report_intrastat_common()

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 Akretion (http://www.akretion.com/)
The licence is in the file __terp__.py
-->
<openerp>
<data>
<!-- Menu entry for Intrastat -->
<menuitem id="menu_intrastat_base_root" name="Intrastat reporting" parent="account.menu_finance_legal_statement" />
</data>
</openerp>

View File

@@ -0,0 +1,36 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Report intrastat base module for OpenERP
# Copyright (C) 2010-2011 Akretion (http://www.akretion.com/) All Rights Reserved
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
# We want to have the country field of partner_address always set
# because the selection of invoices for intrastat reports is based
# on the country of the invoice partner address !
class res_partner_address(osv.osv):
_name = 'res.partner.address'
_inherit = 'res.partner.address'
_columns = {
'country_id': fields.many2one('res.country', 'Country', required=True),
}
res_partner_address()

36
intrastat_base/product.py Normal file
View File

@@ -0,0 +1,36 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Report intrastat base module for OpenERP
# Copyright (C) 2010-2011 Akretion (http://www.akretion.com/) All Rights Reserved
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
class product_template(osv.osv):
_inherit = "product.template"
_columns = {
'exclude_from_intrastat': fields.boolean('Exclude from Intrastat reports', help="If true, the product or service will not taken into account for Intrastat Product or Service reports. So you should leave this field to false unless you have a good reason. Exemple of good reason : 'Shipping' is a service that should probably be excluded from the Intrastat Service report."),
}
_default = {
'exclude_from_intrastat': lambda *a: False,
}
product_template()

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __terp__.py
-->
<openerp>
<data noupdate="1">
<record id="shipping_costs_exclude" model="product.product">
<field name="name">Shipping costs</field>
<field name="code">SHIP</field>
<field name="type">service</field>
<field name="categ_id" ref="product.product_category_services"/>
<field name="list_price">30</field>
<field name="exclude_from_intrastat">False</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010-2011 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __terp__.py
-->
<openerp>
<data>
<!-- Add field on product.product view -->
<record id="intrastat_base_product_normal_form" model="ir.ui.view">
<field name="name">intrastat.base.product.normal.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="account.product_normal_form_view" />
<field name="arch" type="xml">
<data>
<field name="property_account_expense" position="after">
<separator string="Intrastat properties" colspan="4"/>
<group colspan="4">
<field name="exclude_from_intrastat" select="2" />
</group>
</field>
</data>
</field>
</record>
<!-- Same on product.template view -->
<record id="intrastat_base_product_template_form" model="ir.ui.view">
<field name="name">intrastat.base.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="account.product_template_form_view"/>
<field name="arch" type="xml">
<data>
<field name="property_account_expense" position="after">
<separator string="Intrastat properties" colspan="4"/>
<group colspan="4">
<field name="exclude_from_intrastat" select="2" />
</group>
</field>
</data>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,2 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_report_intrastat_common","Read access on report.intrastat.common","model_report_intrastat_common","base.group_user",1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_report_intrastat_common Read access on report.intrastat.common model_report_intrastat_common base.group_user 1 0 0 0