~jo0thlt/sfsoluciones/trunk

« back to all changes in this revision

Viewing changes to account_voucher_tax/account_voucher_old.py

  • Committer: launchpadzbeanz at gmail
  • Date: 2014-01-16 14:07:32 UTC
  • Revision ID: launchpadzbeanz@gmail.com-20140116140732-gykez3yqv5di4jp9
Bug Fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
 
6
#    All Rights Reserved.
 
7
#    info@vauxoo.com
 
8
############################################################################
 
9
#    Coded by: Rodo (rodo@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
 
 
27
from osv import osv, fields
 
28
from tools.translate import _
 
29
import release
 
30
import decimal_precision as dp
 
31
 
 
32
class account_voucher(osv.osv):
 
33
    _inherit = 'account.voucher'
 
34
    
 
35
    #~ _columns={
 
36
        #~ 'move_id2':fields.many2one('account.move', 'Account Entry Tax'),
 
37
        #~ 'move_ids2': fields.related('move_id2','line_id', type='one2many', relation='account.move.line', string='Journal Items Tax', readonly=True),
 
38
#~ 
 
39
        #~ }
 
40
    
 
41
    def get_rate(self, cr, uid, move_id, context=None):
 
42
        move_obj = self.pool.get('account.move')
 
43
        if not context:
 
44
            context = {}
 
45
        for move in move_obj.browse(cr, uid, [move_id], context):
 
46
            for line in move.line_id:
 
47
                amount_base = line.debit or line.credit or 0
 
48
                rate = 1
 
49
                if amount_base and line.amount_currency:
 
50
                    rate=amount_base/line.amount_currency
 
51
                    return rate
 
52
        return rate
 
53
    
 
54
    def get_percent_pay_vs_invoice(self, cr, uid, amount_original,amount, context=None):
 
55
        return amount_original and amount/amount_original or 1.0
 
56
    
 
57
    def get_partial_amount_tax_pay(self, cr, uid, tax_amount,tax_base, context=None):
 
58
        return tax_amount*tax_base
 
59
    
 
60
    def voucher_move_line_tax_create(self, cr, uid, voucher_id, move_id, context=None):
 
61
        move_obj = self.pool.get('account.move')
 
62
        move_line_obj = self.pool.get('account.move.line')
 
63
        invoice_obj = self.pool.get('account.invoice')
 
64
        currency_obj = self.pool.get('res.currency')
 
65
        company_currency = self._get_company_currency(cr, uid, voucher_id, context)
 
66
        current_currency = self._get_current_currency(cr, uid, voucher_id, context)
 
67
        for voucher in self.browse(cr, uid, [voucher_id], context=context):
 
68
            for line in voucher.line_ids:
 
69
                for line_tax in line.tax_line_ids:
 
70
                    credit=line_tax.amount_tax
 
71
                    debit=0.0
 
72
                    if company_currency!=current_currency:
 
73
                        credit=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,credit)), round=True, context=context)
 
74
                    account_tax_voucher=line_tax.tax_id.account_collected_voucher_id.id
 
75
                    account_tax_collected=line_tax.tax_id.account_collected_id.id
 
76
                    if voucher.type=='payment':
 
77
                        credit, debit=debit, credit
 
78
                    move_line={
 
79
                    'journal_id': voucher.journal_id.id,
 
80
                    'period_id': voucher.period_id.id,
 
81
                    'name': line_tax.tax_id.account_collected_voucher_id.name or '/',
 
82
                    'account_id': account_tax_voucher,
 
83
                    'move_id': int(move_id),
 
84
                    'partner_id': voucher.partner_id.id,
 
85
                    'company_id':company_currency,
 
86
                    'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
87
                    #~ 'currency_id': voucher.journal_id.currency.id,
 
88
                    'quantity': 1,
 
89
                    'credit': float('%.*f' % (2,credit)),
 
90
                    'debit': float('%.*f' % (2,debit)),
 
91
                    #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
92
                    'date': voucher.date,
 
93
                    }
 
94
                    if company_currency!=current_currency:
 
95
                        move_line['amount_currency']=line_tax.amount_tax
 
96
                    move_line_obj.create(cr ,uid, move_line, context=context)
 
97
                    #~ if line_tax.diff_amount_tax:
 
98
                    context['date']=line.move_line_id.date
 
