<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>, Comunitea Servicios Tecnológicos S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _, exceptions
import os
import codecs
import re
from datetime import datetime
from odoo.modules.registry import RegistryManager
import logging
_logger = logging.getLogger(__name__)

SerialMap = {'C': 'Canarias', 'D': 'Transporte', 'G': 'Inmovilizado',
             'J': 'Gastos financieros', 'M': 'Patrocinios',
             'AXM': 'La Caixa', 'F': 'Obras', 'H': 'Software',
             'AL': 'Alquileres', 'RC': 'Canarias', 'RD': 'Transporte',
             'RG': 'Inmovilizado', 'RJ': 'Gastos financieros',
             'RM': 'Patrocinios', 'DXM': 'La Caixa', 'RF': 'Obras',
             'RH': 'Software', 'RAL': 'Alquileres'}


class A3ImportLog(models.Model):

    _name = "a3.import.log"

    name = fields.Char("Filename", required=True)
    state = fields.Selection(
        (('new', 'New'), ('imported', 'Imported'), ('error', 'Error')),
        default='new')
    errors = fields.Text()

    @api.multi
    def move_imported_files(self, importation_folder, process_folder):
        for doc in self:
            if doc.state == 'imported':
                from_file = '%s%s%s' % (importation_folder, os.sep, doc.name)
                to_file = '%s%s%s' % (process_folder, os.sep, doc.name)
                os.rename(from_file, to_file)

    @api.model
    def import_invoice(self, line, company, refund=False):
        invoice_number = line[58:68].strip()
        letters = re.findall('\d*\D+', invoice_number)
        tag_ids = []
        if letters and letters[0] in SerialMap:
            tags = self.env["account.invoice.tag"].\
                search([('name', '=', SerialMap[letters[0]])])
            if tags:
                tag_ids.append(tags[0].id)
        invoice_vals = {
            'type': refund and 'out_refund' or 'out_invoice',
            'journal_id': self.env["account.journal"].
            search([('type', '=', 'sale'),
                    ('company_id', '=', company.id)])[0].id,
            'currency_id': company.currency_id.id,
            'number': invoice_number,
            'invoice_number': invoice_number,
            'date_invoice': datetime.
            strftime(datetime.strptime(line[6:14], "%Y%m%d"), "%Y-%m-%d"),
            'company_id': company.id,
            'tag_ids': [(6, 0, tag_ids)]
        }
        return invoice_vals

    @api.model
    def import_invoice_line(self, line, company):
        taxes = self.env["account.tax"]
        national_valid_codes = ['S_IVA21B', 'S_IVA4B', 'S_IVA0', 'S_IVA10B']
        intracomunity_valid_codes = ['S_IVA0_IC']
        extracomunity_valid_codes = ['S_IVA0_E']
        recharge_valid_code = ['S_REQ05', 'S_REQ014', 'S_REQ52']
        fiscal_position_code = line[99:101]
        tax_domain = [('type_tax_use', '=', 'sale'),
                      ('company_id', '=', company.id)]

        iva_tax = float(line[115:120])
        iva_domain = [('amount', '=', iva_tax)]
        iva_domain.extend(tax_domain)
        if fiscal_position_code == "01":
            iva_domain.append(('description', 'in', national_valid_codes))
        elif fiscal_position_code == "03":
            iva_domain.append(('description', 'in',
                               intracomunity_valid_codes))<commit_msg>[MOD] account_invoice_a3_import . Cambio a IVA NO SUJETO<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 <NAME>, Comunitea Servicios Tecnológicos S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields, api, _, exceptions
import os
import codecs
import re
from datetime import datetime
from odoo.modules.registry import RegistryManager
import logging
_logger = logging.getLogger(__name__)

SerialMap = {'C': 'Canarias', 'D': 'Transporte', 'G': 'Inmovilizado',
             'J': 'Gastos financieros', 'M': 'Patrocinios',
             'AXM': 'La Caixa', 'F': 'Obras', 'H': 'Software',
             'AL': 'Alquileres', 'RC': 'Canarias', 'RD': 'Transporte',
             'RG': 'Inmovilizado', 'RJ': 'Gastos financieros',
             'RM': 'Patrocinios', 'DXM': 'La Caixa', 'RF': 'Obras',
             'RH': 'Software', 'RAL': 'Alquileres'}


class A3ImportLog(models.Model):

    _name = "a3.import.log"

    name = fields.Char("Filename", required=True)
    state = fields.Selection(
        (('new', 'New'), ('imported', 'Imported'), ('error', 'Error')),
        default='new')
    errors = fields.Text()

    @api.multi
    def move_imported_files(self, importation_folder, process_folder):
        for doc in self:
            if doc.state == 'imported':
                from_file = '%s%s%s' % (importation_folder, os.sep, doc.name)
                to_file = '%s%s%s' % (process_folder, os.sep, doc.name)
                os.rename(from_file, to_file)

    @api.model
    def import_invoice(self, line, company, refund=False):
        invoice_number = line[58:68].strip()
        letters = re.findall('\d*\D+', invoice_number)
        tag_ids = []
        if letters and letters[0] in SerialMap:
            tags = self.env["account.invoice.tag"].\
                search([('name', '=', SerialMap[letters[0]])])
            if tags:
                tag_ids.append(tags[0].id)
        invoice_vals = {
            'type': refund and 'out_refund' or 'out_invoice',
            'journal_id': self.env["account.journal"].
            search([('type', '=', 'sale'),
                    ('company_id', '=', company.id)])[0].id,
            'currency_id': company.currency_id.id,
            'number': invoice_number,
            'invoice_number': invoice_number,
            'date_invoice': datetime.
            strftime(datetime.strptime(line[6:14], "%Y%m%d"), "%Y-%m-%d"),
            'company_id': company.id,
            'tag_ids': [(6, 0, tag_ids)]
        }
        return invoice_vals

    @api.model
    def import_invoice_line(self, line, company):
        taxes = self.env["account.tax"]
        national_valid_codes = ['S_IVA21B', 'S_IVA4B', 'S_IVA_NS', 'S_IVA10B']
        intracomunity_valid_codes = ['S_IVA0_IC']
        extracomunity_valid_codes = ['S_IVA0_E']
        recharge_valid_code = ['S_REQ05', 'S_REQ014', 'S_REQ52']
        fiscal_position_code = line[99:101]
        tax_domain = [('type_tax_use', '=', 'sale'),
                      ('company_id', '=', company.id)]

        iva_tax = float(line[115:120])
        iva_domain = [('amount', '=', iva_tax)]
        iva_domain.extend(tax_domain)
        if fiscal_position_code == "01":
            iva_domain.append(('description', 'in', national_valid_codes))
        elif fiscal_position_code == "03":
            iva_domain.append(('description', 'in',
                               intracomunity_valid_codes))
{'fraction_non_alphanumeric': 0.1624908424908425, 'fraction_numerical': 0.015238095238095238, 'mean_word_length': 2.520371325425477, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '7143521', 'n_tokens_mistral': 2336, 'n_tokens_neox': 2256, 'n_words': 455}