From bd1b5674537d536d304b971fd32f9cebb57caaf2 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Tue, 14 Sep 2010 18:43:29 +0530 Subject: [PATCH] [FIX]: fix for the journal voucher bzr revid: mga@tinyerp.com-20100914131329-41dylw1tfaiymeap --- addons/account_voucher/voucher.py | 42 +++++++++++++++++++++++-- addons/account_voucher/voucher_view.xml | 8 ++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index f3ad12dcf0b..45e4cf62fe5 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -196,7 +196,6 @@ class account_voucher(osv.osv): self.write(cr, uid, [voucher.id], {'amount':total, 'tax_amount':total_tax}) return True - # TODO: review this code. def onchange_price(self, cr, uid, ids, line_ids, tax_id, partner_id=False, context={}): tax_pool = self.pool.get('account.tax') partner_pool = self.pool.get('res.partner') @@ -255,6 +254,44 @@ class account_voucher(osv.osv): }) return {'value':default} + def onchange_journal_voucher(self, cr, uid, ids, partner_id=False, journal_id=False, context={}): + """price + Returns a dict that contains new values and context + + @param partner_id: latest value from user input for field partner_id + @param args: other arguments + @param context: context arguments, like lang, time zone + + @return: Returns a dict which contains new values, and context + """ + default = { + 'value':{}, + } + + if not journal_id or not journal_id: + return default + + partner_pool = self.pool.get('res.partner') + journal_pool = self.pool.get('account.journal') + + journal = journal_pool.browse(cr, uid, journal_id) + partner = partner_pool.browse(cr, uid, partner_id) + account_id = False + tr_type = False + if journal.type in ('sale','sale_refund'): + account_id = partner.property_account_receivable.id + tr_type = 'sale' + elif journal.type in ('purchase', 'purchase_refund','expense'): + account_id = partner.property_account_payable.id + tr_type = 'purchase' + else: + account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id + tr_type = 'receipt' + + default['value']['account_id'] = account_id + default['value']['type'] = tr_type + return default + def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id=False, price=0.0, currency_id=False, ttype=False, context={}): """price Returns a dict that contains new values and context @@ -440,7 +477,7 @@ class account_voucher(osv.osv): raise osv.except_osv(_('Invalid action !'), _('Cannot delete Voucher(s) which are already opened or paid !')) return super(account_voucher, self).unlink(cr, uid, ids, context=context) - # TODO + # TODO: may be we can remove this method if not used anyware def onchange_payment(self, cr, uid, ids, pay_now, journal_id, partner_id, ttype='sale'): res = {} if not partner_id: @@ -755,6 +792,7 @@ class account_voucher_line(osv.osv): ttype = 'cr' if journal.type in ('sale', 'purchase_refund'): account_id = journal.default_credit_account_id and journal.default_credit_account_id.id or False + ttype = 'cr' elif journal.type in ('purchase', 'expense', 'sale_refund'): account_id = journal.default_debit_account_id and journal.default_debit_account_id.id or False ttype = 'dr' diff --git a/addons/account_voucher/voucher_view.xml b/addons/account_voucher/voucher_view.xml index ebf19eb5969..0a86a7f76e6 100644 --- a/addons/account_voucher/voucher_view.xml +++ b/addons/account_voucher/voucher_view.xml @@ -20,7 +20,7 @@ - + account.voucher.form account.voucher @@ -28,11 +28,11 @@
+ + + - - -