[IMP]: improve account voucher module

* improve sale receipt tax calculation
* improve the reconcle process

bzr revid: mga@tinyerp.com-20100823110908-fwk6v14i8k339ebu
This commit is contained in:
Mantavya Gajjar
2010-08-23 16:39:08 +05:30
parent 8bff08ad12
commit 4fe6490c96
4 changed files with 105 additions and 108 deletions
+75 -52
View File
@@ -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
@@ -16,7 +16,7 @@
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="payment_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<field name="payment_ids" on_change="onchange_price(payment_ids, False, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<tree string="Payment Lines" editable="bottom">
<field name="ref" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="amount"/>
@@ -86,7 +86,7 @@
string="Payment Method"/>
<field name="amount"/>
<field name="reference" select="1" string="Payment Ref"/>
<field name="name" colspan="4" required="1"/>
<field name="name" colspan="4"/>
<field name="account_id"
domain="[('type','=','other')]"
widget="selection"
@@ -95,7 +95,8 @@
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="payment_ids" on_change="onchange_price(payment_ids, False, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<!-- <field name="payment_ids" on_change="onchange_price(payment_ids, 0.0, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">-->
<field name="payment_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<tree string="Payment Lines" editable="bottom">
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'type':parent.type, 'partner_id':parent.partner_id}" on_change="onchange_move_line_id(move_line_id)" domain="[('account_id.type','=','receivable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id), ('debit','>',0)]"/>
<field name="account_id" domain="[('type','=','receivable')]"/>
@@ -17,7 +17,7 @@
</group>
<notebook colspan="4">
<page string="Sales Information">
<field name="payment_ids" on_change="onchange_price(payment_ids, tax_amount, tax_id)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<field name="payment_ids" on_change="onchange_price(payment_ids, tax_id, parent.partner_id)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<tree string="Sales Lines" editable="bottom">
<field name="account_id" domain="[('user_type_type','=','income')]" widget="selection"/>
<field name="name"/>
@@ -43,7 +43,7 @@
</group>
<group col="3" colspan="1">
<separator string="Total" colspan="3"/>
<field name="tax_id" on_change="onchange_price(payment_ids, tax_amount, tax_id)" widget="selection" domain="[('type_tax_use','in',('sale','all'))]"/><field name="tax_amount" on_change="onchange_price(payment_ids, tax_amount, tax_id)" nolabel="1"/>
<field name="tax_id" on_change="onchange_price(payment_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all'))]"/><field name="tax_amount" on_change="onchange_price(payment_ids, tax_id, partner_id)" nolabel="1"/>
<label string="" colspan="1"/><field name="amount" string="Total"/>
</group>
</group>
+24 -51
View File
@@ -7,18 +7,11 @@
<field name="on_create">True</field>
</record>
<!-- <record id="act_draft" model="workflow.activity">-->
<!-- <field name="wkf_id" ref="wkf"/>-->
<!-- <field name="name">draft</field>-->
<!-- <field name="kind">function</field>-->
<!-- </record>-->
<!-- -->
<record id="act_proforma" model="workflow.activity">
<field name="wkf_id" ref="wkf"/>
<field name="flow_start">True</field>
<field name="name">proforma</field>
<field name="action">write({'state':'draft'})</field>
<!-- <field name="action">open_voucher()</field>-->
<field name="kind">function</field>
</record>
@@ -30,12 +23,12 @@
<field name="flow_stop">True</field>
</record>
<record id="act_recheck" model="workflow.activity">
<field name="wkf_id" ref="wkf"/>
<field name="name">recheck</field>
<field name="action">voucher_recheck()</field>
<field name="kind">function</field>
</record>
<!-- <record id="act_recheck" model="workflow.activity">-->
<!-- <field name="wkf_id" ref="wkf"/>-->
<!-- <field name="name">recheck</field>-->
<!-- <field name="action">voucher_recheck()</field>-->
<!-- <field name="kind">function</field>-->
<!-- </record>-->
<record id="act_cancel" model="workflow.activity">
<field name="wkf_id" ref="wkf"/>
@@ -44,52 +37,32 @@
<field name="action">cancel_voucher()</field>
<field name="kind">function</field>
</record>
<!-- <record id="act_audit" model="workflow.activity">-->
<!-- <field name="wkf_id" ref="wkf"/>-->
<!-- <field name="name">audit</field>-->
<!-- <field name="action">audit_pass()</field>-->
<!-- <field name="flow_stop">True</field>-->
<!-- <field name="kind">function</field>-->
<!-- </record>-->
<!-- <record id="t1" model="workflow.transition">-->
<!-- <field name="act_from" ref="act_draft"/>-->
<!-- <field name="act_to" ref="act_proforma"/>-->
<!-- <field name="signal">open_voucher</field>-->
<!-- </record>-->
<record id="t2" model="workflow.transition">
<field name="act_from" ref="act_proforma"/>
<field name="act_to" ref="act_done"/>
<field name="signal">proforma_voucher</field>
<field name="condition">amount &lt;= journal_id.max_amount</field>
<field name="condition">True</field>
</record>
<record id="t3" model="workflow.transition">
<field name="act_from" ref="act_proforma"/>
<field name="act_to" ref="act_recheck"/>
<field name="signal">proforma_voucher</field>
<field name="condition">amount &gt; journal_id.max_amount</field>
</record>
<record id="t4" model="workflow.transition">
<field name="act_from" ref="act_recheck"/>
<field name="act_to" ref="act_done"/>
<field name="signal">recheck_voucher</field>
</record>
<!-- <record id="t10" model="workflow.transition">-->
<!-- <field name="act_from" ref="act_done"/>-->
<!-- <field name="act_to" ref="act_audit"/>-->
<!-- <field name="signal">audit_complete</field>-->
<!-- <record id="t3" model="workflow.transition">-->
<!-- <field name="act_from" ref="act_proforma"/>-->
<!-- <field name="act_to" ref="act_recheck"/>-->
<!-- <field name="signal">proforma_voucher</field>-->
<!-- <field name="condition">amount &gt; journal_id.max_amount</field>-->
<!-- </record>-->
<!-- -->
<!-- <record id="t4" model="workflow.transition">-->
<!-- <field name="act_from" ref="act_recheck"/>-->
<!-- <field name="act_to" ref="act_done"/>-->
<!-- <field name="signal">recheck_voucher</field>-->
<!-- </record>-->
<!-- -->
<!-- <record id="t5" model="workflow.transition">-->
<!-- <field name="act_from" ref="act_recheck"/>-->
<!-- <field name="act_to" ref="act_cancel"/>-->
<!-- <field name="signal">cancel_voucher</field>-->
<!-- </record>-->
<record id="t5" model="workflow.transition">
<field name="act_from" ref="act_recheck"/>
<field name="act_to" ref="act_cancel"/>
<field name="signal">cancel_voucher</field>
</record>
<record id="t6" model="workflow.transition">
<field name="act_from" ref="act_proforma"/>