From 4fe6490c96ea09669c29a5076dd9b7f9234ec2b7 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Mon, 23 Aug 2010 16:39:08 +0530 Subject: [PATCH] [IMP]: improve account voucher module * improve sale receipt tax calculation * improve the reconcle process bzr revid: mga@tinyerp.com-20100823110908-fwk6v14i8k339ebu --- addons/account_voucher/voucher.py | 127 +++++++++++------- .../voucher_payment_receipt_view.xml | 7 +- .../voucher_sales_purchase_view.xml | 4 +- addons/account_voucher/voucher_workflow.xml | 75 ++++------- 4 files changed, 105 insertions(+), 108 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index f7e730566ce..7835a4a4135 100644 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -196,7 +196,7 @@ class account_voucher(osv.osv): \n* The \'Cancelled\' state is used when user cancel voucher.'), #'amount': fields.function(_compute_total, method=True, type='float', digits=(14,2), string='Total', store=True), 'amount': fields.float('Total', digits=(16, 2), readonly=True, states={'draft':[('readonly',False)]}), - 'tax_amount':fields.float('Tax Amount', digits=(14,4), readonly=True, states={'draft':[('readonly',False)]}), + 'tax_amount':fields.float('Tax Amount', digits=(14,2), readonly=True, states={'draft':[('readonly',False)]}), 'reference': fields.char('Ref #', size=64, readonly=True, states={'draft':[('readonly',False)]}, help="Payment or Receipt transaction number, i.e. Bank cheque number or payorder number or Wire transfer number or Acknowledge number."), 'number': fields.related('move_id', 'name', type="char", readonly=True, string='Number'), 'move_id':fields.many2one('account.move', 'Account Entry'), @@ -223,26 +223,43 @@ class account_voucher(osv.osv): 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c), } - def onchange_price(self, cr, uid, ids, payment_ids, tax_amount, tax_id, context={}): + def onchange_price(self, cr, uid, ids, payment_ids, tax_id, partner_id=False, context={}): + tax_pool = self.pool.get('account.tax') + partner_pool = self.pool.get('res.partner') + position_pool = self.pool.get('account.fiscal.position') + res = { 'tax_amount':False, 'amount':False } - tax_pool = self.pool.get('account.tax') + + untax_amount = 0.0 + tax_amount = 0.0 total = 0.0 - + for line in payment_ids: total += line[2].get('amount') - - if tax_id: - tax = tax_pool.browse(cr, uid, tax_id) - if tax.type == 'percent': - tax_amount = total * tax_amount and tax_amount or tax.amount - if tax.type == 'fixed': - tax_amount = tax_amount and tax_amount or tax.amount + if tax_amount: + tax_amount = 0.0 + + if tax_id: + tax_id = tax_id + tax = [tax_pool.browse(cr, uid, tax_id)] + + if partner_id: + partner = partner_pool.browse(cr, uid, partner_id) or False + taxes = position_pool.map_tax(cr, uid, partner and partner.property_account_position or False, tax) + tax = tax_pool.browse(cr, uid, taxes) + + for tax_line in tax_pool.compute_all(cr, uid, tax, total, 1).get('taxes'): + tax_amount += tax_line.get('amount') + untax_amount += tax_line.get('price_unit') + else: + untax_amount = total + res.update({ - 'amount':total + tax_amount, + 'amount':untax_amount, 'tax_amount':tax_amount }) @@ -333,10 +350,10 @@ class account_voucher(osv.osv): }) default = { - 'value':{}, + 'value':{'payment_ids':[],'amount':0.0}, 'context':context, } - if not partner_id or not ttype: + if not partner_id: if ids: line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])]) if line_ids: @@ -388,7 +405,7 @@ class account_voucher(osv.osv): if ttype == 'payment': rs.update({ - 'account_id':line.move_id.partner_id.property_account_payable.id, + 'account_id':line.account_id, #line.move_id.partner_id.property_account_payable.id, #'amount':line.credit }) amount = line.credit @@ -463,7 +480,7 @@ class account_voucher(osv.osv): def proforma_voucher(self, cr, uid, ids, context={}): self.action_move_line_create(cr, uid, ids) - self.write(cr, uid, ids, {'state':'posted'}) + #self.write(cr, uid, ids, ) return True def action_cancel_draft(self, cr, uid, ids, context={}): @@ -482,10 +499,6 @@ class account_voucher(osv.osv): move_pool.button_cancel(cr, uid, [voucher.move_id.id]) move_pool.unlink(cr, uid, [voucher.move_id.id]) - line_ids = voucher_line_pool.search(cr, uid, [('voucher_id','=',voucher.id), ('is_tax','=',True)]) - if line_ids: - voucher_line_pool.unlink(cr, uid, line_ids) - res = { 'state':'cancel', 'move_id':False, @@ -593,19 +606,26 @@ class account_voucher(osv.osv): 'amount_currency':amount_currency, 'currency_id':inv.currency_id.id }) - + + total_amount = 0.0 + if inv.tax_amount: + total_amount = inv.amount + inv.tax_amount + if inv.type in ('sale', 'receipt'): move_line.update({ - 'debit':inv.amount + 'debit':total_amount }) elif inv.type == 'purchase': move_line.update({ - 'credit':inv.amount - }) + 'credit':total_amount + }) line_ids = [] - line_ids += [move_line_pool.create(cr, uid, move_line)] - + master_line = move_line_pool.create(cr, uid, move_line) + line_ids += [master_line] + rec_list_ids = [] + line_total = 0.0 + for line in inv.payment_ids: rec_ids = [] amount=0.0 @@ -640,6 +660,7 @@ class account_voucher(osv.osv): 'analytic_account_id':line.account_analytic_id.id }) + line_total += line.amount if inv.type in ('sale', 'receipt'): move_line.update({ 'credit': line.amount or False @@ -655,14 +676,11 @@ class account_voucher(osv.osv): if inv.type in ('payment', 'receipt') and line.move_id: rec_ids += [move_line_id] -# for move_line in line.move_id.line_id: -# if line.account_id.id == move_line.account_id.id: if line.move_line_id: rec_ids += [line.move_line_id.id] - + if rec_ids: - cr.commit() - move_line_pool.reconcile_partial(cr, uid, rec_ids) + rec_list_ids.append(rec_ids) if inv.type in ('sale', 'purchase') and inv.tax_amount > 0: name = '/' @@ -696,17 +714,36 @@ class account_voucher(osv.osv): move_line_id = move_line_pool.create(cr, uid, move_line) line_ids += [move_line_id] - + + if line_total != inv.amount and inv.type in ('payment', 'receipt'): + name = '/' + + move_line = { + 'name':name, + 'account_id':False, + 'move_id':move_id , + 'journal_id':inv.journal_id.id, + 'period_id':inv.period_id.id, + 'partner_id':inv.partner_id.id, + 'ref':ref, + 'date':inv.date + } + account_id = False + rec = { - 'move_id': move_id + 'move_id': move_id, + 'state':'posted' } - message = _('Voucher ') + " '" + inv.name + "' "+ _("is confirm") - self.log(cr, uid, inv.id, message) - self.write(cr, uid, [inv.id], rec) move_pool.post(cr, uid, [move_id], context={}) - + for rec_ids in rec_list_ids: + move_line_pool.reconcile_partial(cr, uid, rec_ids) + + inv = self.browse(cr, uid, inv.id) + name = inv.name and inv.name or inv.number + message = _('Voucher ') + " '" + str(name) + "' "+ _("is confirm") + self.log(cr, uid, inv.id, message) return True def _convert_ref(self, cr, uid, ref): @@ -767,7 +804,7 @@ class account_voucher_line(osv.osv): _columns = { 'voucher_id':fields.many2one('account.voucher', 'Voucher'), - 'name':fields.char('Description', size=256, required=True), + 'name':fields.char('Description', size=256), 'account_id':fields.many2one('account.account','Account', required=True, domain=[('type','<>','view')]), 'partner_id':fields.related('voucher_id', 'partner_id', type='many2one', relation='res.partner', string='Partner'), 'amount':fields.float('Amount'), @@ -789,20 +826,6 @@ class account_voucher_line(osv.osv): 'name': lambda *a: '/' } -# def create(self, cr, user, vals, context={}): -# """ -# Create a new record for a model account_voucher_line -# @param cr: A database cursor -# @param user: ID of the user currently logged in -# @param vals: provides data for new record -# @param context: context arguments, like lang, time zone -# -# @return: Returns an id of the new record -# """ -# if vals.get('account_id') -# res_id = super(account_voucher_line, self).create(cr, user, vals, context) -# return res_id - def onchange_move_line_id(self, cr, user, ids, move_line_id, context={}): """ Returns a dict that contains new values and context diff --git a/addons/account_voucher/voucher_payment_receipt_view.xml b/addons/account_voucher/voucher_payment_receipt_view.xml index 02c7d7dee57..06d77904dba 100644 --- a/addons/account_voucher/voucher_payment_receipt_view.xml +++ b/addons/account_voucher/voucher_payment_receipt_view.xml @@ -16,7 +16,7 @@ - + @@ -86,7 +86,7 @@ string="Payment Method"/> - + - + + diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 8a7e9a61f0f..af7baf78bd3 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -17,7 +17,7 @@ - + @@ -43,7 +43,7 @@ - + diff --git a/addons/account_voucher/voucher_workflow.xml b/addons/account_voucher/voucher_workflow.xml index 961032458c9..9c4f2d15e71 100644 --- a/addons/account_voucher/voucher_workflow.xml +++ b/addons/account_voucher/voucher_workflow.xml @@ -7,18 +7,11 @@ True - - - - - - True proforma write({'state':'draft'}) - function @@ -30,12 +23,12 @@ True - - - recheck - voucher_recheck() - function - + + + + + + @@ -44,52 +37,32 @@ cancel_voucher() function - - - - - - - - - - - - - - proforma_voucher - amount <= journal_id.max_amount + True - - - - proforma_voucher - amount > journal_id.max_amount - - - - - - recheck_voucher - - - - - - + + + + + + + + + + + + + + + + + - - - - - cancel_voucher -