# -*- encoding: 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/>.
#
##############################################################################

import time
from osv import osv, fields
from tools.translate import _
import decimal_precision as dp
from tools import float_round, float_is_zero, float_compare

class change_journal_si(osv.osv_memory):
    _name = 'change.journal.si'
    _description = 'Change Journal SI'

    def do_validate(self, cr, uid, ids, context=None):
        account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        for obj in self.browse(cr, uid, ids, context=context):

            
            move_id = account_invoice_obj.browse(cr, uid, context.get(('active_ids'), [])[0], context).move_id and \
                        account_invoice_obj.browse(cr, uid, context.get(('active_ids'), [])[0], context).move_id.id or \
                        False
#            raise osv.except_osv(_('Error !'), _(str(context.get(('active_ids'), [])[0])))
            if move_id:
                account_move_obj.write(cr, uid, [move_id], {'journal_id': obj.journal_id.id}, context=context)
                account_invoice_obj.write(cr, uid, context.get(('active_ids'), []), {'journal_id': obj.journal_id.id}, context=context)
        return {'type': 'ir.actions.act_window_close'}

    def do_validate2(self, cr, uid, ids, context=None):
        account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        for obj in self.browse(cr, uid, ids, context=context):

            
            move_id = account_invoice_obj.browse(cr, uid, context.get(('active_ids'), [])[0], context).move_id and \
                        account_invoice_obj.browse(cr, uid, context.get(('active_ids'), [])[0], context).move_id.id or \
                        False

            if move_id:
                account_move_obj.write(cr, uid, [move_id], {'period_id': obj.period_id.id, 'date': obj.date_invoice}, context=context)
                account_invoice_obj.write(cr, uid, context.get(('active_ids'), []), {'period_id': obj.period_id.id, 'date_invoice': obj.date_invoice}, context=context)
        return {'type': 'ir.actions.act_window_close'}

    def do_plus_one(self, cr, uid, ids, context=None):
#UPV0166/13 PIN1819/13
#UPV0167/13 PIN1818/13
#UPV0168/13 PIN1607/13
#UPV0178/13 PIN0985/13
#UPV0195/13 PIN1817/13
        account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        account_move_line_obj = self.pool.get('account.move.line')
        name2 = []

        name2.append('PIN1704/13-A')
        name2.append('PIN1704/13-B')
        name2.append('PIN1608/13-A')
        name2.append('PIN1836/13-A')
        name2.append('PIN1836/13-B')

        ids = account_move_obj.search(cr, uid, [('name','in',name2)], context=context)
        account_moves = account_move_obj.browse(cr, uid, ids, context=context)
        for line in account_moves:
            account_id = account_invoice_obj.browse(cr, uid, account_invoice_obj.search(cr, uid, [('move_id','=',line.id)], context=context)[0], context=context).account_id.id
            for move_line in line.line_id:
                if move_line.account_id.id == account_id:
                    credit = float_round(move_line.credit + 0.01, 2)
                    account_move_line_obj.write(cr, uid, [move_line.id], {'credit': credit}, context=context, check=False, update_check=False)
#        raise osv.except_osv(_('Error !'), _(str(data_id) + 'xxx' + str(data_name)))
        return {'type': 'ir.actions.act_window_close'}
    
    def do_validate3(self, cr, uid, ids, context=None):
        #account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        account_move_line_obj = self.pool.get('account.move.line')
        #data_name = []
        #data_id =[]
        name2 = []
        name2.append('OSBJ/2013/0001')

        ids = account_move_obj.search(cr, uid, [('name','in',name2)], context=context)
        account_moves = account_move_obj.browse(cr, uid, ids, context=context)
        for line in account_moves:
            for move_line in line.line_id:
                debit = float_round(move_line.debit,2)
                credit = float_round(move_line.credit,2)
                #tax_amount = float_round(move_line.tax_amount,2)
                account_move_line_obj.write(cr, uid, [move_line.id], {'debit': debit, 'credit': credit}, context=context, check=False, update_check=False)
#        raise osv.except_osv(_('Error !'), _(str(data_id) + 'xxx' + str(data_name)))
        return {'type': 'ir.actions.act_window_close'}

    def do_ci_checking(self, cr, uid, ids, context=None):
        account_move_obj = self.pool.get('account.move')
        account_move_line_obj = self.pool.get('account.move.line')
        for obj in self.browse(cr, uid, ids, context=context):
            journal_id = obj.journal_id.id
        ids = account_move_obj.search(cr, uid, [('journal_id','=',journal_id)], context=context)
        account_moves = account_move_obj.browse(cr, uid, ids, context=context)
        name2 = []
        for line in account_moves:
            amount = int(float_round(line.amount, 5) * 100000)
            amount2 = str(amount)
            char_count = len(amount2) - 3
            amount2 = amount2[:char_count]
            amount2 = int(amount2) * 1000
            if amount - int(amount2) != 0:
                name2.append(line.id)
        #raise osv.except_osv(_('Error !'), _(str(name2) + 'xxx'))
        move_ids = account_move_obj.search(cr, uid, [('id','in',name2)], context=context)
        acc_moves = account_move_obj.browse(cr, uid, move_ids, context=context)
        for m_ids in acc_moves:
            for am_line in m_ids.line_id:
                debit = float_round(am_line.debit,2)
                credit = float_round(am_line.credit,2)
                tax_amount = float_round(am_line.tax_amount,2)
                account_move_line_obj.write(cr, uid, [am_line.id], {'debit': debit, 'credit': credit, 'tax_amount': tax_amount}, context=context, check=False, update_check=False)

#        move_ids_ret = account_move_obj.search(cr, uid, [('name','=','RCN0034/13')], context=context)
#        acc_moves_ret = account_move_obj.browse(cr, uid, move_ids_ret, context=context)
#        for m_ids_ret in acc_moves_ret:
#            for am_line_ret in m_ids_ret.line_id:
#                debit_ret = float_round(am_line_ret.debit,2)
#                credit_ret = float_round(am_line_ret.credit,2)
#                tax_amount_ret = float_round(am_line_ret.tax_amount,2)
#                account_move_line_obj.write(cr, uid, [am_line_ret.id], {'debit': debit_ret, 'credit': credit_ret, 'tax_amount': tax_amount_ret}, context=context, check=False, update_check=False)

        #raise osv.except_osv(_('Error !'), _(str(move_ids)))

        return {'type': 'ir.actions.act_window_close'}

    def do_ci_checking2(self, cr, uid, ids, context=None):
        name = []
        name2 = []
        account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        account_move_line_obj = self.pool.get('account.move.line')

        ids = account_move_obj.search(cr, uid, [('id','in',[9768, 9719])], context=context)
        account_moves = account_move_obj.browse(cr, uid, ids, context=context)
        for line in account_moves:
            account_id = account_invoice_obj.browse(cr, uid, account_invoice_obj.search(cr, uid, [('move_id','=',line.id)], context=context)[0], context=context).account_id.id
            for move_line in line.line_id:
                if move_line.account_id.id == account_id:
                    debit = float_round(move_line.debit + 0.01, 2)
                    account_move_line_obj.write(cr, uid, [move_line.id], {'debit': debit}, context=context, check=False, update_check=False)
#        raise osv.except_osv(_('Error !'), _(str(data_id) + 'xxx' + str(data_name)))


        return {'type': 'ir.actions.act_window_close'}

    def do_validate5(self, cr, uid, ids, context=None):
        account_invoice_obj = self.pool.get('account.invoice')
        invoice_ids = account_invoice_obj.search(cr, uid, [], context=None)
        invoices = account_invoice_obj.browse(cr, uid, invoice_ids, context=context)
#        raise osv.except_osv(_('Error !'), _(str('amount_untaxed_home') + 'xxx' + str('amount_tax_home')))
        for invoice in invoices:
            amount_untaxed_home = 0
            amount_tax_home = 0
            amount_total_home = 0
            for line in invoice.invoice_line:
                amount_untaxed_home += (line.price_subtotal)
            for line in invoice.tax_line:
                amount_tax_home += line.amount
            ctx = context.copy()
            ctx.update({'date': invoice.cur_date})
            invoice_rate = invoice.currency_id.rate
            company_currency_rate = invoice.company_id.currency_id.rate
            if invoice.company_id.currency_id.id != invoice.currency_id.id:
                amount_tax_home = float_round(amount_tax_home / invoice_rate * company_currency_rate,2)
                amount_untaxed_home = float_round(amount_untaxed_home / invoice_rate * company_currency_rate,2)
            amount_total_home = amount_tax_home + amount_untaxed_home
