[FIX/IMP]: fix and implement some new features and broken code for the voucher and specially for the sales receipt

bzr revid: mga@tinyerp.com-20100820114055-3xp0zrupg1ytx9df
This commit is contained in:
Mantavya Gajjar 2010-08-20 17:10:55 +05:30
parent ad7a4d4881
commit c1a9af0020
3 changed files with 128 additions and 58 deletions

View File

@ -40,6 +40,17 @@ class account_journal(osv.osv):
}
account_journal()
class account_account(osv.osv):
"""
account_account
"""
_inherit = 'account.account'
_columns = {
'user_type_type': fields.related('user_type','report_type', type='char', size=64, relation='account.account.type', string='User Type Code', readonly=True, store=True)
}
account_account()
class account_move(osv.osv):
_inherit = 'account.move'
@ -210,8 +221,9 @@ class account_voucher(osv.osv):
\n* The \'Pro-forma\' when voucher is in Pro-forma state,voucher does not have an voucher number. \
\n* The \'Posted\' state is used when user create voucher,a voucher number is generated and voucher entries are created in account \
\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),
'tax_amount':fields.float('Tax Amount', digits=(14,2), readonly=True, states={'draft':[('readonly',False)]}),
#'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)]}),
'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'),
@ -232,32 +244,40 @@ class account_voucher(osv.osv):
'currency_id': _get_currency,
'state': lambda *a: 'draft',
'pay_now':lambda *a: 'pay_later',
'name': lambda *a: '/',
'name': lambda *a: '',
'date' : lambda *a: time.strftime('%Y-%m-%d'),
'audit': lambda *a: False,
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
}
def onchange_tax_id(self, cr, uid, ids, amount, tax_id, context={}):
def onchange_price(self, cr, uid, ids, payment_ids, tax_amount, tax_id, context={}):
res = {
'tax_amount':False
'tax_amount':False,
'amount':False
}
tax_pool = self.pool.get('account.tax')
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':
res.update({
'tax_amount':amount * tax.amount
})
tax_amount = total * tax_amount and tax_amount or tax.amount
if tax.type == 'fixed':
res.update({
'tax_amount':amount + tax.amount
})
tax_amount = tax_amount and tax_amount or tax.amount
res.update({
'amount':total + tax_amount,
'tax_amount':tax_amount
})
return {
'value':res
}
def create(self, cr, uid, vals, context={}):
"""
Create a new record for a model account_voucher
@ -273,6 +293,7 @@ class account_voucher(osv.osv):
new_lines = []
payment_ids = vals.get('payment_ids')
if not payment_ids:
payment_ids = []
@ -292,6 +313,7 @@ class account_voucher(osv.osv):
vals.update({
'payment_ids':new_lines
})
res_id = super(account_voucher, self).create(cr, uid, vals, context)
if old_line:
@ -300,15 +322,16 @@ class account_voucher(osv.osv):
id1 = line[0]
id2 = line[1]
res = line[2]
res.update({
'voucher_id':res_id
})
new_payment_ids += [(id1, id2, res)]
if res:
res.update({
'voucher_id':res_id
})
new_payment_ids += [(id1, id2, res)]
self.write(cr, uid, [res_id], {'payment_ids':new_payment_ids})
return res_id
def onchange_partner_id(self, cr, uid, ids, partner_id, ttype, context={}):
def onchange_partner_id(self, cr, uid, ids, partner_id, ttype, journal_id=False, context={}):
"""
Returns a dict that contains new values and context
@ -322,7 +345,9 @@ class account_voucher(osv.osv):
"""
move_pool = self.pool.get('account.move')
line_pool = self.pool.get('account.voucher.line')
move_line_pool = self.pool.get('account.move.line')
partner_pool = self.pool.get('res.partner')
journal_pool = self.pool.get('account.journal')
res = []
context.update({
@ -330,6 +355,10 @@ class account_voucher(osv.osv):
'partner_id':partner_id,
'voucher':True,
})
if journal_id:
context.update({
'journal_id':journal_id,
})
default = {
'value':{},
@ -344,39 +373,46 @@ class account_voucher(osv.osv):
account_id = False
partner = partner_pool.browse(cr, uid, partner_id)
if ttype in ('sale', 'receipt'):
if ttype in ('sale'):
account_id = partner.property_account_receivable.id
elif ttype in ('purchase', 'payment'):
elif ttype in ('purchase'):
account_id = partner.property_account_payable.id
elif ttype in ('payment', 'receipt'):
journal = journal_pool.browse(cr, uid, journal_id)
if ttype == 'payment':
account_id = journal.default_credit_account_id.id
elif ttype == 'receipt':
account_id = journal.default_debit_account_id.id
default['value'].update({
'account_id':account_id
})
if ttype not in ('payment', 'receipt'):
return default
voucher_id = ids and ids[0] or False
ids = move_pool.search(cr, uid, [('reconcile_id','=', False), ('state','=','posted'), ('partner_id','=',partner_id)], context=context)
for move in move_pool.browse(cr, uid, ids):
rs = {
'ref':move.ref or '/',
'move_id':move.id,
ids = move_line_pool.search(cr, uid, [('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
for line in move_line_pool.browse(cr, uid, ids):
rs = move_line_pool.default_get(cr, uid, move_line_pool._columns.keys(), context=context)
rs.update({
'ref':line.ref or '/',
'move_id':line.move_id.id,
'move_line_id':line.id,
'voucher_id':voucher_id,
}
})
if ttype == 'payment':
rs.update({
'account_id':move.partner_id.property_account_payable.id,
'account_id':line.move_id.partner_id.property_account_payable.id,
'type':'dr',
'amount':move.amount
'amount':line.credit
})
elif ttype == 'receipt':
rs.update({
'account_id':move.partner_id.property_account_receivable.id,
'account_id':line.move_id.partner_id.property_account_receivable.id,
'type':'cr',
'amount':move.amount
'amount':line.debit
})
line_id = line_pool.create(cr, uid, rs)
line_id = line_pool.create(cr, uid, rs, context=context)
res += [line_id]
res = {'payment_ids':res, 'account_id':account_id}
@ -548,7 +584,7 @@ class account_voucher(osv.osv):
'name':inv.name,
'debit':False,
'credit':False,
'account_id':False,
'account_id':inv.account_id.id,
'move_id':move_id ,
'journal_id':inv.journal_id.id,
'period_id':inv.period_id.id,
@ -567,14 +603,12 @@ class account_voucher(osv.osv):
if inv.type == 'sale':
move_line.update({
'account_id':inv.account_id.id,
'debit':inv.amount
})
elif inv.type == 'purchase':
move_line.update({
'account_id':inv.account_id.id,
'credit':inv.amount
})
})
line_ids = []
line_ids += [move_line_pool.create(cr, uid, move_line)]
@ -724,7 +758,7 @@ class account_voucher(osv.osv):
#Restrict the list of journal view in search view
if view_type == 'search':
journal_list = journal_pool.name_search(cr, uid, '', [], context=context)
res['fields']['journal_id']['selection'] = journal_list
res['fields']['journal_id']['selection'] = journal_list
return res
@ -736,7 +770,8 @@ class account_voucher_line(osv.osv):
_columns = {
'voucher_id':fields.many2one('account.voucher', 'Voucher'),
'name':fields.related('voucher_id', 'name', size=256, type='char', string='Description'),
# 'name':fields.related('voucher_id', 'name', size=256, type='char', string='Description'),
'name':fields.char('Description', size=256, required=True),
'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'),
@ -756,4 +791,42 @@ class account_voucher_line(osv.osv):
'type': lambda *a: 'cr'
}
def default_get(self, cr, user, fields_list, context=None):
"""
Returns default values for fields
@param cr: A database cursor
@param user: ID of the user currently logged in
@param fields_list: list of fields, for which default values are required to be read
@param context: context arguments, like lang, time zone
@return: Returns a dict that contains default values for fields
"""
journal_pool = self.pool.get('account.journal')
partner_pool = self.pool.get('res.partner')
account_id = False
values = super(account_voucher_line, self).default_get(cr, user, fields_list, context=context)
journal_id = context.get('journal_id', False)
ttype = context.get('type', False)
partner_id = context.get('partner_id', False)
if ttype and journal_id and ttype in ('sale', 'purchase'):
journal = journal_pool.browse(cr, user, journal_id)
if ttype == 'sale' and journal:
account_id = journal.default_credit_account_id and journal.default_credit_account_id.id or False
elif ttype == 'purchase' and journal:
account_id = journal.default_credit_account_id and journal.default_debit_account_id.id or False
elif ttype and partner_id and ttype in ('payment', 'receipt'):
partner = partner_pool.browse(cr, user, partner_id)
if ttype == 'receipt' and partner:
account_id = partner.property_account_receivable and partner.property_account_receivable.id or False
elif ttype == 'payment' and partner:
account_id = partner.property_account_receivable and partner.property_account_payable.id or False
else:
account_id = False
values.update({
'account_id':account_id
})
return values
account_voucher_line()

View File

@ -8,7 +8,7 @@
<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)"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, journal_id)"/>
<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"/>
@ -16,8 +16,8 @@
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="payment_ids" colspan="4" nolabel="1" height="180">
<tree string="Payment Lines" editable="top">
<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="ref" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="amount"/>
<field name="account_id"/>
@ -77,28 +77,26 @@
<field name="arch" type="xml">
<form string="Sales Payment">
<group col="6" colspan="4">
<field name="partner_id" on_change="onchange_partner_id(partner_id, type)" string="Customer"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, journal_id)" string="Customer"/>
<field name="journal_id"
domain="[('type','in',['bank', 'cash'])]"
widget="selection" select="1"
on_change="onchange_journal(journal_id,type)"
string="Payment Method"/>
<field name="amount" readonly="0"/>
<field name="reference" select="1" string="Payment Ref"/>
<field name="name" colspan="4"/>
<field name="period_id" invisible="1"/>
<field name="account_id"
domain="[('type','=','other')]"
widget="selection"
on_change="onchange_account(account_id)"
invisible="1"/>
invisible="True"/>
</group>
<notebook colspan="4">
<page string="Payment Information">
<field name="payment_ids" colspan="4" nolabel="1" height="180">
<tree string="Payment Lines" editable="top">
<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"/>
<field name="account_id"/>
<field name="date_original"/>

View File

@ -8,19 +8,18 @@
<field name="arch" type="xml">
<form string="Sales Receipt">
<group col="6" colspan="4">
<field name="partner_id" on_change="onchange_partner_id(partner_id, type)" string="Customer"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, journal_id)" string="Customer"/>
<field name="journal_id" domain="[('type','=','sale')]" widget="selection" select="1" on_change="onchange_journal(journal_id,type)"/>
<field name="number"/>
<field name="name" colspan="4"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="type" on_change="onchange_journal(journal_id,type)" invisible="True"/> <!-- Type is given by menu, not by journal ? yes-->
<field name="period_id" invisible="True"/>
</group>
<notebook colspan="4">
<page string="Sales Information">
<field name="payment_ids" colspan="4" nolabel="1" height="180">
<tree string="Sales Lines" editable="top">
<field name="account_id" widget="selection"/>
<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">
<tree string="Sales Lines" editable="bottom">
<field name="account_id" domain="[('user_type_type','=','income')]" widget="selection"/>
<field name="name"/>
<field name="amount" sum="Total"/>
<field name="account_analytic_id" groups="base.group_extended"/>
@ -36,7 +35,7 @@
<field name="pay_now" on_change="onchange_payment(pay_now, journal_id, partner_id, type)" required="1"/>
<field name="account_id"
attrs="{'invisible':[('type','!=','view'),('pay_now','!=','pay_now')]}"
domain="[('type','in',['other'])]"/>
domain="[('user_type_type','=','asset'), ('type','!=','view')]"/>
<!-- should select income accounts only. Or use the journal for this ? -->
<field name="reference"
attrs="{'invisible':[('pay_now','!=','pay_now')]}"
@ -44,7 +43,7 @@
</group>
<group col="3" colspan="1">
<separator string="Total" colspan="3"/>
<field name="tax_id" widget="selection" domain="[('type_tax_use','=','sale')]" on_change="onchange_tax_id(amount, tax_id)"/><field name="tax_amount" nolabel="1"/>
<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"/>
<label string="" colspan="1"/><field name="amount" string="Total"/>
</group>
</group>
@ -91,7 +90,7 @@
<field name="arch" type="xml">
<form string="Vendor Bills">
<group col="6" colspan="4">
<field name="partner_id" on_change="onchange_partner_id(partner_id, type)"/>
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, journal_id)"/>
<field name="name" colspan="4"/>
<field name="journal_id" domain="[('type','=','purchase')]" 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)"/>
@ -99,12 +98,12 @@
</group>
<notebook colspan="4">
<page string="Bill Information">
<field name="payment_ids" colspan="4" nolabel="1" height="180">
<tree string="Voucher Lines" editable="top">
<field name="payment_ids" default_get="{'journal_id':journal_id, 'type':type, 'partner_id':partner_id}" colspan="4" nolabel="1" height="180">
<tree string="Voucher Lines" editable="bottom">
<field name="stype" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="ref" on_change="onchange_partner(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="amount"/>
<field name="account_id"/>
<field name="account_id" domain="[('user_type_type','=','expense'), ('type','!=','view')]"/>
<field name="type" on_change="onchange_type(parent.partner_id,type,parent.type, parent.currency_id)"/>
<field name="account_analytic_id"/>
</tree>