<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 <NAME> <<EMAIL>>
#    Copyright (C) 2015 <NAME> <<EMAIL>>
#
#    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 base64
import re
import tempfile
from pyxb.exceptions_ import SimpleFacetValueError
from unidecode import unidecode
from openerp.osv import orm
from openerp import addons
from openerp.addons.l10n_it_fatturapa.bindings.fatturapa_v_1_1 import (
    FatturaElettronica,
    FatturaElettronicaHeaderType,
    DatiTrasmissioneType,
    IdFiscaleType,
    ContattiTrasmittenteType,
    CedentePrestatoreType,
    AnagraficaType,
    IndirizzoType,
    IscrizioneREAType,
    CessionarioCommittenteType,
    DatiAnagraficiCedenteType,
    DatiAnagraficiCessionarioType,
    FatturaElettronicaBodyType,
    DatiGeneraliType,
    DettaglioLineeType,
    DatiBeniServiziType,
    DatiRiepilogoType,
    DatiGeneraliDocumentoType,
    DatiDocumentiCorrelatiType
    )
from openerp.addons.l10n_it_fatturapa.models.account import (
    RELATED_DOCUMENT_TYPES)
from openerp.tools.translate import _


class WizardExportFatturapa(orm.TransientModel):
    _name = "wizard.export.fatturapa"
    _description = "Export FatturaPA"

    def __init__(self, cr, uid, **kwargs):
        self.fatturapa = False
        self.number = False
        super(WizardExportFatturapa, self).__init__(cr, uid, **kwargs)

    def getFile(self, filename, context=None):
        if context is None:
            context = {}

        path = addons.get_module_resource(
            'l10n_it_fatturapa', 'data', filename)
        with open(path) as test_data:
            with tempfile.TemporaryFile() as out:
                base64.encode(test_data, out)
                out.seek(0)
                return out.read()
    '''
    def setNameSpace(self):
        register_namespace('ds', "http://www.w3.org/2000/09/xmldsig#")
        register_namespace(
            'p', "http://www.fatturapa.gov.it/sdi/fatturapa/v1.1")
        register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
    '''
    def saveAttachment(self, cr, uid, context=None):
        if context is None:
            context = {}

        number = self.number

        user_obj = self.pool['res.users']
        company = user_obj.browse(cr, uid, uid).company_id

        if not company.vat:
            raise orm.except_orm(
                _('Error!'), _('Company TIN not set.'))
        attach_obj = self.pool['fatturapa.attachment.out']
        attach_vals = {
            'name': '%s_%s.xml' % (company.vat, str(number)),
            'datas_fname': '%s_%s.xml' % (company.vat, str(number)),
            'datas': base64.encodestring(self.fatturapa.toxml("utf-8")),
        }
        attach_id = attach_obj.create(cr, uid, attach_vals, context=context)

        return attach_id

    def setProgressivoInvio(self, cr, uid, context=None):
        if context is None:
            context = {}

        user_obj = self.pool['res.users']<commit_msg>[FIX] change toxml<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 <NAME> <<EMAIL>>
#    Copyright (C) 2015 <NAME> <<EMAIL>>
#
#    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 base64
import re
import tempfile
from pyxb.exceptions_ import SimpleFacetValueError
from unidecode import unidecode
from openerp.osv import orm
from openerp import addons
from openerp.addons.l10n_it_fatturapa.bindings.fatturapa_v_1_1 import (
    FatturaElettronica,
    FatturaElettronicaHeaderType,
    DatiTrasmissioneType,
    IdFiscaleType,
    ContattiTrasmittenteType,
    CedentePrestatoreType,
    AnagraficaType,
    IndirizzoType,
    IscrizioneREAType,
    CessionarioCommittenteType,
    DatiAnagraficiCedenteType,
    DatiAnagraficiCessionarioType,
    FatturaElettronicaBodyType,
    DatiGeneraliType,
    DettaglioLineeType,
    DatiBeniServiziType,
    DatiRiepilogoType,
    DatiGeneraliDocumentoType,
    DatiDocumentiCorrelatiType
    )
from openerp.addons.l10n_it_fatturapa.models.account import (
    RELATED_DOCUMENT_TYPES)
from openerp.tools.translate import _


class WizardExportFatturapa(orm.TransientModel):
    _name = "wizard.export.fatturapa"
    _description = "Export FatturaPA"

    def __init__(self, cr, uid, **kwargs):
        self.fatturapa = False
        self.number = False
        super(WizardExportFatturapa, self).__init__(cr, uid, **kwargs)

    def getFile(self, filename, context=None):
        if context is None:
            context = {}

        path = addons.get_module_resource(
            'l10n_it_fatturapa', 'data', filename)
        with open(path) as test_data:
            with tempfile.TemporaryFile() as out:
                base64.encode(test_data, out)
                out.seek(0)
                return out.read()
    '''
    def setNameSpace(self):
        register_namespace('ds', "http://www.w3.org/2000/09/xmldsig#")
        register_namespace(
            'p', "http://www.fatturapa.gov.it/sdi/fatturapa/v1.1")
        register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
    '''
    def saveAttachment(self, cr, uid, context=None):
        if context is None:
            context = {}

        number = self.number

        user_obj = self.pool['res.users']
        company = user_obj.browse(cr, uid, uid).company_id

        if not company.vat:
            raise orm.except_orm(
                _('Error!'), _('Company TIN not set.'))
        attach_obj = self.pool['fatturapa.attachment.out']
        attach_vals = {
            'name': '%s_%s.xml' % (company.vat, str(number)),
            'datas_fname': '%s_%s.xml' % (company.vat, str(number)),
            'datas': base64.encodestring(self.fatturapa.toxml("latin1")),
        }
        attach_id = attach_obj.create(cr, uid, attach_vals, context=context)

        return attach_id

    def setProgressivoInvio(self, cr, uid, context=None):
        if context is None:
            context = {}

        user_obj = self.pool['res.users']
{'fraction_non_alphanumeric': 0.13590559533280297, 'fraction_numerical': 0.010607265977194379, 'mean_word_length': 3.0207889125799574, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6198791', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2322, 'n_words': 565}