[FIX]: review all vouchers and fix some usablity problems

[IMP]: make working, vendor payment and vendor bills

bzr revid: mga@tinyerp.com-20100826190933-23ibu3s07lix6tpr
This commit is contained in:
Mantavya Gajjar 2010-08-27 00:39:33 +05:30
parent f92443f62b
commit ec9f8f6cd2
4 changed files with 103 additions and 36 deletions

View File

@ -222,8 +222,8 @@ class account_voucher(osv.osv):
'date_due':due_date
})
return {'value':default}
def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id=False, price=0.0, context={}):
def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id=False, price=0.0, ttype=False, context={}):
"""price
Returns a dict that contains new values and context
@ -273,8 +273,14 @@ class account_voucher(osv.osv):
})
if journal.type not in ('cash', 'bank'):
return default
ids = move_line_pool.search(cr, uid, [('account_id.type','in', ('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
account_type = 'receivable'
if ttype == 'payment':
account_type = 'payable'
else:
account_type = 'receivable'
ids = move_line_pool.search(cr, uid, [('account_id.type','=', account_type), ('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
moves = move_line_pool.browse(cr, uid, ids)
total_credit = price or 0.0
total_debit = 0.0
@ -308,7 +314,11 @@ class account_voucher(osv.osv):
default['value']['line_cr_ids'].append(rs)
else:
default['value']['line_dr_ids'].append(rs)
if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
default['value']['pre_line'] = 1
elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
default['value']['pre_line'] = 1
return default
@ -384,6 +394,14 @@ class account_voucher(osv.osv):
}
def action_move_line_create(self, cr, uid, ids, *args):
def _get_payment_term_lines(term_id, amount):
term_pool = self.pool.get('account.payment.term')
if term_id and amount:
terms = term_pool.compute(cr, uid, term_id, amount)
return terms
return False
move_pool = self.pool.get('account.move')
move_line_pool = self.pool.get('account.move.line')
analytic_pool = self.pool.get('account.analytic.line')
@ -412,7 +430,7 @@ class account_voucher(osv.osv):
}
move_id = move_pool.create(cr, uid, move)
company_currency = inv.account_id.company_id.currency_id.id
#create the first line manually
debit = 0.0
credit = 0.0
@ -421,20 +439,40 @@ class account_voucher(osv.osv):
credit = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
elif inv.type in ('sale', 'receipt'):
debit = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
move_line = {
'name':inv.name or '/',
'debit':debit,
'credit':credit,
'account_id':inv.account_id.id,
'move_id':move_id ,
'journal_id':inv.journal_id.id,
'period_id':inv.period_id.id,
'partner_id':inv.partner_id.id,
'currency_id':inv.currency_id.id,
'date':inv.date
}
master_line = move_line_pool.create(cr, uid, move_line)
if inv.type == 'purchase' and inv.term_id and _get_payment_term_lines(inv.term_id.id, credit or debit):
terms = _get_payment_term_lines(inv.term_id.id, credit or debit)
for term in terms:
due_date = term[0]
amount = term[1]
move_line = {
'name':inv.name or '/',
'debit':0.0,
'credit':amount,
'date_maturity':due_date,
'account_id':inv.account_id.id,
'move_id':move_id ,
'journal_id':inv.journal_id.id,
'period_id':inv.period_id.id,
'partner_id':inv.partner_id.id,
'currency_id':inv.currency_id.id,
'date':inv.date
}
master_line = move_line_pool.create(cr, uid, move_line)
else:
move_line = {
'name':inv.name or '/',
'debit':debit,
'credit':credit,
'account_id':inv.account_id.id,
'move_id':move_id ,
'journal_id':inv.journal_id.id,
'period_id':inv.period_id.id,
'partner_id':inv.partner_id.id,
'currency_id':inv.currency_id.id,
'date':inv.date
}
master_line = move_line_pool.create(cr, uid, move_line)
rec_list_ids = []
line_total = debit - credit
@ -581,7 +619,7 @@ class account_voucher_line(osv.osv):
return res
_columns = {
'voucher_id':fields.many2one('account.voucher', 'Voucher', required=1),
'voucher_id':fields.many2one('account.voucher', 'Voucher', required=1, ondelete='cascade'),
'name':fields.char('Description', size=256),
'account_id':fields.many2one('account.account','Account', required=True),
'partner_id':fields.related('voucher_id', 'partner_id', type='many2one', relation='res.partner', string='Partner'),
@ -650,7 +688,11 @@ class account_voucher_line(osv.osv):
elif journal.type in ('purchase', 'expense', 'sale_refund'):
account_id = journal.default_debit_account_id and journal.default_debit_account_id.id or False
elif partner_id:
account_id = partner_pool.browse(cr, user, partner_id, context=context).property_account_receivable.id
partner = partner_pool.browse(cr, user, partner_id, context=context)
if context.get('type') == 'payment':
account_id = partner.property_account_payable.id
elif context.get('type') == 'receipt':
account_id = partner.property_account_receivable.id
if (not account_id) and 'account_id' in fields_list:
raise osv.except_osv(_('Invalid Error !'), _('Please change partner and try again !'))

View File

@ -8,24 +8,50 @@
<field name="arch" type="xml">
<form string="Bill Payment">
<group col="6" colspan="4">
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, journal_id)"/>
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, type)" string="Customer"/>
<field name="journal_id"
domain="[('type','in',['bank', 'cash'])]"
widget="selection" select="1"
on_change="onchange_partner_id(partner_id, journal_id, amount)"
string="Payment Method"/>
<field name="amount"/>
<field name="reference" select="1" string="Payment Ref"/>
<field name="name" colspan="4"/>
<field name="journal_id" domain="[('type','in',['bank', 'cash'])]" widget="selection" select="1" on_change="onchange_journal(journal_id,type)"/>
<field name="account_id" domain="[('type','=','other')]" widget="selection" on_change="onchange_account(account_id)" readonly="1"/>
<field name="number"/>
<field name="account_id"
domain="[('type','=','other')]"
widget="selection"
on_change="onchange_account(account_id)"
invisible="True"/>
<field name="pre_line" invisible="1"/>
<field name="type" invisible="True"/>
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="line_ids" on_change="onchange_price(line_ids, False, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<field name="line_dr_ids" on_change="onchange_price(line_dr_ids, False, False)" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
<tree string="Payment Lines" editable="bottom">
<field name="amount"/>
<field name="account_id"/>
<field name="account_analytic_id"/>
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"
domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
/>
<field name="account_id" domain="[('type','=','payable')]"/>
<field name="date_original" readonly="1"/>
<field name="date_due" readonly="1"/>
<field name="amount_original" readonly="1"/>
<field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
<field name="amount" sum="Payment"/>
</tree>
</field>
<field name="line_cr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}">
<tree string="Credits" editable="bottom">
<field name="move_line_id"/>
<field name="account_id" domain="[('type','=','receivable')]"/>
<field name="date_original"/>
<field name="amount_original"/>
<field name="amount" sum="Payment"/>
</tree>
</field>
<group col="2" colspan="3">
<separator string="Narration" colspan="2"/>
<separator string="Internal Notes" colspan="2"/>
<field name="narration" colspan="2" nolabel="1"/>
</group>
<group col="2" colspan="1">
@ -33,7 +59,6 @@
<field name="reference" select="1"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" select="1" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/>
<field name="type" on_change="onchange_journal(journal_id,type)"/>
</group>
</page>
<page string="Journal Items">
@ -76,7 +101,7 @@
<field name="arch" type="xml">
<form string="Sales Payment">
<group col="6" colspan="4">
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount)" string="Customer"/>
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, type)" string="Customer"/>
<field name="journal_id"
domain="[('type','in',['bank', 'cash'])]"
widget="selection" select="1"
@ -95,7 +120,7 @@
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="line_cr_ids" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
<field name="line_cr_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="140">
<tree string="Invoices and outstanding transactions" editable="bottom">
<field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
on_change="onchange_move_line_id(move_line_id)"

View File

@ -90,7 +90,7 @@
<field name="arch" type="xml">
<form string="Vendor Bills">
<group col="6" colspan="4">
<field name="partner_id" string="Vendor" on_change="onchange_partner_id(partner_id, journal_id, amount)"/>
<field name="partner_id" required="1" string="Vendor" on_change="onchange_partner_id(partner_id, journal_id, amount)"/>
<field name="journal_id" domain="[('type','=','purchase')]" widget="selection" select="1" on_change="onchange_journal(journal_id)"/>
<field name="number"/>
<field name="name" colspan="4"/>

View File

@ -46,9 +46,9 @@ class account_voucher_unreconcile(osv.osv_memory):
recs = []
for line in voucher.move_ids:
if line.reconcile_id:
recs = [line.reconcile_id.id]
recs += [line.reconcile_id.id]
if line.reconcile_partial_id:
recs = [line.reconcile_partial_id.id]
recs += [line.reconcile_partial_id.id]
#for rec in recs:
reconcile_pool.unlink(cr, uid, recs)