99
                    amount=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,line_tax.original_tax)), round=False, context=context)
 
100
                    if credit:
 
101
                        credit=amount
 
102
                    else:
 
103
                        debit=amount
 
104
                    credit, debit=debit, credit
 
105
 
 
106
                    move_line={
 
107
                    'journal_id': voucher.journal_id.id,
 
108
                    'period_id': voucher.period_id.id,
 
109
                    'name': line_tax.tax_id.name or '/',
 
110
                    'account_id':account_tax_collected, 
 
111
                    'move_id': int(move_id),
 
112
                    'partner_id': voucher.partner_id.id,
 
113
                    'company_id':company_currency,
 
114
                    #~ 'currency_id': voucher.journal_id.currency.id,
 
115
                    'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
116
                    'quantity': 1,
 
117
                    'credit': float('%.*f' % (2,credit)),
 
118
                    'debit': float('%.*f' % (2,debit)),
 
119
                    #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
120
                    'date': voucher.date,
 
121
                    }
 
122
                    if company_currency!=current_currency:
 
123
                        move_line['amount_currency']=line_tax.amount_tax
 
124
                    move_line_obj.create(cr ,uid, move_line, context=context)
 
125
                    
 
126
                    if line_tax.diff_amount_tax:
 
127
                        context['date']=line.move_line_id.date
 
128
                        credit_orig=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,line_tax.original_tax)), round=True, context=context)
 
129
                        context['date']=voucher.date
 
130
                        credit_now=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,line_tax.amount_tax)), round=False, context=context)
 
131
                        amount_diff=abs(credit_orig-credit_now)
 
132
                        debit_diff=0.0
 
133
                        if voucher.type=='payment':
 
134
                            if not credit_orig-credit_now < 0: 
 
135
                                amount_diff, debit_diff= debit_diff, amount_diff
 
136
                            move_line={
 
137
                                'journal_id': voucher.journal_id.id,
 
138
                                'period_id': voucher.period_id.id,
 
139
                                'name': 'change_tax: ' + str(line.name),
 
140
                                'account_id':line_tax.diff_account_id.id, 
 
141
                                'move_id': int(move_id),
 
142
                                'partner_id': voucher.partner_id.id,
 
143
                                'company_id':company_currency,
 
144
                                #~ 'currency_id': voucher.journal_id.currency.id,
 
145
                                'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
146
                                'quantity': 1,
 
147
                                'credit': float('%.*f' % (2,amount_diff)),
 
148
                                'debit': float('%.*f' % (2,debit_diff)),
 
149
                                #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
150
                                'date': voucher.date,
 
151
                                }
 
152
                            move_line_obj.create(cr ,uid, move_line, context=context)
 
153
                        else:
 
154
                            if credit_orig-credit_now < 0:
 
155
                                amount_diff, debit_diff= debit_diff, amount_diff
 
156
                            move_line={
 
157
                                'journal_id': voucher.journal_id.id,
 
158
                                'period_id': voucher.period_id.id,
 
159
                                'name': 'change_tax: ' +  str(line.name),
 
160
                                'account_id':line_tax.diff_account_id.id, 
 
161
                                'move_id': int(move_id),
 
162
                                'partner_id': voucher.partner_id.id,
 
163
                                'company_id':company_currency,
 
164
                                #~ 'currency_id': voucher.journal_id.currency.id,
 
165
                                'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
166
                                'quantity': 1,
 
167
                                'credit': float('%.*f' % (2,amount_diff)),
 
168
                                'debit': float('%.*f' % (2,debit_diff)),
 
169
                                #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
170
                                'date': voucher.date,
 
171
                                }
 
172
                            move_line_obj.create(cr ,uid, move_line, context=context)
 
173
        return move_id
 
174
        
 
175
        
 
176
        
 
177
        #~ new_move=move_obj.create(cr, uid, self.account_move_get(cr, uid, voucher_id, context=context), context=context)
 
178
        #~ new_move=move_id
 
179
        #~ for voucher in self.browse(cr,uid,[voucher_id],context=context):
 
180
            #~ lines=[]
 
181
            #~ for line in voucher.line_ids:
 
182
                #~ factor=self.get_percent_pay_vs_invoice(cr,uid,line.amount_original, line.amount,context=context)
 
183
                #~ if line.amount>0:
 
