diff --git a/intrastat_base/__init__.py b/intrastat_base/__init__.py new file mode 100644 index 0000000..c593568 --- /dev/null +++ b/intrastat_base/__init__.py @@ -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 +# +# 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 . +# +############################################################################## + +import country +import product +import partner_address +import intrastat_common + diff --git a/intrastat_base/__terp__.py b/intrastat_base/__terp__.py new file mode 100644 index 0000000..6ad92af --- /dev/null +++ b/intrastat_base/__terp__.py @@ -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 +# +# 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 . +# +############################################################################## + + +{ + '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 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, +} diff --git a/intrastat_base/country.py b/intrastat_base/country.py new file mode 100644 index 0000000..fbd284c --- /dev/null +++ b/intrastat_base/country.py @@ -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 . +# +############################################################################## + +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() diff --git a/intrastat_base/country_data.xml b/intrastat_base/country_data.xml new file mode 100644 index 0000000..228c0b4 --- /dev/null +++ b/intrastat_base/country_data.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/intrastat_base/country_view.xml b/intrastat_base/country_view.xml new file mode 100644 index 0000000..faa85d9 --- /dev/null +++ b/intrastat_base/country_view.xml @@ -0,0 +1,36 @@ + + + + + + + + + + intrastat.base.country.tree + res.country + + + + + + + + + + intrastat.base.country.form + res.country + + + + + + + + + + + diff --git a/intrastat_base/intrastat_common.py b/intrastat_base/intrastat_common.py new file mode 100644 index 0000000..d7e6ec8 --- /dev/null +++ b/intrastat_base/intrastat_common.py @@ -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 +# +# 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 . +# +############################################################################## + +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() + diff --git a/intrastat_base/intrastat_menu.xml b/intrastat_base/intrastat_menu.xml new file mode 100644 index 0000000..42888ca --- /dev/null +++ b/intrastat_base/intrastat_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/intrastat_base/partner_address.py b/intrastat_base/partner_address.py new file mode 100644 index 0000000..bc4e4f0 --- /dev/null +++ b/intrastat_base/partner_address.py @@ -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 +# +# 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 . +# +############################################################################## + +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() + diff --git a/intrastat_base/product.py b/intrastat_base/product.py new file mode 100644 index 0000000..d6c30f5 --- /dev/null +++ b/intrastat_base/product.py @@ -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 +# +# 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 . +# +############################################################################## + +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() + diff --git a/intrastat_base/product_demo.xml b/intrastat_base/product_demo.xml new file mode 100644 index 0000000..f29f16d --- /dev/null +++ b/intrastat_base/product_demo.xml @@ -0,0 +1,22 @@ + + + + + + + + + Shipping costs + SHIP + service + + 30 + False + + + + diff --git a/intrastat_base/product_view.xml b/intrastat_base/product_view.xml new file mode 100644 index 0000000..7173765 --- /dev/null +++ b/intrastat_base/product_view.xml @@ -0,0 +1,47 @@ + + + + + + + + + + intrastat.base.product.normal.form + product.product + + + + + + + + + + + + + + + + intrastat.base.product.template.form + product.template + + + + + + + + + + + + + + + diff --git a/intrastat_base/security/ir.model.access.csv b/intrastat_base/security/ir.model.access.csv new file mode 100644 index 0000000..d7a2bf1 --- /dev/null +++ b/intrastat_base/security/ir.model.access.csv @@ -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