# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import fields, api, models, _


class account_journal_create_wizard(models.TransientModel):
    _inherit = 'account.journal.create.wizard'

    type = fields.Selection(
        selection_add=[
            ('issue_check', 'Issue Check'),
            ('third_check', 'Third Check'),
            ],
        )

    @api.multi
    def _get_vals(self, invoice_subtype=False):
        # TODO mejorar para que no haya ue sobreescribir tantas cosas
        vals = super(account_journal_create_wizard, self)._get_vals(
            invoice_subtype)
        if self.type in ('issue_check', 'third_check'):
            if self.type == 'issue_check':
                domain = [('check_type', '=', 'issue')]
                check_type = 'issue'
                code = _('CHP')
                name = _('Cheques Propios')
                journal_type = 'bank'
            elif self.type == 'third_check':
                check_type = 'third'
                domain = [('check_type', '=', 'third')]
                code = _('CHT')
                name = _('Cheques Terceros')
                journal_type = 'bank'
            domain += [
                ('type', '=', journal_type),
                ('company_id', '=', self.company_id.id)]
            journals = self.env['account.journal'].search(domain)
            next_number = len(journals) + 1

            if self.currency_id:
                name = '%s %s' % (name, self.currency_id.name)

            account_name = name
            if self.name_sufix:
                name = '%s (%s)' % (name, self.name_sufix)
                account_name = '%s %s' % (account_name, self.name_sufix)

            # if none, we create one and use for debit credit
            if not self.default_debit_account_id and not (
                    self.default_credit_account_id):
                account = self.env['account.account'].create(
                    self._get_account_vals(account_name))
                self.default_credit_account_id = account.id
                self.default_debit_account_id = account.id
            # if not debit, we use credit
            elif not self.default_credit_account_id:
                self.default_credit_account_id = self.default_debit_account_id
            # if not credit, we use debit
            elif not self.default_debit_account_id:
                self.default_debit_account_id = self.default_credit_account_id

            vals.update({
                'type': journal_type,
                'name': name,
                'validate_only_checks': True,
                'check_type': check_type,
                'code': '%s%02d' % (code, next_number),
            })
        return vals

@@ -933,38 +933,43 @@
     domain = %5B('
-check_
+payment_sub
 type', '=', 'iss
@@ -970,16 +970,22 @@
 , 'issue
+_check
 ')%5D%0A    
@@ -988,38 +988,43 @@
                 
-check_
+payment_sub
 type = 'issue'%0A 
@@ -1020,16 +1020,22 @@
 = 'issue
+_check
 '%0A      
@@ -1203,22 +1203,27 @@
         
-check_
+payment_sub
 type = '
@@ -1227,16 +1227,22 @@
 = 'third
+_check
 '%0A      
@@ -1263,22 +1263,27 @@
 in = %5B('
-check_
+payment_sub
 type', '
@@ -1292,16 +1292,22 @@
 , 'third
+_check
 ')%5D%0A    
@@ -2879,22 +2879,27 @@
 _type': 
-check_
+payment_sub
 type,%0A  

FIX payment_subtype on checks creations