mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
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. Full re-design of intrastat types : probably requires deleting the report_intrastat_type table, restarting OpenERP and re-creating intrastat types. Moved intrastat departments from stock.warehouse to stock.location. Dropped SQL queries ; replaced by traditionnal python code logic. No more need to have one rate per day for invoices with foreign currency. Add total fiscal value for DEB More code factorization. Prepare translation work. Moved some demo data from l10n_fr_intrastat_product to intrastat_base Moved configuration about taxes from company form to tax form Some modifications to ease v5 -> v6 migration : - object report_intrastat_code now belong to group account manager - button functions now return True Tried to implement the following feature : open attachement form when the XML file as been generated : works on v6, but make client crash en v5 -> code has been commented DEB lines with procedure code = 25 are now deducted from the fiscal total. Round invoice total. Moved the field exclude_from_intrastat_if_present of account.tax from l10n_fr_intrastat_product to intrastat_base, because it should also be used in the module l10n_fr_intrastat_service. Take this field into account in the generation of DEB lines (module l10n_fr_intrastat_service). It is now possible to set the H.S. code on the product category. Some "return None" changed to "return True" Implemented the fiscal representative : for example, when you ship to the EU but invoice outside of the EU, your customer needs to have a fiscal representative inside the EU, which will be used for the DEB . depend on base_vat instead of account. Same modification as my previous commit for DEB : when we sell to a physical person in the EU with VAT, the move is not declared in DEB, so it must not block with a "raise" if the partner doesn't have a VAT number. Add option "is_accessory_cost" on product.template : If the invoice has is_accessory_cost services but no regular product -> DES If the invoice has is_accessory_cost services and regular product -> added to the cost of products in DEB Now allows "pricelist for statistical value" which is not in EUR (the currency conversion will be made from the pricelist currency to EUR) Usability improvements : - Order for DEB and DES tree view : "the more recent at the top" - distinction between "Information to declare" and "Additionnal information" in intrastat lines Better string. Update French translation. Use the new logger API of OpenERP 6.1 Move the "EU fiscal representative" field in order to avoid the "compression" of the VAT field that made it too small. Code clean-up : - context is not passed in constraints - don't use lambda when not necessary IMPORTANT CHANGE : - All EU countries should now be intrastat=True, including your own country - When generating lines for Intrastat Product/Service, all invoices for which country == Company's country are excluded Update help message according to my change of commit 61. Fix copyright header.
133 lines
6.1 KiB
Python
133 lines
6.1 KiB
Python
# -*- 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
|
|
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 is 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, intrastat, context=None):
|
|
if not intrastat.company_id.country_id:
|
|
raise osv.except_osv(_('Error :'), _("The country is not set on the company '%s'.") %intrastat.company_id.name)
|
|
if not intrastat.currency_id.name == 'EUR':
|
|
raise osv.except_osv(_('Error :'), _("The company currency must be 'EUR', but is currently '%s'.") %intrastat.currency_id.name)
|
|
return True
|
|
|
|
|
|
def _check_generate_xml(self, cr, uid, intrastat, context=None):
|
|
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)
|
|
return True
|
|
|
|
|
|
def _check_xml_schema(self, cr, uid, xml_root, xml_string, xsd, context=None):
|
|
'''Validate the XML file against the XSD'''
|
|
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 logging
|
|
_logger = logging.getLogger(__name__)
|
|
_logger.warning("The XML file is invalid against the XML Schema Definition")
|
|
_logger.warning(xml_string)
|
|
_logger.warning(e)
|
|
raise osv.except_osv(_('Error :'), _('The generated XML file is not valid against the official XML Schema Definition. The generated XML file and the full error have been written in the server logs. Here is the error, which may give you an idea on the cause of the problem : %s.') % str(e))
|
|
return True
|
|
|
|
|
|
def _attach_xml_file(self, cr, uid, ids, object, xml_string, start_date_datetime, declaration_name, context=None):
|
|
'''Attach the XML file to the report_intrastat_product/service 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 attach_id
|
|
|
|
|
|
def _open_attach_view(self, cr, uid, attach_id, title='XML file', context=None):
|
|
'''Returns an action which opens the form view of the corresponding attachement'''
|
|
# Only works in v6 -> not used in v5
|
|
action = {
|
|
'name': title,
|
|
'view_type': 'form',
|
|
'view_mode': 'form,tree',
|
|
'view_id': False,
|
|
'res_model': 'ir.attachment',
|
|
'type': 'ir.actions.act_window',
|
|
'nodestroy': True,
|
|
'target': 'current',
|
|
'res_id': [attach_id],
|
|
}
|
|
return action
|
|
|
|
|
|
def partner_on_change(self, cr, uid, ids, partner_id=False):
|
|
result = {}
|
|
result['value'] = {}
|
|
if partner_id:
|
|
company = self.pool.get('res.partner').read(cr, uid, partner_id, ['vat'])
|
|
result['value'].update({'partner_vat': company['vat']})
|
|
return result
|
|
|
|
report_intrastat_common()
|
|
|