184
                    #~ invoice_ids=invoice_obj.search(cr,uid,[('move_id','=',line.move_line_id.move_id.id)],context=context)
 
185
                    #~ for invoice in invoice_obj.browse(cr,uid,invoice_ids,context=context):
 
186
                        #~ for tax in invoice.tax_line:
 
187
                            #~ if tax.tax_id.tax_voucher_ok:
 
188
                                #~ base_amount=self.get_partial_amount_tax_pay(cr, uid, tax.tax_id.amount, tax.base, context=context)
 
189
                                #~ move_ids=[]
 
190
                                #~ account=tax.tax_id.account_collected_voucher_id.id
 
191
                                #~ credit_amount= float('%.*f' % (2,(base_amount*factor)))
 
192
                                #~ if credit_amount:
 
193
                                    #~ if abs(float('%.*f' % (2,credit_amount))-base_amount)<=.02:
 
194
                                        #~ credit_amount=credit_amount-abs(float('%.*f' % (2,credit_amount))-base_amount)
 
195
                                    #~ if abs(float('%.*f' % (2,credit_amount))+ (base_amount*(1-factor))-base_amount)<.02:
 
196
                                        #~ credit_amount=credit_amount-abs(float('%.*f' % (2,credit_amount))+ (base_amount*(1-factor))-base_amount)
 
197
                                #~ #context['date']=invoice.date_invoice
 
198
                                #~ if company_currency==current_currency:
 
199
                                    #~ rate_move=self.get_rate(cr,uid,line.move_line_id.move_id.id,context=context)
 
200
                                    #~ credit_amount=credit_amount*rate_move
 
201
                                #~ else:
 
202
                                    #~ credit_amount=currency_obj.compute(cr, uid, line.move_line_id.currency_id.id,company_currency, float('%.*f' % (2,credit_amount)), round=False, context=context)
 
203
                                #~ debit_amount=0.0
 
204
                                #~ if tax.tax_id.amount<0:
 
205
                                    #~ credit_amount=0.0
 
206
                                    #~ debit_amount=float('%.*f' % (2,(base_amount*factor)))
 
207
                                    #~ if debit_amount: 
 
208
                                        #~ if abs(float('%.*f' % (2,debit_amount))-base_amount)<=.02:
 
209
                                            #~ debit_amount=debit_amount-abs(float('%.*f' % (2,debit_amount))-base_amount)
 
210
                                        #~ if abs(float('%.*f' % (2,debit_amount))+ (base_amount*(1-factor))-base_amount)<.02:
 
211
                                            #~ debit_amount=debit_amount-abs(float('%.*f' % (2,debit_amount))+ (base_amount*(1-factor))-base_amount)
 
212
                                        #~ debit_amount=(-1.0*currency_obj.compute(cr, uid, line.move_line_id.currency_id.id,company_currency, float('%.*f' % (2,debit_amount)), round=False, context=context))
 
213
                                #~ if invoice.type=='out_invoice':## TODO refund
 
214
                                    #~ account=tax.tax_id.account_paid_voucher_id.id
 
215
                                    #~ credit_amount, debit_amount=debit_amount, credit_amount
 
216
                                #~ move_line={
 
217
                                    #~ 'journal_id': voucher.journal_id.id,
 
218
                                    #~ 'period_id': voucher.period_id.id,
 
219
                                    #~ 'name': tax.name or '/',
 
220
                                    #~ 'account_id': tax.account_id.id,
 
221
                                    #~ 'move_id': int(move_id),
 
222
                                    #~ 'partner_id': voucher.partner_id.id,
 
223
                                    #~ 'company_id':company_currency,
 
224
                                    #~ 'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
225
                                    #~ 'quantity': 1,
 
226
                                    #~ 'credit': credit_amount,
 
227
                                    #~ 'debit': debit_amount,
 
228
                                    #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
229
                                    #~ 'date': voucher.date,
 
230
                                    #~ 
 
231
                                    #~ }
 
232
                                #~ if company_currency!=current_currency:
 
233
                                    #~ move_line['amount_currency']=currency_obj.compute(cr, uid, company_currency, current_currency,(credit_amount or debit_amount), round=False, context=context)
 
234
                                #~ print move_line,"moveee1"
 
235
                                #~ move_ids.append(move_line_obj.create(cr,uid,move_line,context=context))
 
