update intrastat modules

This commit is contained in:
luc-demeyer
2015-10-27 15:06:54 +01:00
committed by Alexis de Lattre
parent f61a01cc7d
commit ce293b57db
3 changed files with 51 additions and 4 deletions

View File

@@ -85,14 +85,16 @@ class IntrastatCommon(models.AbstractModel):
return True
@api.model
def _check_xml_schema(self, xml_root, xml_string, xsd_file):
def _check_xml_schema(self, xml_string, xsd_file):
'''Validate the XML file against the XSD'''
from lxml import etree
from StringIO import StringIO
xsd_etree_obj = etree.parse(
tools.file_open(xsd_file))
official_schema = etree.XMLSchema(xsd_etree_obj)
try:
official_schema.assertValid(xml_root)
t = etree.parse(StringIO(xml_string))
official_schema.assertValid(t)
except Exception, e:
# if the validation of the XSD fails, we arrive here
logger = logging.getLogger(__name__)
@@ -124,6 +126,13 @@ class IntrastatCommon(models.AbstractModel):
'datas_fname': filename})
return attach.id
@api.multi
def _unlink_attachments(self):
atts = self.env['ir.attachment'].search(
[('res_model', '=', self._name),
('res_id', '=', self.id)])
atts.unlink()
@api.model
def _open_attach_view(self, attach_id, title='XML file'):
'''Returns an action which opens the form view of the
@@ -140,6 +149,20 @@ class IntrastatCommon(models.AbstractModel):
}
return action
@api.multi
def _generate_xml(self):
"""
Inherit this method in the localization module
to generate the INTRASTAT Declaration XML file
Returns:
string with XML data
Call the _check_xml_schema() method
before returning the XML string.
"""
return False
@api.one
def send_reminder_email(self, mail_template_xmlid):
mail_template = self.env.ref(mail_template_xmlid)

View File

@@ -23,7 +23,7 @@
##############################################################################
from openerp import models, fields, api, _
from openerp.exceptions import RedirectWarning, ValidationError
from openerp.exceptions import RedirectWarning, ValidationError, Warning
import openerp.addons.decimal_precision as dp
from datetime import datetime, date
from dateutil.relativedelta import relativedelta
@@ -438,6 +438,7 @@ class IntrastatProductDeclaration(models.Model):
@api.multi
def action_gather(self):
self.ensure_one()
self._check_generate_lines()
self._note = ''
self._uom_refs = {
'weight_uom_categ': self.env.ref('product.product_uom_categ_kgm'),
@@ -518,6 +519,22 @@ class IntrastatProductDeclaration(models.Model):
cl.write({'declaration_line_id': declaration_line.id})
return True
@api.multi
def generate_xml(self):
""" generate the INTRASTAT Declaration XML file """
self.ensure_one()
self._check_generate_xml()
self._unlink_attachments()
xml_string = self._generate_xml()
if xml_string:
attach_id = self._attach_xml_file(
xml_string, '%s_%s' % (self.type, self.revision))
return self._open_attach_view(attach_id)
else:
raise Warning(
_("Programming Error."),
_("No XML File has been generated."))
@api.multi
def done(self):
self.write({'state': 'done'})

View File

@@ -12,7 +12,13 @@
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('action', '=', 'nihil')]}"
string="Generate lines from invoices"
class="oe_highlight"/>
<button name="generate_declaration" string="Generate Declaration" type="object"/>
<button name="generate_declaration" type="object"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('action', '=', 'nihil')]}"
string="Generate Declaration Lines"/>
<button name="generate_xml"
string="Generate XML Declaration File"
type="object"
attrs="{'invisible': [('state', '!=', 'draft')]}"/>
<button name="done" string="Done" type="object" class="oe_highlight" states="draft"/>
<button name="back2draft" string="Back to draft" type="object" states="done"/>
<field name="state" widget="statusbar"/>
@@ -34,6 +40,7 @@
<field name="type"/>
<field name="action"/>
<field name="revision"/>
<field name="reporting_level" invisible="1"/>
</group>
</group>
<group name="properties-2">