':context\'s key apply_taxes: set to True if you want vals[\'tax_ids\'] to result in the creation of move lines for taxes and eventual
adjustment of the line amount (in case of a tax included in price).
:context\'s key `check_move_validity`: check data consistency after move line creation. Eg. set to false to disable verification that the move
debit-credit == 0 while creating the move lines composing the move.'

@api.model
def create(self, vals):

    context = dict((self._context or {}))
    amount = (vals.get('debit', 0.0) - vals.get('credit', 0.0))
    if ((not vals.get('partner_id')) and context.get('partner_id')):
        vals['partner_id'] = context.get('partner_id')
    move = self.env['account.move'].browse(vals['move_id'])
    account = self.env['account.account'].browse(vals['account_id'])
    if account.deprecated:
        raise UserError(_('You    cannot    use    deprecated    account.'))
    if (('journal_id' in vals) and vals['journal_id']):
        context['journal_id'] = vals['journal_id']
    if (('date' in vals) and vals['date']):
        context['date'] = vals['date']
    if ('journal_id' not in context):
        context['journal_id'] = move.journal_id.id
        context['date'] = move.date
    if ((not context.get('journal_id', False)) and context.get('search_default_journal_id', False)):
        context['journal_id'] = context.get('search_default_journal_id')
    if ('date' not in context):
        context['date'] = fields.Date.context_today(self)
    journal = ((vals.get('journal_id') and self.env['account.journal'].browse(vals['journal_id'])) or move.journal_id)
    vals['date_maturity'] = (vals.get('date_maturity') or vals.get('date') or move.date)
    ok = (not (journal.type_control_ids or journal.account_control_ids))
    if journal.type_control_ids:
        type = account.user_type_id
        for t in journal.type_control_ids:
            if (type == t):
                ok = True
                break
    if (journal.account_control_ids and (not ok)):
        for a in journal.account_control_ids:
            if (a.id == vals['account_id']):
                ok = True
                break
    if (account.currency_id and ('amount_currency' not in vals) and (account.currency_id.id != account.company_id.currency_id.id)):
        vals['currency_id'] = account.currency_id.id
        if (self._context.get('skip_full_reconcile_check') == 'amount_currency_excluded'):
            vals['amount_currency'] = 0.0
        else:
            ctx = {}
            if ('date' in vals):
                ctx['date'] = vals['date']
            vals['amount_currency'] = account.company_id.currency_id.with_context(ctx).compute(amount, account.currency_id)
    if (not ok):
        raise UserError(_("You    cannot    use    this    general    account    in    this    journal,    check    the    tab    'Entry    Controls'    on    the    related    journal."))
    tax_lines_vals = []
    if (context.get('apply_taxes') and vals.get('tax_ids')):
        tax_ids = [tax['id'] for tax in self.resolve_2many_commands('tax_ids', vals['tax_ids']) if tax.get('id')]
        taxes = self.env['account.tax'].browse(tax_ids)
        currency = self.env['res.currency'].browse(vals.get('currency_id'))
        partner = self.env['res.partner'].browse(vals.get('partner_id'))
        res = taxes.with_context(round=True).compute_all(amount, currency, 1, vals.get('product_id'), partner)
        if (abs(res['total_excluded']) < abs(amount)):
            if (vals['debit'] != 0.0):
                vals['debit'] = res['total_excluded']
            if (vals['credit'] != 0.0):
                vals['credit'] = (- res['total_excluded'])
            if vals.get('amount_currency'):
                vals['amount_currency'] = self.env['res.currency'].browse(vals['currency_id']).round((vals['amount_currency'] * (res['total_excluded'] / amount)))
        for tax_vals in res['taxes']:
            if tax_vals['amount']:
                tax = self.env['account.tax'].browse([tax_vals['id']])
                account_id = (((amount > 0) and tax_vals['account_id']) or tax_vals['refund_account_id'])
                if (not account_id):
                    account_id = vals['account_id']
                temp = {'account_id': account_id, 'name': ((vals['name'] + '    ') + tax_vals['name']), 'tax_line_id': tax_vals['id'], 'move_id': vals['move_id'], 'partner_id': vals.get('partner_id'), 'statement_id': vals.get('statement_id'), 'debit': (((tax_vals['amount'] > 0) and tax_vals['amount']) or 0.0), 'credit': (((tax_vals['amount'] < 0) and (- tax_vals['amount'])) or 0.0), 'analytic_account_id': (vals.get('analytic_account_id') if tax.analytic else False)}
                bank = self.env['account.bank.statement'].browse(vals.get('statement_id'))
                if (bank.currency_id != bank.company_id.currency_id):
                    ctx = {}
                    if ('date' in vals):
                        ctx['date'] = vals['date']
                    temp['currency_id'] = bank.currency_id.id
                    temp['amount_currency'] = bank.company_id.currency_id.with_context(ctx).compute(tax_vals['amount'], bank.currency_id, round=True)
                tax_lines_vals.append(temp)
    new_line = super(AccountMoveLine, self).create(vals)
    for tax_line_vals in tax_lines_vals:
        self.with_context(context).create(tax_line_vals)
    if self._context.get('check_move_validity', True):
        move.with_context(context)._post_validate()
    return new_line