#            raise osv.except_osv(_('Error !'), _(str(amount_untaxed_home) + 'xxx' + str(amount_tax_home)))
            account_invoice_obj.write(cr, uid, invoice.id, {'amount_tax_home': amount_untaxed_home, 'amount_untaxed_home': amount_untaxed_home, 'amount_total_home':amount_total_home}, context=context)
            
#        raise osv.except_osv(_('Error !'), _(str(data_id) + 'xxx' + str(data_name)))
        return {'type': 'ir.actions.act_window_close'}

    def _write_line(self, cr, uid, sm_id,  invoice_line_id, context=None):
        account_invoice_line_obj = self.pool.get('account.invoice.line')
        account_invoice_line_obj.write(cr, uid, invoice_line_id, {'stock_move_id': sm_id}, context=None)
        return True
    

    def write_move_id2(self, cr, uid, ids, context=None):
        self._write_line(cr, uid, 8758, 4096, context=None)
        self._write_line(cr, uid, 8759, 4097, context=None)
        self._write_line(cr, uid, 3998, 4091, context=None)
        self._write_line(cr, uid, 4000, 4090, context=None)
        self._write_line(cr, uid, 6289, 4078, context=None)
        self._write_line(cr, uid, 6290, 4079, context=None)
        self._write_line(cr, uid, 6291, 4080, context=None)
        self._write_line(cr, uid, 6293, 4073, context=None)
        self._write_line(cr, uid, 6294, 4074, context=None)
        self._write_line(cr, uid, 6295, 4075, context=None)
        self._write_line(cr, uid, 6296, 4076, context=None)
        self._write_line(cr, uid, 3994, 4071, context=None)
        self._write_line(cr, uid, 3995, 4072, context=None)
        self._write_line(cr, uid, 6297, 4066, context=None)
        self._write_line(cr, uid, 6298, 4067, context=None)
        self._write_line(cr, uid, 6300, 4069, context=None)
        self._write_line(cr, uid, 6301, 4070, context=None)
        self._write_line(cr, uid, 4929, 4145, context=None)
        self._write_line(cr, uid, 4930, 4146, context=None)
        self._write_line(cr, uid, 6304, 4063, context=None)
        self._write_line(cr, uid, 6305, 4064, context=None)
        self._write_line(cr, uid, 6306, 4060, context=None)
        self._write_line(cr, uid, 6307, 4061, context=None)
        self._write_line(cr, uid, 3932, 4023, context=None)
        self._write_line(cr, uid, 3933, 4024, context=None)
        self._write_line(cr, uid, 3935, 4025, context=None)
        self._write_line(cr, uid, 3936, 4026, context=None)
        self._write_line(cr, uid, 3918, 4011, context=None)
        self._write_line(cr, uid, 3919, 4012, context=None)
        self._write_line(cr, uid, 6349, 3999, context=None)
        self._write_line(cr, uid, 6350, 4000, context=None)
        self._write_line(cr, uid, 6533, 3965, context=None)
        self._write_line(cr, uid, 6534, 3966, context=None)
        self._write_line(cr, uid, 6535, 3967, context=None)
        self._write_line(cr, uid, 6537, 3969, context=None)
        self._write_line(cr, uid, 6539, 3971, context=None)
        self._write_line(cr, uid, 6541, 3973, context=None)
        self._write_line(cr, uid, 6545, 3977, context=None)
        self._write_line(cr, uid, 6546, 3978, context=None)
        self._write_line(cr, uid, 6551, 3983, context=None)
        self._write_line(cr, uid, 6553, 3985, context=None)
        self._write_line(cr, uid, 6554, 3986, context=None)
        self._write_line(cr, uid, 6555, 3987, context=None)
        self._write_line(cr, uid, 6556, 3988, context=None)
        self._write_line(cr, uid, 6560, 3992, context=None) 
        self._write_line(cr, uid, 6562, 3994, context=None)
        self._write_line(cr, uid, 6563, 3995, context=None)
        self._write_line(cr, uid, 6536, 3968, context=None)
        self._write_line(cr, uid, 6540, 3972, context=None)
        self._write_line(cr, uid, 6542, 3974, context=None)
        self._write_line(cr, uid, 6547, 3979, context=None)
        self._write_line(cr, uid, 6548, 3980, context=None)
        self._write_line(cr, uid, 6557, 3989, context=None)
        self._write_line(cr, uid, 6558, 3990, context=None)
        self._write_line(cr, uid, 6564, 3996, context=None)
        self._write_line(cr, uid, 6565, 3997, context=None)
        self._write_line(cr, uid, 6538, 3970, context=None)
        self._write_line(cr, uid, 6543, 3975, context=None)
        self._write_line(cr, uid, 6544, 3976, context=None)
        self._write_line(cr, uid, 6549, 3981, context=None)
        self._write_line(cr, uid, 6550, 3982, context=None)
        self._write_line(cr, uid, 6552, 3984, context=None)
        self._write_line(cr, uid, 6559, 3991, context=None)
        self._write_line(cr, uid, 6561, 3993, context=None)
        self._write_line(cr, uid, 4470, 3961, context=None)
        self._write_line(cr, uid, 4471, 3962, context=None)
        self._write_line(cr, uid, 4053, 3936, context=None)
        self._write_line(cr, uid, 4054, 3937, context=None)
        self._write_line(cr, uid, 4064, 3928, context=None)
        self._write_line(cr, uid, 4071, 3920, context=None)
        self._write_line(cr, uid, 4062, 3925, context=None)
        self._write_line(cr, uid, 4067, 3929, context=None)
        self._write_line(cr, uid, 4063, 3926, context=None)
        self._write_line(cr, uid, 4065, 3927, context=None)
        self._write_line(cr, uid, 3682, 3914, context=None)
        self._write_line(cr, uid, 3683, 3915, context=None)
        self._write_line(cr, uid, 3684, 3916, context=None)
        self._write_line(cr, uid, 3685, 3917, context=None)
        self._write_line(cr, uid, 3680, 3912, context=None)
        self._write_line(cr, uid, 3679, 3911, context=None) 
        self._write_line(cr, uid, 4076, 3895, context=None)
        self._write_line(cr, uid, 4079, 3896, context=None)
        self._write_line(cr, uid, 4080, 3898, context=None)
        self._write_line(cr, uid, 6530, 3884, context=None)
        self._write_line(cr, uid, 6531, 3883, context=None)
        self._write_line(cr, uid, 6532, 3885, context=None)
        self._write_line(cr, uid, 6528, 3874, context=None)
        self._write_line(cr, uid, 6529, 3873, context=None)
        self._write_line(cr, uid, 6525, 3871, context=None)
        self._write_line(cr, uid, 6526, 3872, context=None)
        self._write_line(cr, uid, 6527, 3868, context=None)
        self._write_line(cr, uid, 6520, 3875, context=None)
        self._write_line(cr, uid, 6522, 3877, context=None)
        self._write_line(cr, uid, 6523, 3869, context=None)
        self._write_line(cr, uid, 6517, 3878, context=None)
        self._write_line(cr, uid, 6518, 3879, context=None)
        self._write_line(cr, uid, 6519, 3880, context=None)
        self._write_line(cr, uid, 6515, 3881, context=None)
        self._write_line(cr, uid, 6516, 3882, context=None)
        self._write_line(cr, uid, 6422, 3856, context=None)
        self._write_line(cr, uid, 6423, 3857, context=None)
        self._write_line(cr, uid, 6473, 3803, context=None)
        self._write_line(cr, uid, 6476, 3806, context=None)
        self._write_line(cr, uid, 6477, 3807, context=None)
        self._write_line(cr, uid, 6483, 3813, context=None)
        self._write_line(cr, uid, 6486, 3816, context=None)
        self._write_line(cr, uid, 6487, 3817, context=None)
        self._write_line(cr, uid, 6493, 3823, context=None)
        self._write_line(cr, uid, 6496, 3826, context=None)
        self._write_line(cr, uid, 6503, 3833, context=None)
        self._write_line(cr, uid, 6504, 3834, context=None)
        self._write_line(cr, uid, 6505, 3835, context=None)
        self._write_line(cr, uid, 6474, 3804, context=None)
        self._write_line(cr, uid, 6484, 3814, context=None)
        self._write_line(cr, uid, 6485, 3815, context=None)
        self._write_line(cr, uid, 6488, 3818, context=None)
        self._write_line(cr, uid, 6497, 3827, context=None)
        self._write_line(cr, uid, 6498, 3828, context=None)
        self._write_line(cr, uid, 6502, 3832, context=None)
        self._write_line(cr, uid, 6506, 3836, context=None)
        self._write_line(cr, uid, 6511, 3841, context=None)
        self._write_line(cr, uid, 6475, 3805, context=None)
        self._write_line(cr, uid, 6478, 3808, context=None)
        self._write_line(cr, uid, 6479, 3809, context=None)
        self._write_line(cr, uid, 6480, 3810, context=None)
        self._write_line(cr, uid, 6481, 3811, context=None)
        self._write_line(cr, uid, 6482, 3812, context=None)
        self._write_line(cr, uid, 6489, 3819, context=None)
        self._write_line(cr, uid, 6490, 3820, context=None)
        self._write_line(cr, uid, 6491, 3821, context=None)
        self._write_line(cr, uid, 6492, 3822, context=None)
        self._write_line(cr, uid, 6494, 3824, context=None)
        self._write_line(cr, uid, 6495, 3825, context=None)
        self._write_line(cr, uid, 6499, 3829, context=None)
        self._write_line(cr, uid, 6500, 3830, context=None)
        self._write_line(cr, uid, 6501, 3831, context=None)
        self._write_line(cr, uid, 6507, 3837, context=None)
        self._write_line(cr, uid, 6508, 3838, context=None)
        self._write_line(cr, uid, 6509, 3839, context=None)
        self._write_line(cr, uid, 6510, 3840, context=None)
        self._write_line(cr, uid, 3394, 3800, context=None)
        self._write_line(cr, uid, 3395, 3801, context=None)
        self._write_line(cr, uid, 3386, 3796, context=None)
        self._write_line(cr, uid, 3387, 3797, context=None)
        self._write_line(cr, uid, 3831, 3771, context=None)
        self._write_line(cr, uid, 3834, 3773, context=None)
        self._write_line(cr, uid, 3826, 3783, context=None)
        self._write_line(cr, uid, 3832, 3772, context=None)
        self._write_line(cr, uid, 3538, 3732, context=None)
        self._write_line(cr, uid, 3539, 3733, context=None)
        self._write_line(cr, uid, 3540, 3734, context=None)
        self._write_line(cr, uid, 3541, 3735, context=None)
        self._write_line(cr, uid, 3794, 3725, context=None)
        self._write_line(cr, uid, 3795, 3726, context=None)
        self._write_line(cr, uid, 3245, 3718, context=None)
        self._write_line(cr, uid, 3246, 3715, context=None)
        self._write_line(cr, uid, 3247, 3716, context=None)
        self._write_line(cr, uid, 3226, 3707, context=None)
        self._write_line(cr, uid, 3227, 3708, context=None)
        self._write_line(cr, uid, 3203, 3699, context=None)
        self._write_line(cr, uid, 3204, 3700, context=None)
        self._write_line(cr, uid, 3788, 3696, context=None)
        self._write_line(cr, uid, 3790, 3694, context=None)
        self._write_line(cr, uid, 3789, 3697, context=None)
        self._write_line(cr, uid, 3791, 3695, context=None)
        self._write_line(cr, uid, 6229, 3663, context=None)
        self._write_line(cr, uid, 6230, 3664, context=None)
        self._write_line(cr, uid, 6231, 3665, context=None)
        self._write_line(cr, uid, 6232, 3673, context=None)
        self._write_line(cr, uid, 6235, 3666, context=None)
        self._write_line(cr, uid, 6236, 3667, context=None)
        self._write_line(cr, uid, 6233, 3674, context=None)
        self._write_line(cr, uid, 6237, 3668, context=None)
        self._write_line(cr, uid, 6238, 3669, context=None)
        self._write_line(cr, uid, 6239, 3670, context=None)
        self._write_line(cr, uid, 6240, 3671, context=None)
        self._write_line(cr, uid, 6234, 3675, context=None)
        self._write_line(cr, uid, 6241, 3672, context=None)
        self._write_line(cr, uid, 6225, 3677, context=None)
        self._write_line(cr, uid, 6227, 3679, context=None)
        self._write_line(cr, uid, 6224, 3676, context=None)
        self._write_line(cr, uid, 6226, 3678, context=None)
        self._write_line(cr, uid, 6222, 3680, context=None)
        self._write_line(cr, uid, 6223, 3681, context=None)
        self._write_line(cr, uid, 6228, 3682, context=None)
        self._write_line(cr, uid, 6216, 3685, context=None)
        self._write_line(cr, uid, 6217, 3686, context=None)
        self._write_line(cr, uid, 6218, 3687, context=None)
        self._write_line(cr, uid, 6219, 3688, context=None)
        self._write_line(cr, uid, 6197, 3658, context=None)
        self._write_line(cr, uid, 6198, 3659, context=None)
        self._write_line(cr, uid, 6199, 3660, context=None)
        self._write_line(cr, uid, 6200, 3661, context=None)
        self._write_line(cr, uid, 6201, 3662, context=None)
        self._write_line(cr, uid, 3173, 3637, context=None)
        self._write_line(cr, uid, 3176, 3635, context=None)
        self._write_line(cr, uid, 6122, 3631, context=None)
        self._write_line(cr, uid, 6121, 3630, context=None)
        self._write_line(cr, uid, 6124, 3627, context=None)
        self._write_line(cr, uid, 6125, 3628, context=None)
        self._write_line(cr, uid, 3781, 3613, context=None)
        self._write_line(cr, uid, 3785, 3609, context=None)
        self._write_line(cr, uid, 6043, 3578, context=None)
        self._write_line(cr, uid, 6044, 3572, context=None)
        self._write_line(cr, uid, 6047, 3601, context=None)
        self._write_line(cr, uid, 6051, 3564, context=None)
        self._write_line(cr, uid, 6058, 3571, context=None)
        self._write_line(cr, uid, 6059, 3573, context=None)
        self._write_line(cr, uid, 6060, 3577, context=None)
        self._write_line(cr, uid, 6064, 3587, context=None)
        self._write_line(cr, uid, 6065, 3605, context=None)
        self._write_line(cr, uid, 6074, 3589, context=None)
        self._write_line(cr, uid, 6075, 3588, context=None)
        self._write_line(cr, uid, 6076, 3593, context=None)
        self._write_line(cr, uid, 6080, 3594, context=None)
        self._write_line(cr, uid, 6081, 3602, context=None)
        self._write_line(cr, uid, 6037, 3565, context=None)
        self._write_line(cr, uid, 6038, 3574, context=None)
        self._write_line(cr, uid, 6066, 3579, context=None)
        self._write_line(cr, uid, 6068, 3580, context=None)
        self._write_line(cr, uid, 6069, 3581, context=None)
        self._write_line(cr, uid, 6070, 3566, context=None)
        self._write_line(cr, uid, 6041, 3599, context=None)


        self._write_line(cr, uid, 6045, 3603, context=None)
        self._write_line(cr, uid, 6048, 3582, context=None)
        self._write_line(cr, uid, 6052, 3595, context=None)
        self._write_line(cr, uid, 6053, 3567, context=None)
        self._write_line(cr, uid, 6054, 3583, context=None)
        self._write_line(cr, uid, 6061, 3596, context=None)
        self._write_line(cr, uid, 6067, 3606, context=None)
        self._write_line(cr, uid, 6077, 3590, context=None)
        self._write_line(cr, uid, 6078, 3591, context=None)
        self._write_line(cr, uid, 6071, 3568, context=None)
        self._write_line(cr, uid, 6072, 3585, context=None)
        self._write_line(cr, uid, 6073, 3569, context=None)
        self._write_line(cr, uid, 6039, 3570, context=None)
        self._write_line(cr, uid, 6040, 3575, context=None)
        self._write_line(cr, uid, 6042, 3586, context=None)
        self._write_line(cr, uid, 6046, 3576, context=None)
        self._write_line(cr, uid, 6049, 3592, context=None)
        self._write_line(cr, uid, 6050, 3598, context=None)
        self._write_line(cr, uid, 6055, 3584, context=None)
        self._write_line(cr, uid, 6056, 3600, context=None)
        self._write_line(cr, uid, 6057, 3597, context=None)
        self._write_line(cr, uid, 6062, 3607, context=None)
        self._write_line(cr, uid, 6063, 3604, context=None)
        self._write_line(cr, uid, 6079, 3608, context=None)
        self._write_line(cr, uid, 3472, 3559, context=None)
        self._write_line(cr, uid, 3471, 3558, context=None)
        self._write_line(cr, uid, 3469, 3556, context=None)
        self._write_line(cr, uid, 3470, 3557, context=None)
        self._write_line(cr, uid, 3466, 3553, context=None)
        self._write_line(cr, uid, 3467, 3554, context=None)
        self._write_line(cr, uid, 3468, 3555, context=None)
        self._write_line(cr, uid, 3141, 3551, context=None)
        self._write_line(cr, uid, 3142, 3552, context=None)
        self._write_line(cr, uid, 3464, 3548, context=None)
        self._write_line(cr, uid, 3465, 3549, context=None)
        self._write_line(cr, uid, 3459, 3538, context=None)
        self._write_line(cr, uid, 3458, 3537, context=None)
        self._write_line(cr, uid, 6180, 3524, context=None)
        self._write_line(cr, uid, 6181, 3525, context=None)
        self._write_line(cr, uid, 6189, 3517, context=None)
        self._write_line(cr, uid, 6190, 3518, context=None)
        self._write_line(cr, uid, 6204, 3511, context=None)
        self._write_line(cr, uid, 6208, 3501, context=None)
        self._write_line(cr, uid, 6213, 3504, context=None)
        self._write_line(cr, uid, 6214, 3505, context=None)
        self._write_line(cr, uid, 6205, 3506, context=None)
        self._write_line(cr, uid, 6206, 3507, context=None)
        self._write_line(cr, uid, 6207, 3508, context=None)
        self._write_line(cr, uid, 6120, 3509, context=None)
        self._write_line(cr, uid, 6211, 3510, context=None)
        self._write_line(cr, uid, 3770, 3485, context=None)
        self._write_line(cr, uid, 3771, 3486, context=None)
        self._write_line(cr, uid, 3772, 3487, context=None)
        self._write_line(cr, uid, 3760, 3498, context=None)
        self._write_line(cr, uid, 3768, 3489, context=None)
        self._write_line(cr, uid, 3761, 3499, context=None)
        self._write_line(cr, uid, 3758, 3490, context=None)
        self._write_line(cr, uid, 3769, 3496, context=None)
        self._write_line(cr, uid, 5170, 3474, context=None)
        self._write_line(cr, uid, 5171, 3475, context=None)
        self._write_line(cr, uid, 5172, 3476, context=None)
        self._write_line(cr, uid, 5173, 3477, context=None)
        self._write_line(cr, uid, 5168, 3478, context=None)
        self._write_line(cr, uid, 5169, 3479, context=None)
        self._write_line(cr, uid, 3034, 3467, context=None)
        self._write_line(cr, uid, 3035, 3466, context=None)
        self._write_line(cr, uid, 3740, 3459, context=None)
        self._write_line(cr, uid, 3741, 3460, context=None)
        self._write_line(cr, uid, 5181, 3448, context=None)
        self._write_line(cr, uid, 5179, 3446, context=None)
        self._write_line(cr, uid, 5180, 3447, context=None)
        self._write_line(cr, uid, 3442, 3411, context=None)
        self._write_line(cr, uid, 3441, 3410, context=None)
        self._write_line(cr, uid, 3752, 3408, context=None)
        self._write_line(cr, uid, 3753, 3407, context=None)
        self._write_line(cr, uid, 3751, 3409, context=None)
        self._write_line(cr, uid, 2863, 3401, context=None)
        self._write_line(cr, uid, 2862, 3402, context=None)
        self._write_line(cr, uid, 3432, 3394, context=None)
        self._write_line(cr, uid, 3433, 3395, context=None)
        self._write_line(cr, uid, 2809, 3382, context=None)
        self._write_line(cr, uid, 2808, 3381, context=None)
        self._write_line(cr, uid, 2807, 3383, context=None)
        self._write_line(cr, uid, 2801, 3378, context=None)
        self._write_line(cr, uid, 2802, 3379, context=None)
        self._write_line(cr, uid, 3618, 3370, context=None)
        self._write_line(cr, uid, 3622, 3367, context=None)
        self._write_line(cr, uid, 3617, 3371, context=None)
        self._write_line(cr, uid, 3621, 3373, context=None)
        self._write_line(cr, uid, 5017, 3316, context=None)
        self._write_line(cr, uid, 4996, 3352, context=None)
        self._write_line(cr, uid, 4997, 3344, context=None)
        self._write_line(cr, uid, 4999, 3355, context=None)
        self._write_line(cr, uid, 5000, 3340, context=None)
        self._write_line(cr, uid, 5009, 3319, context=None)
        self._write_line(cr, uid, 5012, 3320, context=None)
        self._write_line(cr, uid, 5013, 3322, context=None)
        self._write_line(cr, uid, 5015, 3324, context=None)
        self._write_line(cr, uid, 4971, 3327, context=None)
        self._write_line(cr, uid, 4972, 3328, context=None)
        self._write_line(cr, uid, 4979, 3335, context=None)
        self._write_line(cr, uid, 4980, 3336, context=None)
        self._write_line(cr, uid, 4984, 3356, context=None)
        self._write_line(cr, uid, 4988, 3353, context=None)
        self._write_line(cr, uid, 4989, 3345, context=None)
        self._write_line(cr, uid, 5016, 3321, context=None)
        self._write_line(cr, uid, 4994, 3358, context=None)
        self._write_line(cr, uid, 5001, 3331, context=None)
        self._write_line(cr, uid, 5002, 3350, context=None)
        self._write_line(cr, uid, 5007, 3330, context=None)
        self._write_line(cr, uid, 5010, 3318, context=None)
        self._write_line(cr, uid, 5011, 3317, context=None)
        self._write_line(cr, uid, 5014, 3323, context=None)
        self._write_line(cr, uid, 4973, 3329, context=None)
        self._write_line(cr, uid, 4974, 3342, context=None)
        self._write_line(cr, uid, 4975, 3357, context=None)
        self._write_line(cr, uid, 4981, 3337, context=None)
        self._write_line(cr, uid, 4985, 3341, context=None)
        self._write_line(cr, uid, 4986, 3363, context=None)
        self._write_line(cr, uid, 4990, 3346, context=None)
        self._write_line(cr, uid, 4991, 3347, context=None)
        self._write_line(cr, uid, 4992, 3326, context=None)
        self._write_line(cr, uid, 4993, 3349, context=None)
        self._write_line(cr, uid, 4995, 3332, context=None)
        self._write_line(cr, uid, 4998, 3343, context=None)
        self._write_line(cr, uid, 5003, 3325, context=None)
        self._write_line(cr, uid, 5004, 3333, context=None)
        self._write_line(cr, uid, 5005, 3334, context=None)
        self._write_line(cr, uid, 5006, 3339, context=None)
        self._write_line(cr, uid, 5008, 3364, context=None)
        self._write_line(cr, uid, 4969, 3359, context=None)
        self._write_line(cr, uid, 4970, 3338, context=None)
        self._write_line(cr, uid, 4976, 3348, context=None)
        self._write_line(cr, uid, 4977, 3351, context=None)
        self._write_line(cr, uid, 4978, 3360, context=None)
        self._write_line(cr, uid, 4982, 3361, context=None)
        self._write_line(cr, uid, 4983, 3362, context=None)
        self._write_line(cr, uid, 4987, 3354, context=None)
        self._write_line(cr, uid, 2842, 3296, context=None)
        self._write_line(cr, uid, 2843, 3297, context=None)
        self._write_line(cr, uid, 2760, 3256, context=None)
        self._write_line(cr, uid, 2761, 3257, context=None)
        self._write_line(cr, uid, 2755, 3245, context=None)
        self._write_line(cr, uid, 2756, 3246, context=None)
        self._write_line(cr, uid, 6008, 3229, context=None)
        self._write_line(cr, uid, 6009, 3230, context=None)
        self._write_line(cr, uid, 6011, 3232, context=None)
        self._write_line(cr, uid, 6012, 3233, context=None)
        self._write_line(cr, uid, 6013, 3234, context=None)
        self._write_line(cr, uid, 6014, 3235, context=None)
        self._write_line(cr, uid, 6004, 3237, context=None)
        self._write_line(cr, uid, 6007, 3236, context=None)
        self._write_line(cr, uid, 6005, 3238, context=None)
        self._write_line(cr, uid, 6006, 3239, context=None)
        self._write_line(cr, uid, 3043, 3223, context=None)
        self._write_line(cr, uid, 3039, 3224, context=None)
        self._write_line(cr, uid, 3040, 3225, context=None)
        self._write_line(cr, uid, 3041, 3221, context=None)
        self._write_line(cr, uid, 4937, 3211, context=None)
        self._write_line(cr, uid, 4938, 3212, context=None)
        self._write_line(cr, uid, 4935, 3213, context=None)
        self._write_line(cr, uid, 4936, 3214, context=None)
        self._write_line(cr, uid, 2624, 3180, context=None)
        self._write_line(cr, uid, 2625, 3181, context=None)
        self._write_line(cr, uid, 2623, 3179, context=None)
        self._write_line(cr, uid, 2742, 3164, context=None)
        self._write_line(cr, uid, 2743, 3165, context=None)
        self._write_line(cr, uid, 3633, 3154, context=None)
        self._write_line(cr, uid, 3634, 3155, context=None)
        self._write_line(cr, uid, 3629, 3156, context=None)
        self._write_line(cr, uid, 3632, 3157, context=None)
        self._write_line(cr, uid, 5211, 3138, context=None)
        self._write_line(cr, uid, 5214, 3141, context=None)
        self._write_line(cr, uid, 5217, 3144, context=None)
        self._write_line(cr, uid, 5212, 3139, context=None)
        self._write_line(cr, uid, 5213, 3140, context=None)
        self._write_line(cr, uid, 5218, 3142, context=None)
        self._write_line(cr, uid, 5215, 3143, context=None)
        self._write_line(cr, uid, 5216, 3145, context=None)
        self._write_line(cr, uid, 5205, 3148, context=None)
        self._write_line(cr, uid, 5207, 3150, context=None)
        self._write_line(cr, uid, 5208, 3151, context=None)
        self._write_line(cr, uid, 5209, 3152, context=None)
        self._write_line(cr, uid, 5219, 3146, context=None)
        self._write_line(cr, uid, 5200, 3132, context=None)
        self._write_line(cr, uid, 5202, 3134, context=None)
        self._write_line(cr, uid, 5199, 3131, context=None)
        self._write_line(cr, uid, 5201, 3133, context=None)
        self._write_line(cr, uid, 5203, 3135, context=None)
        self._write_line(cr, uid, 3754, 3126, context=None)
        self._write_line(cr, uid, 3755, 3127, context=None)
        self._write_line(cr, uid, 3032, 3119, context=None)
        self._write_line(cr, uid, 3031, 3120, context=None)
        self._write_line(cr, uid, 3027, 3115, context=None)
        self._write_line(cr, uid, 3029, 3116, context=None)
        self._write_line(cr, uid, 2916, 3111, context=None)
        self._write_line(cr, uid, 2917, 3110, context=None)
        self._write_line(cr, uid, 6163, 3087, context=None)
        self._write_line(cr, uid, 6165, 3089, context=None)
        self._write_line(cr, uid, 6164, 3088, context=None)
        self._write_line(cr, uid, 6166, 3090, context=None)
        self._write_line(cr, uid, 6174, 3098, context=None)
        self._write_line(cr, uid, 6167, 3091, context=None)
        self._write_line(cr, uid, 6168, 3092, context=None)
        self._write_line(cr, uid, 6169, 3093, context=None)
        self._write_line(cr, uid, 6170, 3094, context=None)
        self._write_line(cr, uid, 6171, 3095, context=None)
        self._write_line(cr, uid, 6172, 3096, context=None)
        self._write_line(cr, uid, 6173, 3097, context=None)
        self._write_line(cr, uid, 6155, 3052, context=None)
        self._write_line(cr, uid, 6156, 3053, context=None)
        self._write_line(cr, uid, 6158, 3055, context=None)
        self._write_line(cr, uid, 6148, 3077, context=None)
        self._write_line(cr, uid, 6145, 3074, context=None)
        self._write_line(cr, uid, 6157, 3054, context=None)
        self._write_line(cr, uid, 6127, 3056, context=None)
        self._write_line(cr, uid, 6129, 3058, context=None)
        self._write_line(cr, uid, 6128, 3057, context=None)
        self._write_line(cr, uid, 6138, 3067, context=None)
        self._write_line(cr, uid, 6143, 3072, context=None)
        self._write_line(cr, uid, 6144, 3059, context=None)
        self._write_line(cr, uid, 6130, 3062, context=None)
        self._write_line(cr, uid, 6133, 3069, context=None)
        self._write_line(cr, uid, 6140, 3073, context=None)
        self._write_line(cr, uid, 6131, 3060, context=None)
        self._write_line(cr, uid, 6132, 3061, context=None)
        self._write_line(cr, uid, 6135, 3064, context=None)
        self._write_line(cr, uid, 6139, 3068, context=None)
        self._write_line(cr, uid, 6150, 3079, context=None)
        self._write_line(cr, uid, 6153, 3082, context=None)
        self._write_line(cr, uid, 6146, 3075, context=None)
        self._write_line(cr, uid, 6134, 3063, context=None)
        self._write_line(cr, uid, 6136, 3065, context=None)
        self._write_line(cr, uid, 6147, 3076, context=None)
        self._write_line(cr, uid, 6151, 3080, context=None)
        self._write_line(cr, uid, 6154, 3083, context=None)
        self._write_line(cr, uid, 6137, 3066, context=None)
        self._write_line(cr, uid, 6141, 3070, context=None)
        self._write_line(cr, uid, 6149, 3078, context=None)
        self._write_line(cr, uid, 6142, 3071, context=None)
        self._write_line(cr, uid, 3253, 3042, context=None)
        self._write_line(cr, uid, 3254, 3044, context=None)
        self._write_line(cr, uid, 3545, 3034, context=None)
        self._write_line(cr, uid, 3543, 3032, context=None)
        self._write_line(cr, uid, 3809, 3029, context=None)
        self._write_line(cr, uid, 3812, 3028, context=None)
        self._write_line(cr, uid, 4024, 3019, context=None)
        self._write_line(cr, uid, 4025, 3018, context=None)
        self._write_line(cr, uid, 4026, 3016, context=None)
        self._write_line(cr, uid, 4027, 3017, context=None)
        self._write_line(cr, uid, 6274, 3011, context=None)
        self._write_line(cr, uid, 6275, 3012, context=None)
        self._write_line(cr, uid, 6276, 3013, context=None)
        self._write_line(cr, uid, 6405, 2939, context=None)
        self._write_line(cr, uid, 6406, 2990, context=None)
        self._write_line(cr, uid, 6411, 2940, context=None)
        self._write_line(cr, uid, 6412, 2944, context=None)
        self._write_line(cr, uid, 6413, 2945, context=None)
        self._write_line(cr, uid, 6351, 2946, context=None)
        self._write_line(cr, uid, 6352, 2938, context=None)
        self._write_line(cr, uid, 6353, 2935, context=None)
        self._write_line(cr, uid, 6354, 2936, context=None)
        self._write_line(cr, uid, 6355, 2937, context=None)
        self._write_line(cr, uid, 6356, 2951, context=None)
        self._write_line(cr, uid, 6360, 2953, context=None)
        self._write_line(cr, uid, 6361, 2954, context=None)
        self._write_line(cr, uid, 6362, 2962, context=None)
        self._write_line(cr, uid, 6367, 2963, context=None)
        self._write_line(cr, uid, 6368, 2952, context=None)
        self._write_line(cr, uid, 6369, 2970, context=None)
        self._write_line(cr, uid, 6370, 2971, context=None)
        self._write_line(cr, uid, 6371, 2955, context=None)
        self._write_line(cr, uid, 6378, 2972, context=None)
        self._write_line(cr, uid, 6379, 2973, context=None)
        self._write_line(cr, uid, 6380, 2964, context=None)
        self._write_line(cr, uid, 6386, 2982, context=None)
        self._write_line(cr, uid, 6387, 2981, context=None)
        self._write_line(cr, uid, 6388, 2989, context=None)
        self._write_line(cr, uid, 6389, 2996, context=None)
        self._write_line(cr, uid, 6397, 2997, context=None)
        self._write_line(cr, uid, 6398, 2995, context=None)
        self._write_line(cr, uid, 6399, 2983, context=None)
        self._write_line(cr, uid, 6359, 2941, context=None)
        self._write_line(cr, uid, 6400, 2947, context=None)
        self._write_line(cr, uid, 6401, 2943, context=None)
        self._write_line(cr, uid, 6402, 2942, context=None)
        self._write_line(cr, uid, 6403, 2987, context=None)
        self._write_line(cr, uid, 6404, 2988, context=None)
        self._write_line(cr, uid, 6407, 2948, context=None)
        self._write_line(cr, uid, 6408, 2992, context=None)
        self._write_line(cr, uid, 6409, 2993, context=None)
        self._write_line(cr, uid, 6410, 2994, context=None)
        self._write_line(cr, uid, 6414, 2949, context=None)
        self._write_line(cr, uid, 6415, 2966, context=None)
        self._write_line(cr, uid, 6416, 2950, context=None)
        self._write_line(cr, uid, 6417, 2956, context=None)
        self._write_line(cr, uid, 6418, 3002, context=None)
        self._write_line(cr, uid, 6357, 2958, context=None)
        self._write_line(cr, uid, 6358, 2978, context=None)
        self._write_line(cr, uid, 6363, 2959, context=None)
        self._write_line(cr, uid, 6364, 2965, context=None)
        self._write_line(cr, uid, 6365, 2969, context=None)
        self._write_line(cr, uid, 6366, 2967, context=None)
        self._write_line(cr, uid, 6372, 2968, context=None)
        self._write_line(cr, uid, 6373, 2957, context=None)
        self._write_line(cr, uid, 6374, 2974, context=None)
        self._write_line(cr, uid, 6375, 2975, context=None)
        self._write_line(cr, uid, 6376, 2960, context=None)
        self._write_line(cr, uid, 6381, 2976, context=None)
        self._write_line(cr, uid, 6382, 2979, context=None)
        self._write_line(cr, uid, 6383, 2977, context=None)
        self._write_line(cr, uid, 6384, 2984, context=None)
        self._write_line(cr, uid, 6385, 2985, context=None)
        self._write_line(cr, uid, 6390, 2980, context=None)
        self._write_line(cr, uid, 6391, 2991, context=None)
        self._write_line(cr, uid, 6392, 2998, context=None)
        self._write_line(cr, uid, 6393, 3000, context=None)
        self._write_line(cr, uid, 6394, 2986, context=None)
        self._write_line(cr, uid, 6395, 2999, context=None)
        self._write_line(cr, uid, 6396, 3001, context=None)
        self._write_line(cr, uid, 5942, 2920, context=None)
        self._write_line(cr, uid, 5899, 2877, context=None)
        self._write_line(cr, uid, 5901, 2879, context=None)
        self._write_line(cr, uid, 5907, 2921, context=None)
        self._write_line(cr, uid, 5908, 2885, context=None)
        self._write_line(cr, uid, 5911, 2889, context=None)
        self._write_line(cr, uid, 5914, 2892, context=None)
        self._write_line(cr, uid, 5918, 2886, context=None)
        self._write_line(cr, uid, 5919, 2896, context=None)
        self._write_line(cr, uid, 5924, 2897, context=None)
        self._write_line(cr, uid, 5928, 2906, context=None)
        self._write_line(cr, uid, 5929, 2902, context=None)
        self._write_line(cr, uid, 5930, 2907, context=None)
        self._write_line(cr, uid, 5937, 2908, context=None)
        self._write_line(cr, uid, 5938, 2915, context=None)
        self._write_line(cr, uid, 5939, 2916, context=None)
        self._write_line(cr, uid, 5940, 2917, context=None)
        self._write_line(cr, uid, 5941, 2918, context=None)
        self._write_line(cr, uid, 5943, 2919, context=None)
        self._write_line(cr, uid, 5898, 2876, context=None)
        self._write_line(cr, uid, 5897, 2878, context=None)
        self._write_line(cr, uid, 5906, 2874, context=None)
        self._write_line(cr, uid, 5921, 2875, context=None)
        self._write_line(cr, uid, 5935, 2913, context=None)
        self._write_line(cr, uid, 5944, 2881, context=None)
        self._write_line(cr, uid, 5900, 2882, context=None)
        self._write_line(cr, uid, 5902, 2883, context=None)
        self._write_line(cr, uid, 5903, 2880, context=None)
        self._write_line(cr, uid, 5904, 2888, context=None)
        self._write_line(cr, uid, 5905, 2884, context=None)
        self._write_line(cr, uid, 5909, 2887, context=None)
        self._write_line(cr, uid, 5910, 2894, context=None)
        self._write_line(cr, uid, 5912, 2890, context=None)
        self._write_line(cr, uid, 5913, 2898, context=None)
        self._write_line(cr, uid, 5916, 2899, context=None)
        self._write_line(cr, uid, 5917, 2900, context=None)
        self._write_line(cr, uid, 5920, 2895, context=None)
        self._write_line(cr, uid, 5922, 2903, context=None)
        self._write_line(cr, uid, 5923, 2904, context=None)
        self._write_line(cr, uid, 5925, 2905, context=None)
        self._write_line(cr, uid, 5926, 2901, context=None)
        self._write_line(cr, uid, 5927, 2910, context=None)
        self._write_line(cr, uid, 5931, 2911, context=None)
        self._write_line(cr, uid, 5932, 2912, context=None)
        self._write_line(cr, uid, 5933, 2909, context=None)
        self._write_line(cr, uid, 5934, 2914, context=None)
        self._write_line(cr, uid, 5936, 2891, context=None)
        self._write_line(cr, uid, 3292, 2869, context=None)
        self._write_line(cr, uid, 3293, 2870, context=None)
        self._write_line(cr, uid, 3294, 2871, context=None)
        self._write_line(cr, uid, 3278, 2866, context=None)
        self._write_line(cr, uid, 3279, 2867, context=None)
        self._write_line(cr, uid, 4040, 2857, context=None)
        self._write_line(cr, uid, 4034, 2851, context=None)
        self._write_line(cr, uid, 6082, 2810, context=None)
        self._write_line(cr, uid, 6084, 2812, context=None)
        self._write_line(cr, uid, 6086, 2814, context=None)
        self._write_line(cr, uid, 6087, 2815, context=None)
        self._write_line(cr, uid, 6088, 2816, context=None)
        self._write_line(cr, uid, 6091, 2821, context=None)
        self._write_line(cr, uid, 6092, 2820, context=None)
        self._write_line(cr, uid, 6093, 2839, context=None)
        self._write_line(cr, uid, 6094, 2822, context=None)
        self._write_line(cr, uid, 6099, 2827, context=None)
        self._write_line(cr, uid, 6100, 2819, context=None)
        self._write_line(cr, uid, 6104, 2832, context=None)
        self._write_line(cr, uid, 6106, 2834, context=None)
        self._write_line(cr, uid, 6107, 2835, context=None)
        self._write_line(cr, uid, 6111, 2828, context=None)
        self._write_line(cr, uid, 6083, 2811, context=None)
        self._write_line(cr, uid, 6085, 2813, context=None)
        self._write_line(cr, uid, 6089, 2817, context=None)
        self._write_line(cr, uid, 6090, 2818, context=None)
        self._write_line(cr, uid, 6095, 2824, context=None)
        self._write_line(cr, uid, 6096, 2823, context=None)
        self._write_line(cr, uid, 6097, 2825, context=None)
        self._write_line(cr, uid, 6098, 2826, context=None)
        self._write_line(cr, uid, 6101, 2829, context=None)
        self._write_line(cr, uid, 6102, 2830, context=None)
        self._write_line(cr, uid, 6103, 2831, context=None)
        self._write_line(cr, uid, 6105, 2833, context=None)
        self._write_line(cr, uid, 6108, 2836, context=None)
        self._write_line(cr, uid, 6109, 2837, context=None)
        self._write_line(cr, uid, 6110, 2841, context=None)
        self._write_line(cr, uid, 6113, 2842, context=None)
        self._write_line(cr, uid, 6114, 2838, context=None)
        self._write_line(cr, uid, 6471, 2806, context=None)
        self._write_line(cr, uid, 6453, 2788, context=None)
        self._write_line(cr, uid, 6467, 2802, context=None)
        self._write_line(cr, uid, 6472, 2807, context=None)
        self._write_line(cr, uid, 6454, 2789, context=None)
        self._write_line(cr, uid, 6468, 2797, context=None)
        self._write_line(cr, uid, 6461, 2796, context=None)
        self._write_line(cr, uid, 6462, 2803, context=None)
        self._write_line(cr, uid, 6455, 2790, context=None)
        self._write_line(cr, uid, 6458, 2793, context=None)
        self._write_line(cr, uid, 6469, 2804, context=None)
        self._write_line(cr, uid, 6470, 2805, context=None)
        self._write_line(cr, uid, 6456, 2791, context=None)
        self._write_line(cr, uid, 6465, 2798, context=None)
        self._write_line(cr, uid, 6463, 2800, context=None)
        self._write_line(cr, uid, 6430, 2767, context=None)
        self._write_line(cr, uid, 6426, 2763, context=None)
        self._write_line(cr, uid, 6427, 2782, context=None)
        self._write_line(cr, uid, 6431, 2764, context=None)
        self._write_line(cr, uid, 6433, 2768, context=None)
        self._write_line(cr, uid, 6441, 2770, context=None)
        self._write_line(cr, uid, 6445, 2778, context=None)
        self._write_line(cr, uid, 6428, 2765, context=None)
        self._write_line(cr, uid, 6429, 2766, context=None)
        self._write_line(cr, uid, 6436, 2773, context=None)
        self._write_line(cr, uid, 6437, 2774, context=None)
        self._write_line(cr, uid, 6438, 2775, context=None)
        self._write_line(cr, uid, 6440, 2777, context=None)
        self._write_line(cr, uid, 6444, 2781, context=None)
        self._write_line(cr, uid, 6448, 2785, context=None)
        self._write_line(cr, uid, 6449, 2786, context=None)
        self._write_line(cr, uid, 6432, 2769, context=None)
        self._write_line(cr, uid, 6434, 2771, context=None)
        self._write_line(cr, uid, 6443, 2780, context=None)
        self._write_line(cr, uid, 6446, 2783, context=None)
        self._write_line(cr, uid, 6435, 2772, context=None)
        self._write_line(cr, uid, 6442, 2779, context=None)
        self._write_line(cr, uid, 6447, 2784, context=None)
        self._write_line(cr, uid, 6450, 2787, context=None)
        self._write_line(cr, uid, 3668, 2749, context=None)
        self._write_line(cr, uid, 3669, 2750, context=None)
        self._write_line(cr, uid, 3670, 2751, context=None)
        self._write_line(cr, uid, 3672, 2746, context=None)
        self._write_line(cr, uid, 3673, 2747, context=None)
        self._write_line(cr, uid, 3671, 2745, context=None)
        self._write_line(cr, uid, 3676, 2735, context=None)
        self._write_line(cr, uid, 3677, 2736, context=None)
        self._write_line(cr, uid, 4004, 2729, context=None)
        self._write_line(cr, uid, 4005, 2730, context=None)
        self._write_line(cr, uid, 6568, 2718, context=None)
        self._write_line(cr, uid, 6572, 2714, context=None)
        self._write_line(cr, uid, 6574, 2720, context=None)
        self._write_line(cr, uid, 6577, 2723, context=None)
        self._write_line(cr, uid, 6580, 2726, context=None)
        self._write_line(cr, uid, 6569, 2716, context=None)
        self._write_line(cr, uid, 6570, 2717, context=None)
        self._write_line(cr, uid, 6571, 2715, context=None)
        self._write_line(cr, uid, 6573, 2719, context=None)
        self._write_line(cr, uid, 6576, 2722, context=None)
        self._write_line(cr, uid, 6575, 2721, context=None)
        self._write_line(cr, uid, 6581, 2727, context=None)
        self._write_line(cr, uid, 6578, 2724, context=None)
        self._write_line(cr, uid, 6579, 2725, context=None)
        self._write_line(cr, uid, 6582, 2728, context=None)
        self._write_line(cr, uid, 2874, 2711, context=None)
        self._write_line(cr, uid, 2875, 2713, context=None)
        self._write_line(cr, uid, 2876, 2712, context=None)
        self._write_line(cr, uid, 2849, 2700, context=None)
        self._write_line(cr, uid, 2850, 2701, context=None)
        self._write_line(cr, uid, 6322, 2674, context=None)
        self._write_line(cr, uid, 6321, 2675, context=None)
        self._write_line(cr, uid, 6342, 2695, context=None)
        self._write_line(cr, uid, 6325, 2678, context=None)
        self._write_line(cr, uid, 6330, 2688, context=None)
        self._write_line(cr, uid, 6335, 2683, context=None)
        self._write_line(cr, uid, 6345, 2698, context=None)
        self._write_line(cr, uid, 6326, 2679, context=None)
        self._write_line(cr, uid, 6339, 2692, context=None)
        self._write_line(cr, uid, 6343, 2696, context=None)
        self._write_line(cr, uid, 6344, 2697, context=None)
        self._write_line(cr, uid, 6327, 2680, context=None)
        self._write_line(cr, uid, 6332, 2685, context=None)
        self._write_line(cr, uid, 6336, 2689, context=None)
        self._write_line(cr, uid, 6340, 2693, context=None)
        self._write_line(cr, uid, 6328, 2681, context=None)
        self._write_line(cr, uid, 6331, 2684, context=None)
        self._write_line(cr, uid, 6337, 2690, context=None)
        self._write_line(cr, uid, 6329, 2682, context=None)
        self._write_line(cr, uid, 6333, 2686, context=None)
        self._write_line(cr, uid, 6334, 2687, context=None)
        self._write_line(cr, uid, 6282, 2658, context=None)
        self._write_line(cr, uid, 6283, 2656, context=None)
        self._write_line(cr, uid, 6284, 2657, context=None)
        self._write_line(cr, uid, 5108, 2621, context=None)
        self._write_line(cr, uid, 5122, 2620, context=None)
        self._write_line(cr, uid, 5123, 2606, context=None)
        self._write_line(cr, uid, 5126, 2624, context=None)
        self._write_line(cr, uid, 5127, 2625, context=None)
        self._write_line(cr, uid, 5128, 2627, context=None)
        self._write_line(cr, uid, 5129, 2629, context=None)
        self._write_line(cr, uid, 5131, 2626, context=None)
        self._write_line(cr, uid, 5135, 2633, context=None)
        self._write_line(cr, uid, 5136, 2634, context=None)
        self._write_line(cr, uid, 5138, 2611, context=None)
        self._write_line(cr, uid, 5141, 2616, context=None)
        self._write_line(cr, uid, 5142, 2615, context=None)
        self._write_line(cr, uid, 5143, 2639, context=None)
        self._write_line(cr, uid, 5144, 2640, context=None)
        self._write_line(cr, uid, 5146, 2641, context=None)
        self._write_line(cr, uid, 5148, 2646, context=None)
        self._write_line(cr, uid, 5153, 2651, context=None)
        self._write_line(cr, uid, 5154, 2612, context=None)
        self._write_line(cr, uid, 5155, 2642, context=None)
        self._write_line(cr, uid, 5113, 2636, context=None)
        self._write_line(cr, uid, 5114, 2652, context=None)
        self._write_line(cr, uid, 5117, 2644, context=None)
        self._write_line(cr, uid, 5118, 2653, context=None)
        self._write_line(cr, uid, 5120, 2622, context=None)
        self._write_line(cr, uid, 5121, 2619, context=None)
        self._write_line(cr, uid, 5124, 2623, context=None)
        self._write_line(cr, uid, 5125, 2628, context=None)
        self._write_line(cr, uid, 5130, 2631, context=None)
        self._write_line(cr, uid, 5132, 2630, context=None)
        self._write_line(cr, uid, 5133, 2632, context=None)
        self._write_line(cr, uid, 5134, 2635, context=None)
        self._write_line(cr, uid, 5137, 2608, context=None)
        self._write_line(cr, uid, 5139, 2637, context=None)
        self._write_line(cr, uid, 5140, 2609, context=None)
        self._write_line(cr, uid, 5147, 2647, context=None)
        self._write_line(cr, uid, 5149, 2645, context=None)
        self._write_line(cr, uid, 5150, 2607, context=None)
        self._write_line(cr, uid, 5151, 2613, context=None)
        self._write_line(cr, uid, 5152, 2610, context=None)
        self._write_line(cr, uid, 5109, 2617, context=None)
        self._write_line(cr, uid, 5110, 2618, context=None)
        self._write_line(cr, uid, 5111, 2614, context=None)
        self._write_line(cr, uid, 5112, 2638, context=None)
        self._write_line(cr, uid, 5115, 2648, context=None)
        self._write_line(cr, uid, 5116, 2649, context=None)
        self._write_line(cr, uid, 5119, 2650, context=None)
        self._write_line(cr, uid, 3416, 2603, context=None)
        self._write_line(cr, uid, 3417, 2601, context=None)
        self._write_line(cr, uid, 3418, 2598, context=None)
        self._write_line(cr, uid, 3419, 2604, context=None)
        self._write_line(cr, uid, 3420, 2602, context=None)
        self._write_line(cr, uid, 3421, 2597, context=None)
        self._write_line(cr, uid, 3422, 2600, context=None)
        self._write_line(cr, uid, 3423, 2599, context=None)
        self._write_line(cr, uid, 2752, 2595, context=None)
        self._write_line(cr, uid, 2753, 2596, context=None)
        self._write_line(cr, uid, 2837, 2585, context=None)
        self._write_line(cr, uid, 2838, 2584, context=None)
        self._write_line(cr, uid, 2739, 2581, context=None)
        self._write_line(cr, uid, 2740, 2580, context=None)
        self._write_line(cr, uid, 2737, 2583, context=None)
        self._write_line(cr, uid, 2738, 2582, context=None)
