<commit_before># -*- coding: utf-8 -*-
# © 2016 <NAME> (Open Net Sarl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import openerp.tests.common as common
from openerp.modules import get_resource_path
import logging
from StringIO import StringIO
import base64
import difflib
import tempfile

_logger = logging.getLogger(__name__)


class TestImport(common.TransactionCase):

    def setUp(self):
        super(TestImport, self).setUp()

        tax_obj = self.env['account.tax']
        account_obj = self.env['account.account']

        user_type = {
                include_initial_balance:
                self.env['account.account.type'].search(
                    [('include_initial_balance',
                        '=', include_initial_balance)],
                    limit=1) for include_initial_balance in [False, True]}

        for code, include_initial_balance in [
                ('1000', True),
                ('1010', True),
                ('1020', True),
                ('1050', True),
                ('1061', True),
                ('1120', True),
                ('2000', True),
                ('2010', True),
                ('2091', True),
                ('2200', True),
                ('4000', False),
                ('4051', False),
                ('4055', False),
                ('4095', False),
                ('4210', False),
                ('4300', False),
                ('4400', False),
                ('4412', False),
                ('4510', False),
                ('4511', False),
                ('4590', False),
                ('4600', False),
                ('5472', False),
                ('5700', False),
                ('6200', False),
                ('6207', False),
                ('8100', False),
                ]:
            acc = account_obj.search([('code', '=', code)])
            if acc:  # patch it within the transaction
                acc.write({
                    'user_type_id': user_type[include_initial_balance].id,
                    'reconcile': True})
            else:
                acc = account_obj.create({
                    'name': 'dummy %s' % code,
                    'code': code,
                    'user_type_id': user_type[include_initial_balance].id,
                    'reconcile': True})

        journal_obj = self.env['account.journal']
        for code, winbiz_code in ('INV','v'), ('BILL','a'), ('MISC','d'), ('JS','s'), ( 'OJ', 'o'):
            journal = journal_obj.search([('code', '=', code)])
            if journal:
                journal.write({'winbiz_mapping': winbiz_code})
            else:
                journal_obj.create({'name': 'dummy '+code, 'code': code, 'type':'general', 'winbiz_mapping': winbiz_code})

        for code, amount, scope in [
                ('310', 6.5, 'sale'), ('315', 6.5, 'purchase'),
                ('400', 7.5, 'sale'), ('405', 7.5, 'purchase'),
                ('410', 7.6, 'sale'), ('415', 7.6, 'purchase')]:
            tax_obj.search([('name', '=', code)]).unlink()
            tax_obj.create({'name': code, 'amount': amount, 'price_include': True, 'type_tax_use': scope})

    def test_import(self):
        def get_path(filename):
            res = get_resource_path('l10n_ch_import_winbiz', 'tests', filename)
            return res
        input = open(get_path('input.xls'))
        gold = open(get_path('golden-output.txt'))
        temp = tempfile.NamedTemporaryFile(prefix='odoo-l10n_ch_import_winbiz')

        buf = StringIO()
        base64.encode(input, buf)
        contents = buf.getvalue()
        buf.close()

        wizard = self.env['account.winbiz.import'].create({<commit_msg>test on an empty database<commit_after># -*- coding: utf-8 -*-
# © 2016 <NAME> (Open Net Sarl)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import openerp.tests.common as common
from openerp.modules import get_resource_path
import logging
from StringIO import StringIO
import base64
import difflib
import tempfile

_logger = logging.getLogger(__name__)


class TestImport(common.TransactionCase):

    def setUp(self):
        super(TestImport, self).setUp()

        tax_obj = self.env['account.tax']
        account_obj = self.env['account.account']
        journal_obj = self.env['account.journal']

        user_type = {
                include_initial_balance:
                self.env['account.account.type'].create({'include_initial_balance': include_initial_balance, 'name': 'dummy'})
                    for include_initial_balance in (False, True)}

        for code, include_initial_balance in [
                ('1000', True),
                ('1010', True),
                ('1020', True),
                ('1050', True),
                ('1061', True),
                ('1120', True),
                ('2000', True),
                ('2010', True),
                ('2091', True),
                ('2200', True),
                ('4000', False),
                ('4051', False),
                ('4055', False),
                ('4095', False),
                ('4210', False),
                ('4300', False),
                ('4400', False),
                ('4412', False),
                ('4510', False),
                ('4511', False),
                ('4590', False),
                ('4600', False),
                ('5472', False),
                ('5700', False),
                ('6200', False),
                ('6207', False),
                ('8100', False),
                ]:
            account_obj.create({
                'name': 'dummy %s' % code,
                'code': code,
                'user_type_id': user_type[include_initial_balance].id,
                'reconcile': True})

        for code, winbiz_code in ('INV','v'), ('BILL','a'), ('MISC','d'), ('JS','s'), ( 'OJ', 'o'):
                journal_obj.create({'name': 'dummy '+code, 'code': code, 'type':'general', 'winbiz_mapping': winbiz_code})

        for code, amount, scope in [
                ('310', 6.5, 'sale'), ('315', 6.5, 'purchase'),
                ('400', 7.5, 'sale'), ('405', 7.5, 'purchase'),
                ('410', 7.6, 'sale'), ('415', 7.6, 'purchase')]:
            tax_obj.create({'name': code, 'amount': amount, 'price_include': True, 'type_tax_use': scope})

    def test_import(self):
        def get_path(filename):
            res = get_resource_path('l10n_ch_import_winbiz', 'tests', filename)
            return res
        input = open(get_path('input.xls'))
        gold = open(get_path('golden-output.txt'))
        temp = tempfile.NamedTemporaryFile(prefix='odoo-l10n_ch_import_winbiz')

        buf = StringIO()
        base64.encode(input, buf)
        contents = buf.getvalue()
        buf.close()

        wizard = self.env['account.winbiz.import'].create({
{'fraction_non_alphanumeric': 0.16111929307805598, 'fraction_numerical': 0.045213549337260676, 'mean_word_length': 1.7338969404186795, 'pattern_counts': {'":': 0, '<': 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': '1357502', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1911, 'n_words': 434}