mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
update intrastat modules
This commit is contained in:
committed by
Alexis de Lattre
parent
f61a01cc7d
commit
ce293b57db
@@ -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)
|
||||
|
||||
@@ -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'})
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user