<commit_before># -*- coding: utf-8 -*-
# Copyright 2015 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api, exceptions
from openerp.tools.translate import _
from openerp.addons.l10n_ch_import_winbiz.utils import importers


def prepare_move(lines, journal, date, ref):
    return {'line_ids': [(0, 0, dict(ln)) for ln in lines],
            'journal_id': journal.id,
            'date': date,
            'ref': ref}


def account_line_merge(lines):
    lines_orig = lines
    lines = [ln for ln in lines
             if ln.account.user_type_id.include_initial_balance]
    lines.sort(key=lambda ln: ln.account.code)
    to_remove = []
    previous = None
    for current in lines:
        if previous is not None \
                and previous.account == current.account:
            previous.amount += current.amount
            to_remove.append(current)
        else:
            previous = current

    lines = lines_orig
    for elem in to_remove:
        lines.remove(elem)
    return lines


class LineIntermediate(object):
    '''has a single ``amount`` attribute that's negative for debit, but
    can be converted into a dict for the ORM ``create()`` with
    ``dict(self)``
    '''
    def __init__(self, name, account, amount=0,
                 tax=None, originator_tax=None):
        self.name = name
        self.account = account
        self.amount = amount
        self.tax = tax
        self.originator_tax = originator_tax

    def __iter__(self):
        yield 'name', self.name
        yield 'account_id', self.account.id
        if self.amount < 0:
            yield 'debit', -self.amount
        else:
            yield 'credit', self.amount
        if self.tax:
            yield 'tax_ids', [(4, self.tax.id, 0)]
        if self.originator_tax:
            yield 'tax_line_id', self.originator_tax.id

prepare_line = LineIntermediate


class AccountWinbizImport(models.TransientModel):<commit_msg>[PEP8]<commit_after># -*- coding: utf-8 -*-
# Copyright 2015 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api, exceptions
from openerp.tools.translate import _
from openerp.addons.l10n_ch_import_winbiz.utils import importers


def prepare_move(lines, journal, date, ref):
    return {'line_ids': [(0, 0, dict(ln)) for ln in lines],
            'journal_id': journal.id,
            'date': date,
            'ref': ref}


def account_line_merge(lines):
    lines_orig = lines
    lines = [ln for ln in lines
             if ln.account.user_type_id.include_initial_balance]
    lines.sort(key=lambda ln: ln.account.code)
    to_remove = []
    previous = None
    for current in lines:
        if previous is not None \
                and previous.account == current.account:
            previous.amount += current.amount
            to_remove.append(current)
        else:
            previous = current

    lines = lines_orig
    for elem in to_remove:
        lines.remove(elem)
    return lines


class LineIntermediate(object):
    '''has a single ``amount`` attribute that's negative for debit, but
    can be converted into a dict for the ORM ``create()`` with
    ``dict(self)``
    '''
    def __init__(self, name, account, amount=0,
                 tax=None, originator_tax=None):
        self.name = name
        self.account = account
        self.amount = amount
        self.tax = tax
        self.originator_tax = originator_tax

    def __iter__(self):
        yield 'name', self.name
        yield 'account_id', self.account.id
        if self.amount < 0:
            yield 'debit', -self.amount
        else:
            yield 'credit', self.amount
        if self.tax:
            yield 'tax_ids', [(4, self.tax.id, 0)]
        if self.originator_tax:
            yield 'tax_line_id', self.originator_tax.id


prepare_line = LineIntermediate


class AccountWinbizImport(models.TransientModel):
{'fraction_non_alphanumeric': 0.10417715148465023, 'fraction_numerical': 0.007800704579768495, 'mean_word_length': 2.3403361344537816, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3134425', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1160, 'n_words': 331}