236
                                #~ print move_ids,"avanzando"
 
237
                                #~ move_line={
 
238
                                    #~ 'journal_id': voucher.journal_id.id,
 
239
                                    #~ 'period_id': voucher.period_id.id,
 
240
                                    #~ 'name': tax.name or '/',
 
241
                                    #~ 'account_id': account,
 
242
                                    #~ 'move_id': int(move_id),
 
243
                                    #~ 'partner_id': voucher.partner_id.id,
 
244
                                    #~ 'company_id':company_currency,
 
245
                                    #~ 'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
246
                                    #~ 'quantity': 1,
 
247
                                    #~ 'credit': debit_amount,
 
248
                                    #~ 'debit': credit_amount,
 
249
                                    #~ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
250
                                    #~ 'date': voucher.date,
 
251
                                    #~ }
 
252
                                #~ if company_currency!=current_currency:
 
253
                                    #~ move_line['amount_currency']=currency_obj.compute(cr, uid, company_currency, current_currency,(debit_amount or credit_amount), round=False, context=context)
 
254
                                #~ print move_line,"move222"
 
255
                                #~ move_line_obj.create(cr,uid,move_line,context=context)
 
256
                                #~ print 'avanzoo'
 
257
                                #~ account_income_id = voucher.company_id.income_currency_exchange_account_id.id
 
258
                                #~ account_expense_id = voucher.company_id.expense_currency_exchange_account_id.id
 
259
                                #~ for m in move_obj.browse(cr,uid,[move_id],context=context):
 
260
                                    #~ for mlines in m.line_id:
 
261
                                        #~ dif=0
 
262
                                        #~ if mlines.account_id.id==account_income_id:
 
263
                                            #~ account=account_expense_id
 
264
                                            #~ if invoice.type=='out_invoice':
 
265
                                                #~ credit=(debit_amount-tax.tax_amount)
 
266
                                                #~ debit=0.0
 
267
                                                #~ dif=1
 
268
                                            #~ else:
 
269
                                                #~ credit=0.0
 
270
                                                #~ debit=(credit_amount-tax.tax_amount)
 
271
                                                #~ dif=1
 
272
                                        #~ if mlines.account_id.id==account_expense_id:
 
273
                                            #~ account=account_income_id
 
274
                                            #~ if invoice.type=='out_invoice':
 
275
                                                #~ credit=0.0
 
276
                                                #~ debit=(debit_amount-tax.tax_amount)
 
277
                                                #~ dif=1
 
278
                                            #~ else:
 
279
                                                #~ credit=(credit_amount-tax.tax_amount)
 
280
                                                #~ debit=0.0
 
281
                                                #~ dif=1
 
282
                                        #~ if dif:
 
283
                                            #~ if invoice.type=='out_invoice':## TODO refund
 
284
                                                #~ credit, debit=debit, credit
 
285
                                            #~ move_line = {
 
286
                                                #~ 'journal_id': voucher.journal_id.id,
 
287
                                                #~ 'period_id': voucher.period_id.id,
 
288
                                                #~ 'name': _('change')+': '+(line.name or '/'),
 
289
                                                #~ 'account_id': account,
 
290
                                                #~ 'move_id': int(move_id),
 
291
                                                #~ 'partner_id': voucher.partner_id.id,
 
292
                                                #~ 'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
293
                                                #~ 'amount_currency': 0.0,
 
294
                                                #~ 'quantity': 1,
 
295
                                                #~ 'credit': credit,
 
296
                                                #~ 'debit': debit,
 
297
                                                #~ 'date': line.voucher_id.date,
 
298
                                            #~ }
 
299
                                            #~ if company_currency!=current_currency:
 
300
                                                #~ move_line['amount_currency']=currency_obj.compute(cr, uid, company_currency, current_currency,debit, round=False, context=context)
 
301
                                            #~ move_line_obj.create(cr,uid,move_line,context=context)
 
302
                                            #~ move_line_counterpart = {
 
303
                                                #~ 'journal_id': voucher.journal_id.id,
 
304
                                                #~ 'period_id': voucher.period_id.id,
 
305
                                                #~ 'name': _('change')+': '+(line.name or '/'),
 
306
                                                #~ 'account_id': tax.account_id.id,
 
307
                                                #~ 'move_id': int(move_id),
 
