[FIX]: fix a problem for the multi currency voucher

[IMP]: now its possible to sale and purchase in journal currency
[FIX]: adopt voucher payment, receipy, sale and purchase fully  with the multi currency

bzr revid: mga@tinyerp.com-20100915143340-8f2nctpr0iiw5hxg
This commit is contained in:
Mantavya Gajjar 2010-09-15 20:03:40 +05:30
parent f5037005dd
commit 91b613d7a8
5 changed files with 68 additions and 35 deletions

View File

@ -46,11 +46,12 @@
"voucher_payment_receipt_view.xml",
"voucher_sales_purchase_view.xml",
"voucher_wizard.xml",
"security/account_voucher_security.xml"
],
"test" : [
# "test/account_voucher.yml",
"test/sales_receipt.yml",
"test/sales_payment.yml",
# "test/sales_receipt.yml",
# "test/sales_payment.yml",
],
'certificate': '0037580727101',
"active": False,

View File

@ -65,10 +65,15 @@ class account_voucher(osv.osv):
return res and res[0] or False
def _get_tax(self, cr, uid, context={}):
journal_pool = self.pool.get('account.journal')
journal_id = context.get('journal_id', False)
if not journal_id:
return False
journal_pool = self.pool.get('account.journal')
ttype = context.get('type', 'bank')
res = journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
if not res:
return False
journal_id = res[0]
journal = journal_pool.browse(cr, uid, journal_id)
account_id = journal.default_credit_account_id or journal.default_debit_account_id
if account_id and account_id.tax_ids:
@ -77,14 +82,30 @@ class account_voucher(osv.osv):
return False
def _get_currency(self, cr, uid, context):
user = self.pool.get('res.users').browse(cr, uid, uid)
if user.company_id:
return user.company_id.currency_id.id
return False
journal_pool = self.pool.get('account.journal')
journal_id = context.get('journal_id', False)
if not journal_id:
ttype = context.get('type', 'bank')
res = journal_pool.search(cr, uid, [('type', '=', ttype)], limit=1)
if not res:
return False
journal_id = res[0]
journal = journal_pool.browse(cr, uid, journal_id)
currency_id = journal.company_id.currency_id.id
if journal.currency:
currency_id = journal.currency.id
return
def _get_partner(self, cr, uid, context={}):
return context.get('partner_id', False)
def _get_reference(self, cr, uid, context={}):
return context.get('reference', False)
def _get_narration(self, cr, uid, context={}):
return context.get('narration', False)
_name = 'account.voucher'
_description = 'Accounting Voucher'
_order = "date desc, id desc"
@ -100,7 +121,6 @@ class account_voucher(osv.osv):
'date':fields.date('Date', readonly=True, states={'draft':[('readonly',False)]}, help="Effective date for accounting entries"),
'journal_id':fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'account_id':fields.many2one('account.account', 'Account', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'line_ids':fields.one2many('account.voucher.line','voucher_id','Voucher Lines', readonly=True, states={'draft':[('readonly',False)]}),
'line_cr_ids':fields.one2many('account.voucher.line','voucher_id','Credits',
domain=[('type','=','cr')], context={'default_type':'cr'}, readonly=True, states={'draft':[('readonly',False)]}),
@ -108,8 +128,9 @@ class account_voucher(osv.osv):
domain=[('type','=','dr')], context={'default_type':'dr'}, readonly=True, states={'draft':[('readonly',False)]}),
'period_id': fields.many2one('account.period', 'Period', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'narration':fields.text('Notes', readonly=True, states={'draft':[('readonly',False)]}),
'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'company_id': fields.many2one('res.company', 'Company', required=True),
'currency_id':fields.many2one('res.currency', 'Currency', readonly=True, states={'draft':[('readonly',False)]}),
# 'currency_id': fields.related('journal_id','currency', type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, states={'draft':[('readonly',False)]}),
'company_id': fields.many2one('res.company', 'Company', required=True, readonly=True, states={'draft':[('readonly',False)]}),
'state':fields.selection(
[('draft','Draft'),
('proforma','Pro-forma'),
@ -141,6 +162,8 @@ class account_voucher(osv.osv):
'partner_id': _get_partner,
'journal_id':_get_journal,
'currency_id': _get_currency,
'reference': _get_reference,
'narration':_get_narration,
'type':_get_type,
'state': lambda *a: 'draft',
'pay_now':lambda *a: 'pay_later',
@ -296,7 +319,7 @@ class account_voucher(osv.osv):
return default
def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, context):
def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, context={}):
"""price
Returns a dict that contains new values and context
@ -315,8 +338,12 @@ class account_voucher(osv.osv):
move_line_pool = self.pool.get('account.move.line')
partner_pool = self.pool.get('res.partner')
journal_pool = self.pool.get('account.journal')
vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context)
vals = vals.get('value')
currency_id = vals.get('currency_id', currency_id)
default = {
'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False},
'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id':currency_id},
}
if not partner_id:
@ -356,7 +383,7 @@ class account_voucher(osv.osv):
ids.reverse()
moves = move_line_pool.browse(cr, uid, ids)
company_currency = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
company_currency = journal.company_id.currency_id.id
if company_currency != currency_id and ttype == 'payment':
total_debit = currency_pool.compute(cr, uid, currency_id, company_currency, total_debit)
elif company_currency != currency_id and ttype == 'receipt':
@ -366,8 +393,7 @@ class account_voucher(osv.osv):
if line.credit and line.reconcile_partial_id and ttype == 'receipt':
continue
if line.debit and line.reconcile_partial_id and ttype == 'payment':
continue
continue
total_credit += line.credit or 0.0
total_debit += line.debit or 0.0
@ -377,15 +403,16 @@ class account_voucher(osv.osv):
if line.debit and line.reconcile_partial_id and ttype == 'payment':
continue
orignal_amount = line.credit or line.debit or 0.0
rs = {
'name':line.move_id.name,
'type': line.credit and 'dr' or 'cr',
'move_line_id':line.id,
'account_id':line.account_id.id,
'amount_original':line.credit or line.debit or 0.0,
'amount_original':currency_pool.compute(cr, uid, company_currency, currency_id, orignal_amount),
'date_original':line.date,
'date_due':line.date_maturity,
'amount_unreconciled': line.amount_unreconciled
'amount_unreconciled':currency_pool.compute(cr, uid, company_currency, currency_id, line.amount_unreconciled)
}
if line.credit:
amount = min(line.amount_unreconciled, total_debit)
@ -437,6 +464,10 @@ class account_voucher(osv.osv):
vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context)
vals['value'].update({'tax_id':tax_id})
currency_id = journal.company_id.currency_id.id
if journal.currency:
currency_id = journal.currency.id
vals['value'].update({'currency_id':currency_id})
return vals
def proforma_voucher(self, cr, uid, ids):
@ -537,12 +568,13 @@ class account_voucher(osv.osv):
'period_id': inv.period_id and inv.period_id.id or False
}
move_id = move_pool.create(cr, uid, move)
company_currency = inv.account_id.company_id.currency_id.id
#create the first line manually
company_currency = inv.journal_id.company_id.currency_id.id
debit = 0.0
credit = 0.0
# TODO: is there any other alternative then the voucher type ??
# TODO: is there any other alternative then the voucher type ??
# -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt
if inv.type in ('purchase', 'payment'):
credit = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
elif inv.type in ('sale', 'receipt'):
@ -564,6 +596,7 @@ class account_voucher(osv.osv):
'period_id':inv.period_id.id,
'partner_id':inv.partner_id.id,
'currency_id':inv.currency_id.id,
'amount_currency':inv.amount,
'date':inv.date,
'date_maturity':inv.date_due
}
@ -573,11 +606,10 @@ class account_voucher(osv.osv):
rec_list_ids = []
line_total = debit - credit
if inv.type == 'sale':
line_total = line_total - inv.tax_amount
line_total = line_total - currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.tax_amount)
elif inv.type == 'purchase':
line_total = line_total + inv.tax_amount
line_total = line_total + currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.tax_amount)
for line in inv.line_ids:
if not line.amount:
@ -621,7 +653,7 @@ 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)
if not self.pool.get('res.currency').is_zero(cr, uid, inv.currency_id, line_total):
diff = line_total
move_line = {
@ -646,7 +678,7 @@ class account_voucher(osv.osv):
'move_id': move_id,
'state':'posted'
})
#move_pool.post(cr, uid, [move_id], context={})
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)
@ -690,7 +722,7 @@ class account_voucher_line(osv.osv):
'account_id':fields.many2one('account.account','Account', required=True),
'partner_id':fields.related('voucher_id', 'partner_id', type='many2one', relation='res.partner', string='Partner'),
'untax_amount':fields.float('Untax Amount'),
'amount':fields.float('Amount'),
'amount':fields.float('Amount', digits=(14,2)),
'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Cr/Dr'),
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'move_line_id': fields.many2one('account.move.line', 'Journal Item'),

View File

@ -138,7 +138,7 @@
<group col="2" colspan="1">
<separator string="Other Information" colspan="2"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" select="1" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
</group>
</page>
@ -244,7 +244,7 @@
<group col="2" colspan="1">
<separator string="Other Information" colspan="2"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="currency_id" select="1"/>
<field name="currency_id" invisible="True"/>
<field name="number"/>
</group>
</page>

View File

@ -96,7 +96,7 @@
<field name="arch" type="xml">
<form string="Sales Receipt">
<group col="6" colspan="4">
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id)" string="Customer"/>
<field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type)" string="Customer"/>
<field name="journal_id" domain="[('type','in',['sale','sale_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id)"/>
<field name="number"/>
<field name="name" colspan="4"/>
@ -133,7 +133,7 @@
<group col="4" colspan="1">
<separator string="Total" colspan="4"/>
<field name="tax_id" on_change="onchange_price(line_cr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all'))]"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
<label colspan="1" string=""/><field name="amount" string="Total"/>
<label string="" colspan="1"/><field name="currency_id" invisible="True" nolabel="1"/><field name="amount" string="Total"/>
</group>
</group>
</page>
@ -152,7 +152,7 @@
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
<button name="cancel_voucher" string="Cancel" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to confirm this record ?"/>
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
<button icon="terp-dolar_ok!" name="%(act_pay_voucher)d" context="{'title':'Sales Payment', 'type':'receipt', 'partner_id': partner_id}" type="action" string="Pay" attrs="{'invisible':[('pay_now','!=','pay_now'),('state','!=','posted')]}"/>
<button icon="terp-dolar_ok!" name="%(act_pay_voucher)d" context="{'narration':narration, 'title':'Sales Payment', 'type':'receipt', 'partner_id': partner_id, 'reference':reference}" type="action" string="Pay" attrs="{'invisible':['|', ('pay_now','!=','pay_now'), ('state','!=','posted')]}"/>
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
</group>
</form>
@ -204,7 +204,7 @@
<field name="arch" type="xml">
<form string="Vendor Bills">
<group col="6" colspan="4">
<field name="partner_id" required="1" 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, currency_id, type)"/>
<field name="journal_id" domain="[('type','in',['purchase','purchase_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id)"/>
<field name="number"/>
<field name="name" colspan="4"/>
@ -235,7 +235,7 @@
<group col="4" colspan="1">
<separator string="Total" colspan="4"/>
<field name="tax_id" on_change="onchange_price(line_dr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('purchase','all'))]"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" string="Compute Tax" groups="base.group_extended" attrs="{'invisible': [('state','!=','draft')]}"/>
<label colspan="1" string=""/><field name="amount" string="Total"/>
<label string="" colspan="1"/><field name="currency_id" invisible="True" nolabel="1"/><field name="amount" string="Total"/>
</group>
</group>
</page>
@ -254,7 +254,7 @@
<button name="cancel_voucher" string="Cancel" states="draft,proforma" icon="gtk-cancel"/>
<button name="cancel_voucher" string="Cancel" type="object" states="posted" icon="terp-stock_effects-object-colorize" confirm="Are you sure to confirm this record ?"/>
<button name="proforma_voucher" string="Post" states="draft" icon="terp-camera_test"/>
<button icon="terp-dolar_ok!" name="%(act_pay_bills)d" context="{'title':'Bill Payment', 'type':'payment', 'partner_id': partner_id}" type="action" string="Pay Bill" attrs="{'invisible':[('state','!=','posted')]}"/>
<button icon="terp-dolar_ok!" name="%(act_pay_bills)d" context="{'narration':narration, 'title':'Bill Payment', 'type':'payment', 'partner_id': partner_id, 'reference':reference}" type="action" string="Pay Bill" attrs="{'invisible':['|', ('pay_now','!=','pay_now'), ('state','!=','posted')]}"/>
<button name="action_cancel_draft" type="object" states="cancel" string="Set to Draft" icon="terp-stock_effects-object-colorize"/>
</group>
</form>

View File

@ -55,7 +55,7 @@
<separator string="Other Information" colspan="2"/>
<field name="number"/>
<field name="date" on_change="onchange_date(date)"/>
<field name="currency_id" attrs="{'readonly':[('type','in',['sale', 'purchase'])]}"/>
<field name="currency_id" invisible="True"/>
</group>
<group col="4" colspan="1" attrs="{'invisible':[('type','in',['payment', 'receipt', False])]}">
<separator string="Total" colspan="4"/>