[ADD] account_voucher: implement writeoff on customer and vendor payment

bzr revid: psi@tinyerp.co.in-20101124065640-z04pv5m86nhrf9ar
This commit is contained in:
psi (Open ERP) 2010-11-24 12:26:40 +05:30
parent fad4dba6f4
commit 9b50d07a9b
2 changed files with 64 additions and 9 deletions

View File

@ -26,6 +26,7 @@ import netsvc
from osv import fields
from osv import osv
from tools.translate import _
import decimal_precision as dp
class account_move_line(osv.osv):
_inherit = 'account.move.line'
@ -190,6 +191,14 @@ class account_voucher(osv.osv):
'tax_id':fields.many2one('account.tax', 'Tax', readonly=True, states={'draft':[('readonly',False)]}),
'pre_line':fields.boolean('Previous Payments ?', required=False),
'date_due': fields.date('Due Date', readonly=True, states={'draft':[('readonly',False)]}),
'payment_option':fields.selection([
('not_reconcile', 'Without Write-off'),
('close_balance', 'With Write-off'),
], 'Payment Option', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'writeoff_acc_id': fields.many2one('account.account', 'Write-Off account', readonly=True, states={'draft': [('readonly', False)]}),
'writeoff_journal_id': fields.many2one('account.journal', 'Write-Off journal', readonly=True, states={'draft': [('readonly', False)]}),
'comment': fields.char('Comment', size=64, readonly=True, states={'draft': [('readonly', False)]}),
'analytic_id': fields.many2one('account.analytic.account','Analytic Account', readonly=True, states={'draft': [('readonly', False)]}),
}
_defaults = {
'period_id': _get_period,
@ -205,6 +214,8 @@ class account_voucher(osv.osv):
'date': lambda *a: time.strftime('%Y-%m-%d'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
'tax_id': _get_tax,
'payment_option': 'not_reconcile',
'comment': 'Write-Off',
}
def compute_tax(self, cr, uid, ids, context={}):
@ -694,6 +705,10 @@ class account_voucher(osv.osv):
if line.move_line_id.id:
rec_ids = [master_line, line.move_line_id.id]
rec_list_ids.append(rec_ids)
writeoff_account_id = False
writeoff_journal_id = False
writeoff_period_id = inv.period_id.id,
comment = False
if not currency_pool.is_zero(cr, uid, inv.currency_id, line_total):
diff = line_total
@ -717,6 +732,15 @@ class account_voucher(osv.osv):
move_line['account_id'] = account_id
move_line_pool.create(cr, uid, move_line)
for rec_ids in rec_list_ids:
if len(rec_ids) >= 2:
if inv.payment_option == 'close_balance':
writeoff_account_id = inv.writeoff_acc_id.id
writeoff_journal_id = inv.writeoff_journal_id.id
comment = inv.comment
self.pool.get('account.move.line').reconcile(cr, uid, rec_ids, 'manual', writeoff_account_id, writeoff_period_id, writeoff_journal_id, context)
else:
move_line_pool.reconcile_partial(cr, uid, rec_ids)
self.write(cr, uid, [inv.id], {
'move_id': move_id,
@ -724,9 +748,6 @@ class account_voucher(osv.osv):
'number': name,
})
move_pool.post(cr, uid, [move_id], context={})
for rec_ids in rec_list_ids:
if len(rec_ids) >= 2:
move_line_pool.reconcile_partial(cr, uid, rec_ids)
return True
def copy(self, cr, uid, id, default={}, context=None):

View File

@ -196,10 +196,27 @@
<field name="narration" colspan="2" nolabel="1"/>
</group>
<group col="2" colspan="1">
<group col="2" colspan="1">
<separator string="Payment Options" colspan="2"/>
<field name="payment_option" required="1"/>
<field name="writeoff_acc_id"
attrs="{'invisible':[('payment_option','!=','close_balance')], 'required':[('payment_option','=','close_balance')]}"
domain="[('type','=','liquidity')]"/>
<!-- should select income accounts only. Or use the journal for this ? -->
<field name="writeoff_journal_id"
attrs="{'invisible':[('payment_option','!=','close_balance')], 'required':[('payment_option','=','close_balance')]}"/>
<field name="comment"
attrs="{'invisible':[('payment_option','!=','close_balance')]}"/>
<field name="analytic_id"
attrs="{'invisible':[('payment_option','!=','close_balance')]}"
groups="analytic.group_analytic_accounting"/>
</group>
<separator string="Other Information" colspan="2"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
<group col="4" colspan="1">
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
</group>
</group>
</page>
<page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">
@ -304,10 +321,27 @@
<field name="narration" colspan="2" nolabel="1"/>
</group>
<group col="2" colspan="1">
<group col="2" colspan="1">
<separator string="Payment Options" colspan="2"/>
<field name="payment_option" required="1"/>
<field name="writeoff_acc_id"
attrs="{'invisible':[('payment_option','!=','close_balance')], 'required':[('payment_option','=','close_balance')]}"
domain="[('type','=','liquidity')]"/>
<!-- should select income accounts only. Or use the journal for this ? -->
<field name="writeoff_journal_id"
attrs="{'invisible':[('payment_option','!=','close_balance')], 'required':[('payment_option','=','close_balance')]}"/>
<field name="comment"
attrs="{'invisible':[('payment_option','!=','close_balance')]}"/>
<field name="analytic_id"
attrs="{'invisible':[('payment_option','!=','close_balance')]}"
groups="analytic.group_analytic_accounting"/>
</group>
<separator string="Other Information" colspan="2"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
<group col="4" colspan="1">
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
</group>
</group>
</page>
<page string="Journal Items" groups="base.group_extended" attrs="{'invisible': [('state','!=','posted')]}">