308
                                                #~ 'amount_currency': 0.0,
 
309
                                                #~ 'partner_id': voucher.partner_id.id,
 
310
                                                #~ 'currency_id': line.move_line_id and (company_currency <> current_currency and current_currency) or False,
 
311
                                                #~ 'quantity': 1,
 
312
                                                #~ 'credit': debit,
 
313
                                                #~ 'debit': credit,
 
314
                                                #~ 'date': line.voucher_id.date,
 
315
                                            #~ }
 
316
                                            #~ if company_currency!=current_currency:
 
317
                                                #~ move_line['amount_currency']=currency_obj.compute(cr, uid, company_currency, current_currency,debit, round=False, context=context)
 
318
                                            #~ move_ids.append(move_line_obj.create(cr,uid,move_line_counterpart,context=context))
 
319
                                            #~ print move_ids,"llega a este punto"
 
320
                                #~ for mov_line in invoice.move_id.line_id:
 
321
                                    #~ if mov_line.account_id.id==tax.account_id.id:
 
322
                                        #~ move_ids.append(mov_line.id)
 
323
                                #~ if line.amount==line.amount_original:
 
324
                                    #~ print move_ids,"lineasss"
 
325
                                    #~ print self.pool.get('account.move.line').reconcile(cr, uid, move_ids, 'manual', writeoff_acc_id=tax.account_id.id, writeoff_period_id=voucher.period_id.id, writeoff_journal_id=voucher.journal_id.id),"toma este dato"
 
326
                                #~ else:
 
327
                                    #~ print 'partial' 
 
328
                                    #~ self.pool.get('account.move.line').reconcile_partial(cr, uid, move_ids, 'manual', context)
 
329
            #~ self.write(cr,uid,voucher_id,{'move_id2':new_move},context=context)
 
330
        #~ return move_id
 
331
    
 
332
    def voucher_move_line_create(self, cr, uid, voucher_id, line_total, move_id, company_currency, current_currency, context=None):
 
333
        move_obj = self.pool.get('account.move')
 
334
        move_line_obj = self.pool.get('account.move.line')
 
335
        invoice_obj = self.pool.get('account.invoice')
 
336
        currency_obj = self.pool.get('res.currency')
 
337
        res=super(account_voucher, self).voucher_move_line_create(cr, uid, voucher_id, line_total, move_id, company_currency, current_currency, context=None)
 
338
        new=self.voucher_move_line_tax_create(cr,uid, voucher_id, move_id, context=context)
 
339
        return res
 
340
        
 
341
    def compute_tax(self, cr, uid, ids, context=None):
 
342
        move_obj = self.pool.get('account.move')
 
343
        move_line_obj = self.pool.get('account.move.line')
 
344
        invoice_obj = self.pool.get('account.invoice')
 
345
        currency_obj = self.pool.get('res.currency')
 
346
        tax_line_obj = self.pool.get('account.voucher.line.tax')
 
347
        for voucher in self.browse(cr, uid, ids, context=context):
 
348
            company_currency = self._get_company_currency(cr, uid, voucher.id, context)
 
349
            current_currency = self._get_current_currency(cr, uid, voucher.id, context)
 
350
            lines=[]
 
351
            for line in voucher.line_ids:
 
352
                delete_ids=tax_line_obj.search(cr , uid, [('voucher_line_id', '=' , line.id)], context=context)
 
353
                tax_line_obj.unlink(cr, uid, delete_ids, context=context)
 
354
                factor=self.get_percent_pay_vs_invoice(cr,uid,line.amount_original, line.amount,context=context)
 
355
                if line.amount>0:
 
356
                    invoice_ids=invoice_obj.search(cr,uid,[('move_id','=',line.move_line_id.move_id.id)],context=context)
 
357
                    for invoice in invoice_obj.browse(cr,uid,invoice_ids,context=context):
 
358
                        for tax in invoice.tax_line:
 
359
                            if tax.tax_id.tax_voucher_ok:
 
360
                                base_amount=self.get_partial_amount_tax_pay(cr, uid, tax.tax_id.amount, tax.base, context=context)
 
361
                                move_ids=[]
 
362
                                account=tax.tax_id.account_collected_voucher_id.id
 
363
                                credit_amount= float('%.*f' % (2,(base_amount*factor)))
 
364
                                if credit_amount:
 
365
                                    if abs(float('%.*f' % (2,credit_amount))-base_amount)<=.02:
 
366
                                        credit_amount=credit_amount-abs(float('%.*f' % (2,credit_amount))-base_amount)
 
367
                                    if abs(float('%.*f' % (2,credit_amount))+ (base_amount*(1-factor))-base_amount)<.02:
 
368
                                        credit_amount=credit_amount-abs(float('%.*f' % (2,credit_amount))+ (base_amount*(1-factor))-base_amount)
 
369
                                #context['date']=invoice.date_invoice
 
370
                                diff_amount_tax=0.0
 
371
                                diff_account_id=False
 
372
                                base_amount_curr=base_amount
 
373
                                if company_currency==current_currency:
 
374
                                    rate_move=self.get_rate(cr,uid,line.move_line_id.move_id.id,context=context)
 
375
                                    credit_amount=credit_amount*rate_move
 
376
                                else:
 
377
                                    credit_amount=currency_obj.compute(cr, uid, invoice.currency_id.id,current_currency, float('%.*f' % (2,credit_amount)), round=False, context=context)
 
378
                                    base_amount_curr=currency_obj.compute(cr, uid, invoice.currency_id.id,current_currency, float('%.*f' % (2,base_amount)), round=False, context=context)
 
379
                                    context['date']=invoice.date_invoice
 
380
                                    credit_orig=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,credit_amount)), round=False, context=context)
 
381
                                    context['date']=voucher.date
 
382
                                    credit_diff=currency_obj.compute(cr, uid, current_currency,company_currency, float('%.*f' % (2,credit_amount)), round=False, context=context)
 
383
 
 
384
                                    diff_amount_tax=currency_obj.compute(cr, uid, company_currency,current_currency, float('%.*f' % (2,(credit_orig-credit_diff))), round=False, context=context)
 
385
                                    if credit_orig>credit_diff:
 
386
                                        if voucher.type=='receipt':
 
387
                                            diff_account_id=tax.tax_id.account_expense_voucher_id.id
 
388
                                        else:
 
389
                                            diff_account_id=tax.tax_id.account_income_voucher_id.id
 
390
                                    if credit_orig<credit_diff:
 
391
                                        if voucher.type=='receipt':
 
392
                                            diff_account_id=tax.tax_id.account_income_voucher_id.id
 
393
                                        else:
 
394
                                            diff_account_id=tax.tax_id.account_expense_voucher_id.id
 
395
                                        
 
396
                                debit_amount=0.0
 
397
                                tax_line={
 
398
                                    'tax_id':tax.tax_id.id,
 
399
                                    'account_id':account,
 
400
                                    'amount_tax':credit_amount,
 
401
                                    'voucher_line_id':line.id,
 
402
                                    'original_tax':base_amount_curr,
 
403
                                    'diff_account_id':diff_account_id,
 
404
                                    'diff_amount_tax':abs(diff_amount_tax)
 
405
                                    
 
406
                                }
 
407
                                tax_line_obj.create(cr, uid, tax_line, context=context)
 
408
        return True
 
409
        
 
410
account_voucher()
 
411
 
 
412
class account_voucher_line(osv.osv):
 
413
    _inherit = 'account.voucher.line'
 
414
    
 
415
    _columns={
 
416
        'tax_line_ids':fields.one2many('account.voucher.line.tax', 'voucher_line_id', 'Tax Lines'),
 
417
        }
 
418
account_voucher_line()
 
419
 
 
420
 
 
421
class account_voucher_line_tax(osv.osv):
 
422
    _name= 'account.voucher.line.tax'
 
423
    
 
424
    _columns={
 
425
        'tax_id':fields.many2one('account.tax','Tax'),
 
426
        'account_id':fields.many2one('account.account','Account'),
 
427
        'amount_tax':fields.float('Amount Tax'),
 
428
        'original_tax':fields.float('Original Import Tax'),
 
429
        'balance_tax':fields.float('Balance Import Tax'),
 
430
        'diff_amount_tax':fields.float('Difference',digits_compute= dp.get_precision('Account')),
 
431
        'diff_account_id':fields.many2one('account.account','Account Diff'),
 
432
        'voucher_line_id':fields.many2one('account.voucher.line', 'Voucher Line'),
 
433
        
 
434
    }
 
435
account_voucher_line_tax()