#        raise osv.except_osv(_('Error !'), _(str(data_id) + 'xxx' + str(data_name)))
        return {'type': 'ir.actions.act_window_close'}

    def write_move_id(self, cr, uid, ids, context=None):
        account_invoice_obj = self.pool.get('account.invoice')
        account_invoice_line_obj = self.pool.get('account.invoice.line')
        stock_move_obj = self.pool.get('stock.move')
        invoice_ids = account_invoice_obj.search(cr, uid, [('type', '=' ,'out_invoice')], context=None)
        
        invoices = account_invoice_obj.browse(cr, uid, invoice_ids, context=context)
#        raise osv.except_osv(_('Error !'), _(str('amount_untaxed_home') + 'xxx' + str('amount_tax_home')))
        val_res = []
        for invoice in invoices:
            
            amount_untaxed_home = 0
            amount_tax_home = 0
            amount_total_home = 0
            if invoice.picking_id:
                for line in invoice.invoice_line:
                    if not line.stock_move_id:
                        stock_move_ids = stock_move_obj.search(cr, uid, [('picking_id', '=', invoice.picking_id.id), ('product_id', '=', line.product_id.id)], order='name ASC')
                        if stock_move_ids:
                            count = 0
                            for stm_id in stock_move_ids:
                                count += 1
                            if count > 1:
                                val_res.append(str(stock_move_ids) + '   ' + (invoice.number) + '   ' + str(invoice.picking_id.name))

                            else:
                                stock_move_id = stock_move_obj.browse(cr, uid, stock_move_ids[0]).id
                                account_invoice_line_obj.write(cr, uid, line.id, {'stock_move_id': stock_move_id}, context=None)
        if val_res:
            raise osv.except_osv(_('Error !'), _(str(val_res) + 'xxx'))
        return {'type': 'ir.actions.act_window_close'}

    def _get_taxes_invoice(self, cr, uid):
        """ Gets taxes on invoice
        @param move_line: Stock move lines
        @param type: Type of invoice
        @return: Taxes Ids for the move line
        """
        account_tax_obj = self.pool.get('account.tax')
        taxes = account_tax_obj.browse(cr, uid, [13], context=None)

        return map(lambda x: x.id, taxes)

    def line_get_convert(self, cr, uid, x, obj, context=None):
        return {
            'date_maturity': x.get('date_maturity', False),
            'partner_id': obj.partner_id.id,
            'name': x['name'][:64],
            'date': obj.date_invoice or time.strftime('%Y-%m-%d'),
            'cur_date': obj.cur_date or obj.date_invoice or time.strftime('%Y-%m-%d'),
            'debit': x['price']>0 and float_round(x['price'],2),
            'credit': x['price']<0 and float_round(-x['price'],2),
            'account_id': x['account_id'],
            'is_refund': False,
            'analytic_lines': x.get('analytic_lines', []),
            'amount_currency': False,
            'currency_id': False,
            'tax_code_id': x.get('tax_code_id', False),
            'tax_amount': x.get('tax_amount') and float_round(x.get('tax_amount'),2) or False,
            'ref': x.get('ref', False),
            'quantity': x.get('quantity',1.00),
            'product_id': x.get('product_id', False),
            'product_uom_id': x.get('uos_id', False),
            'analytic_account_id': x.get('account_analytic_id', False),
            'move_id': obj.move_id.id,
        }

    def do_validate4(self, cr, uid, ids, context=None):
        account_invoice_obj = self.pool.get('account.invoice')
        account_move_obj = self.pool.get('account.move')
        account_invoice_line_obj = self.pool.get('account.invoice.line')
        account_move_line_obj = self.pool.get('account.move.line')
        ait_obj = self.pool.get('account.invoice.tax')
        for obj in self.browse(cr, uid, ids, context=context):
            for acc in account_invoice_obj.browse(cr, uid, context.get(('active_ids'), []), context):
                for line in acc.invoice_line:
                    account_invoice_line_obj.write(cr, uid, [line.id], {'account_id': 282, 'invoice_line_tax_id': [(6, 0, self._get_taxes_invoice(cr, uid))]}, context=context)
                account_invoice_obj.button_reset_taxes(cr, uid, context.get(('active_ids'), []),context=context)
                taxline = ait_obj.move_line_get(cr, uid, context.get(('active_ids'), [])[0])
                value = float_round(abs(taxline[0]['price']),2)
                vals = map(lambda x:(self.line_get_convert(cr, uid, x, acc, context=None)),taxline)
                for move_line in acc.move_id.line_id:
                    if move_line.account_id.id == acc.account_id.id:
                        value += move_line.credit
                        account_move_line_obj.write(cr, uid, [move_line.id], {'credit': value}, context=None, check=False, update_check=False)
                    else:
                        account_move_line_obj.write(cr, uid, [move_line.id], {'tax_code_id': 29}, context=None, check=False, update_check=False)
                        #raise osv.except_osv(_('Error !'), _(str('found') + 'xxx' + str('')))
                account_move_line_obj.create(cr, uid, vals[0], context=context)
                #raise osv.except_osv(_('Error !'), _(str(value) + 'xxx' + str('')))
            #account_invoice_obj.write(cr, uid, context.get(('active_ids'), []), {'period_id': obj.period_id.id, 'date_invoice': obj.date_invoice}, context=context)
        return {'type': 'ir.actions.act_window_close'}

    _columns = {
        'journal_id': fields.many2one('account.journal', 'Journal'),
        'date_invoice': fields.date('Invoice Date'),
        'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')]),
    }

change_journal_si()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
