[IMP] removal of usages of the deprecated node.getchildren call, better usage of...
[odoo/odoo.git] / addons / account_voucher / voucher.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 import time
24 import netsvc
25 from osv import fields, osv
26 import ir
27 import pooler
28 import mx.DateTime
29 from mx.DateTime import RelativeDateTime
30 from tools import config
31
32 class ir_sequence_type(osv.osv):
33     _inherit = "ir.sequence.type"
34     _columns = {
35         'name': fields.char('Sequence Name',size=128, required=True),
36         'code': fields.char('Sequence Code',size=128, required=True),
37     }
38 ir_sequence_type()
39
40 class account_voucher(osv.osv):
41     def _get_period(self, cr, uid, context):
42         periods = self.pool.get('account.period').find(cr, uid)
43         if periods:
44             return periods[0]
45         else:
46             return False
47         
48     def _get_type(self, cr, uid, context={}):
49         type = context.get('type', 'rec_voucher')
50         return type
51     
52     def _get_reference_type(self, cursor, user, context=None):
53         return [('none', 'Free Reference')]
54     
55     def _get_journal(self, cr, uid, context):
56         type_inv = 'rec_voucher'
57         
58         if type(context) == type(''):
59             type_inv = context
60         elif type(context) == type({}):
61             type_inv = context.get('type', 'rec_voucher')
62
63         type2journal = {
64             'rec_voucher': 'cash', 
65             'bank_rec_voucher': 'cash',
66             'pay_voucher': 'cash',
67             'bank_pay_voucher': 'cash', 
68             'cont_voucher': 'cash',
69             'journal_sale_vou': 'sale',
70             'journal_pur_voucher': 'purchase',
71             'journal_voucher':'expanse'
72         }
73         
74         journal_obj = self.pool.get('account.journal')
75         ttype = type2journal.get(type_inv, 'cash')
76         res = journal_obj.search(cr, uid, [('type', '=', ttype)], limit=1)
77         
78         if res:
79             return res[0]
80         else:
81             return False
82         
83     def _get_currency(self, cr, uid, context):
84         user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, [uid])[0]
85         if user.company_id:
86             return user.company_id.currency_id.id
87         else:
88             return pooler.get_pool(cr.dbname).get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
89         
90     _name = 'account.voucher'
91     _description = 'Accounting Voucher'
92     _order = "number"
93     _columns = {
94         'name':fields.char('Name', size=256, required=True, readonly=True, states={'draft':[('readonly',False)]}),
95         'type': fields.selection([
96             ('pay_voucher','Cash Payment Voucher'),
97             ('bank_pay_voucher','Bank Payment Voucher'),
98             ('rec_voucher','Cash Receipt Voucher'),
99             ('bank_rec_voucher','Bank Receipt Voucher'),
100             ('cont_voucher','Contra Voucher'),
101             ('journal_sale_vou','Journal Sale Voucher'),
102             ('journal_pur_voucher','Journal Purchase Voucher'),
103             ('journal_voucher','Journal Voucher'),
104             ],'Type', readonly=True, select=True , size=128),
105         'date':fields.date('Date', readonly=True, states={'draft':[('readonly',False)]}),
106         'journal_id':fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}),
107         'account_id':fields.many2one('account.account', 'Account', required=True, readonly=True, states={'draft':[('readonly',False)]}),
108         'payment_ids':fields.one2many('account.voucher.line','voucher_id','Voucher Lines', readonly=False, states={'proforma':[('readonly',True)]}),
109         'period_id': fields.many2one('account.period', 'Period', required=True, states={'posted':[('readonly',True)]}),
110         'narration':fields.text('Narration', readonly=True, states={'draft':[('readonly',False)]}, required=True),
111         'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}),
112         'company_id': fields.many2one('res.company', 'Company', required=True),
113         'state':fields.selection(
114                     [('draft','Draft'),
115                      ('proforma','Pro-forma'),
116                      ('posted','Posted'),
117                      ('cancel','Cancel')
118                     ], 'State', 
119                     readonly=True),
120         'amount':fields.float('Amount', readonly=True),
121         'number':fields.char('Number', size=32, readonly=True),
122         'reference': fields.char('Voucher Reference', size=64),
123         'reference_type': fields.selection(_get_reference_type, 'Reference Type',
124             required=True),
125         'move_id':fields.many2one('account.move', 'Account Entry'),
126         'move_ids':fields.many2many('account.move.line', 'voucher_id', 'account_id', 'rel_account_move', 'Real Entry'),
127         'partner_id':fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]})
128     }
129     
130     _defaults = {
131         'state': lambda *a: 'draft',
132         'date' : lambda *a: time.strftime('%Y-%m-%d'),
133         'period_id': _get_period,
134         'type': _get_type,
135         'reference_type': lambda *a: 'none',
136         'journal_id':_get_journal,
137         'company_id': lambda self, cr, uid, context: \
138                 self.pool.get('res.users').browse(cr, uid, uid,
139                     context=context).company_id.id,
140         'currency_id': _get_currency,
141     }
142     
143     def _get_analityc_lines(self, cr, uid, id):
144         inv = self.browse(cr, uid, [id])[0]
145         cur_obj = self.pool.get('res.currency')
146         
147     def onchange_account(self, cr, uid, ids, account_id):
148         if not account_id:
149             return {'value':{'amount':False}}
150         account = self.pool.get('account.account').browse(cr,uid,account_id)
151         balance=account.balance
152         return {'value':{'amount':balance}}
153
154     def onchange_journal(self, cr, uid, ids, journal_id,type):
155         if not journal_id:
156             return {'value':{'account_id':False}}
157         journal = self.pool.get('account.journal')
158         if journal_id and (type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher','journal_voucher')):
159             account_id = journal.browse(cr, uid, journal_id).default_debit_account_id
160             return {'value':{'account_id':account_id.id}}
161         elif journal_id and (type in ('pay_voucher','bank_pay_voucher','journal_sale_vou')) :
162                 account_id = journal.browse(cr, uid, journal_id).default_credit_account_id
163                 return {'value':{'account_id':account_id.id}}
164         else:
165             account_id = journal.browse(cr, uid, journal_id).default_credit_account_id
166             return {'value':{'account_id':account_id.id}}
167         
168     def open_voucher(self, cr, uid, ids, context={}):
169         obj=self.pool.get('account.voucher').browse(cr,uid,ids)
170         total=0
171         for i in obj[0].payment_ids:
172             total+=i.amount
173         self.write(cr,uid,ids,{'amount':total})
174         self.write(cr, uid, ids, {'state':'proforma'})
175         return True
176     
177     def proforma_voucher(self, cr, uid, ids, context={}):
178         self.action_number(cr, uid, ids)
179         self.action_move_line_create(cr, uid, ids)
180         self.write(cr, uid, ids, {'state':'posted'})
181         return True
182     
183     def cancel_voucher(self,cr,uid,ids,context={}):
184         self.action_cancel(cr, uid, ids)
185         self.write(cr, uid, ids, {'state':'cancel'})
186         return True
187         
188     def action_cancel_draft(self, cr, uid, ids, *args):
189         self.write(cr, uid, ids, {'state':'draft'})
190         return True
191
192     def unlink(self, cr, uid, ids, context={}):
193         vouchers = self.read(cr, uid, ids, ['state'])
194         unlink_ids = []
195         for t in vouchers:
196             if t['state'] in ('draft', 'cancel'):
197                 unlink_ids.append(t['id'])
198             else:
199                 raise osv.except_osv('Invalid action !', 'Cannot delete invoice(s) which are already opened or paid !')
200         osv.osv.unlink(self, cr, uid, unlink_ids)
201         return True
202          
203     def _get_analytic_lines(self, cr, uid, id):
204         inv = self.browse(cr, uid, [id])[0]
205         cur_obj = self.pool.get('res.currency')
206
207         company_currency = inv.company_id.currency_id.id
208         if inv.type in ('rec_voucher'):
209             sign = 1
210         else:
211             sign = -1
212
213         iml = self.pool.get('account.voucher.line').move_line_get(cr, uid, inv.id)
214         
215         for il in iml:
216             if il['account_analytic_id']:
217                 if inv.type in ('pay_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'):
218                     ref = inv.reference
219                 else:
220                     ref = self._convert_ref(cr, uid, inv.number)
221                     
222                 il['analytic_lines'] = [(0, 0, {
223                     'name': il['name'],
224                     'date': inv['date'],
225                     'account_id': il['account_analytic_id'],
226                     'amount': inv['amount'] * sign,
227                     'general_account_id': il['account_id'] or False,
228                     'journal_id': self.pool.get('account.voucher').browse(cr, uid, id).journal_id.analytic_journal_id.id or False,
229                     'ref': ref,
230                 })]
231         return iml
232     
233     def action_move_line_create(self, cr, uid, ids, *args):
234         for inv in self.browse(cr, uid, ids):
235             if inv.move_id:
236                 continue
237             company_currency = inv.company_id.currency_id.id
238
239             line_ids = self.read(cr, uid, [inv.id], ['payment_ids'])[0]['payment_ids']
240             ils = self.pool.get('account.voucher.line').read(cr, uid, line_ids)
241
242             iml = self._get_analytic_lines(cr, uid, inv.id)
243
244             diff_currency_p = inv.currency_id.id <> company_currency
245
246             total = 0
247             if inv.type in ('pay_voucher', 'journal_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'):
248                 ref = inv.reference
249             else:
250                 ref = self._convert_ref(cr, uid, inv.number)
251                 
252             date = inv.date
253             total_currency = 0
254             acc_id = None
255             for i in iml:
256                 partner_id=i['partner_id']
257                 acc_id = i['account_id']    
258                 if inv.currency_id.id != company_currency:
259                     i['currency_id'] = inv.currency_id.id
260                     i['amount_currency'] = i['amount']
261                 else:
262                     i['amount_currency'] = False
263                     i['currency_id'] = False
264                 if inv.type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher','journal_voucher'):
265                     total += i['amount']
266                     total_currency += i['amount_currency'] or i['amount']
267                     i['amount'] = - i['amount']
268                 else:
269                     total -= i['amount']
270                     total_currency -= i['amount_currency'] or i['amount']
271
272             name = inv['name'] or '/'
273             totlines = False
274
275             iml.append({
276                 'type': 'dest',
277                 'name': name,
278                 'amount': total or False,
279                 'account_id': acc_id,
280                 'amount_currency': diff_currency_p \
281                         and total_currency or False,
282                 'currency_id': diff_currency_p \
283                         and inv.currency_id.id or False,
284                 'ref': ref,
285                 'partner_id':partner_id or False,
286             })
287
288             date = inv.date
289             inv.amount=total
290
291             line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml)
292             an_journal_id=inv.journal_id.analytic_journal_id.id
293             journal_id = inv.journal_id.id
294             
295             journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
296             if journal.sequence_id:
297                 name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id)
298
299             move = {
300                 'name': name, 
301                 'journal_id': journal_id, 
302                 'voucher_type':inv.type,
303                 'narration' : inv.narration
304             }
305             if inv.period_id:
306                 move['period_id'] = inv.period_id.id
307                 for i in line:
308                     i[2]['period_id'] = inv.period_id.id
309             move_id = self.pool.get('account.move').create(cr, uid, move)
310             ref = move['name']
311             amount=0.0
312             
313             #create the first line our self
314             move_line = {
315                 'name': inv.name,
316                 'debit': False,
317                 'credit':False,
318                 'account_id': inv.account_id.id or False,
319                 'move_id':move_id ,
320                 'journal_id':journal_id ,
321                 'period_id':inv.period_id.id,
322                 'partner_id': False,
323                 'ref': ref, 
324                 'date': inv.date
325             }
326             if inv.type in ('rec_voucher', 'bank_rec_voucher', 'journal_pur_voucher', 'journal_voucher'):
327                 move_line['debit'] = inv.amount
328             else:
329                 move_line['credit'] = inv.amount * (-1)
330             self.pool.get('account.move.line').create(cr, uid, move_line)
331             
332             for line in inv.payment_ids:
333                 
334                 move_line = {
335                     'name':line.name,
336                      'debit':False,
337                      'credit':False,
338                      'account_id':line.account_id.id or False,
339                      'move_id':move_id ,
340                      'journal_id':journal_id ,
341                      'period_id':inv.period_id.id,
342                      'partner_id':line.partner_id.id or False,
343                      'ref':ref, 
344                      'date':inv.date
345                  }
346                 
347                 if line.type == 'dr':
348                     move_line['debit'] = line.amount or False
349                     amount=line.amount
350                 elif line.type == 'cr':
351                     move_line['credit'] = line.amount or False
352                     amount=line.amount * (-1)
353                 
354                 ml_id=self.pool.get('account.move.line').create(cr, uid, move_line)
355                 
356                 if inv.narration:
357                     line.name=inv.narration
358                 else:
359                     line.name=line.name
360                 
361                 if line.account_analytic_id:
362                     an_line = {
363                          'name':line.name,
364                          'date':inv.date,
365                          'amount':amount,
366                          'account_id':line.account_analytic_id.id or False,
367                          'move_id':ml_id,
368                          'journal_id':an_journal_id ,
369                          'general_account_id':line.account_id.id,
370                          'ref':ref
371                      }
372                     self.pool.get('account.analytic.line').create(cr,uid,an_line)
373                 
374             self.write(cr, uid, [inv.id], {'move_id': move_id})
375             obj=self.pool.get('account.move').browse(cr, uid, move_id)
376             
377             for line in obj.line_id :
378                 cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id)))
379                 
380         return True
381
382     
383     def line_get_convert(self, cr, uid, x, date, context={}):
384        
385         return {
386             'date':date,
387             'date_maturity': x.get('date_maturity', False),
388             'partner_id':x.get('partner_id',False),
389             'name':x['name'][:64],
390             'debit':x['amount']>0 and x['amount'],
391             'credit':x['amount']<0 and -x['amount'],
392             'account_id':x['account_id'],
393             'analytic_lines':x.get('analytic_lines', []),
394             'amount_currency':x.get('amount_currency', False),
395             'currency_id':x.get('currency_id', False),
396             'tax_code_id': x.get('tax_code_id', False),
397             'tax_amount': x.get('tax_amount', False),
398             'ref':x.get('ref',False)
399         }
400     def _convert_ref(self, cr, uid, ref):
401         return (ref or '').replace('/','')
402     
403     
404     def action_number(self, cr, uid, ids, *args):
405         cr.execute('SELECT id, type, number, move_id, reference ' \
406                 'FROM account_voucher ' \
407                 'WHERE id IN ('+','.join(map(str,ids))+')')
408         for (id, invtype, number, move_id, reference) in cr.fetchall():
409             if not number:
410                 number = self.pool.get('ir.sequence').get(cr, uid, invtype)
411
412                 if type in ('pay_voucher', 'journal_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'):
413                     ref = reference
414                 else:
415                     ref = self._convert_ref(cr, uid, number)
416                     
417                 cr.execute('UPDATE account_voucher SET number=%s ' \
418                         'WHERE id=%d', (number, id))
419                 cr.execute('UPDATE account_move_line SET ref=%s ' \
420                         'WHERE move_id=%d AND (ref is null OR ref = \'\')',
421                         (ref, move_id))
422                 cr.execute('UPDATE account_analytic_line SET ref=%s ' \
423                         'FROM account_move_line ' \
424                         'WHERE account_move_line.move_id = %d ' \
425                             'AND account_analytic_line.move_id = account_move_line.id',
426                             (ref, move_id))
427         return True
428
429
430     
431     def name_get(self, cr, uid, ids, context={}):
432         if not len(ids):
433             return []
434         types = {
435                 'pay_voucher': 'CPV: ',
436                 'rec_voucher': 'CRV: ',
437                 'cont_voucher': 'CV: ',
438                 'bank_pay_voucher': 'BPV: ',
439                 'bank_rec_voucher': 'BRV: ',
440                 'journal_sale_vou': 'JSV: ',
441                 'journal_pur_voucher': 'JPV: ',
442                 'journal_voucher':'JV'
443         }
444         return [(r['id'], types[r['type']]+(r['number'] or '')+' '+(r['name'] or '')) for r in self.read(cr, uid, ids, ['type', 'number', 'name'], context, load='_classic_write')]
445
446     def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
447         if not args:
448             args=[]
449         if not context:
450             context={}
451         ids = []
452         if name:
453             ids = self.search(cr, user, [('number','=',name)]+ args, limit=limit, context=context)
454         if not ids:
455             ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
456         return self.name_get(cr, user, ids, context)
457     
458     def copy(self, cr, uid, id, default=None, context=None):
459         if default is None:
460             default = {}
461         default = default.copy()
462         default.update({'state':'draft', 'number':False, 'move_id':False, 'move_ids':False, 'payment_ids':False})
463         if 'date' not in default:
464             default['date'] = time.strftime('%Y-%m-%d')
465         return super(account_voucher, self).copy(cr, uid, id, default, context)
466     
467     def action_cancel(self, cr, uid, ids, *args):
468         account_move_obj = self.pool.get('account.move')
469         voucher = self.read(cr, uid, ids, ['move_id'])
470         for i in voucher:
471             if i['move_id']:
472                 account_move_obj.button_cancel(cr, uid, [i['move_id'][0]])
473                 # delete the move this invoice was pointing to
474                 # Note that the corresponding move_lines and move_reconciles
475                 # will be automatically deleted too
476                 account_move_obj.unlink(cr, uid, [i['move_id'][0]])
477         self.write(cr, uid, ids, {'state':'cancel', 'move_id':False})
478         return True
479     
480 account_voucher()
481
482 class VoucherLine(osv.osv):
483     _name = 'account.voucher.line'
484     _description = 'Voucher Line'
485     _columns = {
486         'voucher_id':fields.many2one('account.voucher', 'Voucher'),
487         'name':fields.char('Description', size=256, required=True),
488         'account_id':fields.many2one('account.account','Account', required=True),
489         'partner_id': fields.many2one('res.partner', 'Partner', change_default=True),
490         'amount':fields.float('Amount'),
491         'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Type'),
492         'ref':fields.char('Ref.', size=32),
493         'account_analytic_id':  fields.many2one('account.analytic.account', 'Analytic Account')
494     }
495     _defaults = {
496         'type': lambda *a: 'cr'
497     }
498     
499     def move_line_get(self, cr, uid, voucher_id, context={}):
500         res = []
501
502         cur_obj = self.pool.get('res.currency')
503         inv = self.pool.get('account.voucher').browse(cr, uid, voucher_id)
504         company_currency = inv.company_id.currency_id.id
505         cur = inv.currency_id
506
507         for line in inv.payment_ids:
508             res.append(self.move_line_get_item(cr, uid, line, context))
509         return res
510     
511     def onchange_partner(self, cr, uid, ids, partner_id, ttype ,type1):
512         if not partner_id:
513             return {'value' : {'account_id' : False, 'type' : False ,'amount':False}}
514         obj = self.pool.get('res.partner')
515         account_id = False
516         if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
517             account_id = obj.browse(cr, uid, partner_id).property_account_receivable
518             balance = obj.browse(cr,uid,partner_id).credit
519             ttype = 'cr'
520         elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : 
521             account_id = obj.browse(cr, uid, partner_id).property_account_payable
522             balance = obj.browse(cr,uid,partner_id).debit
523             ttype = 'dr'
524         elif type1 in ('journal_sale_vou') : 
525             account_id = obj.browse(cr, uid, partner_id).property_account_receivable
526             balance = obj.browse(cr,uid,partner_id).credit
527             ttype = 'dr'
528         elif type1 in ('journal_pur_voucher') : 
529             account_id = obj.browse(cr, uid, partner_id).property_account_payable
530             balance = obj.browse(cr,uid,partner_id).debit
531             ttype = 'cr'   
532         
533         return {
534             'value' : {'account_id' : account_id.id, 'type' : ttype, 'amount':balance}
535         }
536         
537     def onchange_amount(self, cr, uid, ids,partner_id,amount, type,type1):
538         if not amount:
539             return {'value' : {}}
540         if partner_id:
541             
542             obj = self.pool.get('res.partner')
543             if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
544                 if amount < 0 :
545                     account_id = obj.browse(cr, uid, partner_id).property_account_payable 
546                     type = 'dr'
547                 else:
548                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable 
549                     type = 'cr'
550                
551             elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : 
552                 if amount < 0 :
553                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable 
554                     type = 'cr'
555                 else:
556                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
557                     type = 'dr'
558                     
559             elif type1 in ('journal_sale_vou') : 
560                 if amount < 0 :
561                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
562                     type = 'cr'
563                 else:
564                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable
565                     type = 'dr'
566                 
567             elif type1 in ('journal_pur_voucher') : 
568                 if amount< 0 :
569                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable
570                     type = 'dr'
571                 else:
572                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
573                     type = 'cr'
574         else:
575             if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'):
576                 if amount < 0 :
577                      
578                     type = 'dr'
579                 else:
580                    
581                     type = 'cr'
582                
583             elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : 
584                 if amount < 0 :
585                     
586                     type = 'cr'
587                 else:
588                    
589                     type = 'dr'
590                     
591             elif type1 in ('journal_sale_vou') : 
592                 if amount < 0 :
593                    
594                     type = 'cr'
595                 else:
596                    
597                     type = 'dr'
598                 
599             elif type1 in ('journal_pur_voucher') : 
600                 if amount< 0 :
601                     
602                     type = 'dr'
603                 else:
604                    
605                     type = 'cr'
606                 
607         return {
608             'value' : { 'type' : type , 'amount':amount}
609         }
610         
611     def onchange_type(self, cr, uid, ids,partner_id,amount,type,type1):
612         if partner_id:
613            
614             obj = self.pool.get('res.partner')
615         
616             if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
617                 if type == 'dr' :
618                     account_id = obj.browse(cr, uid, partner_id).property_account_payable 
619                     total=amount*(-1)
620                 else:
621                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable 
622                     total=amount*(-1)
623                
624             elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : 
625                 if type == 'cr' :
626                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable 
627                     total=amount*(-1)
628                 else:
629                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
630                     total=amount*(-1)
631                     
632             elif type1 in ('journal_sale_vou') : 
633                 if type == 'cr' :
634                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
635                     total=amount*(-1)
636                 else:
637                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable
638                     total=amount*(-1)
639                 
640             elif type1 in ('journal_pur_voucher') : 
641                 if type == 'dr' :
642                     account_id = obj.browse(cr, uid, partner_id).property_account_receivable
643                     total=amount*(-1)
644                 else:
645                     account_id = obj.browse(cr, uid, partner_id).property_account_payable
646                     total=amount*(-1)
647         else:
648             if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'):
649                 if type == 'dr' :
650     
651                     total=amount*(-1)
652                 else:
653     
654                     total=amount*(-1)
655                
656             elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : 
657                 if type == 'cr' :
658     
659                     total=amount*(-1)
660                 else:
661     
662                     total=amount*(-1)
663                     
664             elif type1 in ('journal_sale_vou') : 
665                 if type == 'cr' :
666     
667                     total=amount*(-1)
668                 else:
669     
670                     total=amount*(-1)
671                 
672             elif type1 in ('journal_pur_voucher') : 
673                 if type == 'dr' :
674     
675                     total=amount*(-1)
676                 else:
677     
678                     total=amount*(-1)
679                     
680         return {
681             'value' : {'type' : type , 'amount':total}
682         }
683         
684     def move_line_get_item(self, cr, uid, line, context={}):
685         return {
686             'type':'src',
687             'name': line.name[:64],
688             'amount':line.amount,
689             'account_id':line.account_id.id,
690             'partner_id':line.partner_id.id or False ,
691             'account_analytic_id':line.account_analytic_id.id or False,
692             'ref' : line.ref
693         }
694         
695 VoucherLine()
696
697
698
699
700
701