2010-11-23 10:46:33 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp . osv import fields , osv
2010-11-23 10:46:33 +00:00
class account_sequence_installer ( osv . osv_memory ) :
_name = ' account.sequence.installer '
_inherit = ' res.config.installer '
2010-11-25 04:10:33 +00:00
2010-11-23 10:46:33 +00:00
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Name ' , required = True ) ,
' prefix ' : fields . char ( ' Prefix ' , size = 64 , help = " Prefix value of the record for the sequence " ) ,
' suffix ' : fields . char ( ' Suffix ' , size = 64 , help = " Suffix value of the record for the sequence " ) ,
2010-11-26 10:28:30 +00:00
' number_next ' : fields . integer ( ' Next Number ' , required = True , help = " Next number of this sequence " ) ,
' number_increment ' : fields . integer ( ' Increment Number ' , required = True , help = " The next number of the sequence will be incremented by this number " ) ,
2014-07-09 11:39:38 +00:00
' padding ' : fields . integer ( ' Number padding ' , required = True , help = " Odoo will automatically adds some ' 0 ' on the left of the ' Next Number ' to get the required padding size. " ) ,
2010-11-26 10:28:30 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' ) ,
}
_defaults = {
' company_id ' : lambda s , cr , uid , c : s . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' ir.sequence ' , context = c ) ,
' number_increment ' : 1 ,
' number_next ' : 1 ,
' padding ' : 0 ,
' name ' : ' Internal Sequence Journal ' ,
2010-11-25 04:10:33 +00:00
}
def execute ( self , cr , uid , ids , context = None ) :
2010-11-23 10:46:33 +00:00
if context is None :
context = { }
2010-12-13 06:43:09 +00:00
record = self . browse ( cr , uid , ids , context = context ) [ 0 ]
2010-11-25 04:10:33 +00:00
j_ids = [ ]
2010-11-26 10:28:30 +00:00
if record . company_id :
company_id = record . company_id . id ,
search_criteria = [ ( ' company_id ' , ' = ' , company_id ) ]
else :
company_id = False
search_criteria = [ ]
vals = {
' id ' : ' internal_sequence_journal ' ,
' code ' : ' account.journal ' ,
' name ' : record . name ,
' prefix ' : record . prefix ,
' suffix ' : record . suffix ,
' number_next ' : record . number_next ,
' number_increment ' : record . number_increment ,
' padding ' : record . padding ,
' company_id ' : company_id ,
}
2011-01-20 16:07:22 +00:00
obj_sequence = self . pool . get ( ' ir.sequence ' )
2010-11-26 10:28:30 +00:00
ir_seq = obj_sequence . create ( cr , uid , vals , context )
2010-11-25 04:10:33 +00:00
res = super ( account_sequence_installer , self ) . execute ( cr , uid , ids , context = context )
2011-01-20 16:07:22 +00:00
jou_obj = self . pool . get ( ' account.journal ' )
2010-11-26 10:28:30 +00:00
journal_ids = jou_obj . search ( cr , uid , search_criteria , context = context )
2010-12-13 06:43:09 +00:00
for journal in jou_obj . browse ( cr , uid , journal_ids , context = context ) :
2010-11-26 10:28:30 +00:00
if not journal . internal_sequence_id :
2010-11-25 04:10:33 +00:00
j_ids . append ( journal . id )
if j_ids :
2010-11-26 10:28:30 +00:00
jou_obj . write ( cr , uid , j_ids , { ' internal_sequence_id ' : ir_seq } )
2011-05-16 15:33:31 +00:00
ir_values_obj = self . pool . get ( ' ir.values ' )
ir_values_obj . set ( cr , uid , key = ' default ' , key2 = False , name = ' internal_sequence_id ' , models = [ ( ' account.journal ' , False ) ] , value = ir_seq )
2010-11-23 10:46:33 +00:00
return res
2010-11-25 04:10:33 +00:00
2010-11-23 10:46:33 +00:00
2010-11-26 10:28:30 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: