[IMP] account_voucher: multi currency improvements (part 4)
bzr revid: qdp-launchpad@openerp.com-20110715124738-q64m7ev5yk0denge
This commit is contained in:
@@ -182,13 +182,13 @@ class account_voucher(osv.osv):
|
||||
ctx.update({'date': voucher.date})
|
||||
for l in voucher.line_dr_ids:
|
||||
real_amount -= l.amount_in_company_currency
|
||||
counter_for_writeoff -= l.amount_in_voucher_currency
|
||||
counter_for_writeoff -= (l.voucher_currency_id.id == l.company_currency_id.id) and l.amount_in_company_currency or l.amount_in_voucher_currency
|
||||
#ctx.update({'date': l.date_original})
|
||||
#counter_for_writeoff -= currency_pool.compute(cr, uid, voucher.company_id.currency_id.id, voucher.currency_id.id, l.amount_in_company_currency, context=ctx)
|
||||
counter_for_currency_diff -= currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
|
||||
for l in voucher.line_cr_ids:
|
||||
real_amount += l.amount_in_company_currency
|
||||
counter_for_writeoff += l.amount_in_voucher_currency
|
||||
counter_for_writeoff += (l.voucher_currency_id.id == l.company_currency_id.id) and l.amount_in_company_currency or l.amount_in_voucher_currency
|
||||
#ctx.update({'date': l.date_original})
|
||||
#counter_for_writeoff += currency_pool.compute(cr, uid, voucher.company_id.currency_id.id, voucher.currency_id.id, l.amount_in_company_currency, context=ctx)
|
||||
counter_for_currency_diff += currency_pool.compute(cr, uid, l.currency_id.id, voucher.company_id.currency_id.id, l.amount, context=ctx)
|
||||
@@ -216,7 +216,7 @@ class account_voucher(osv.osv):
|
||||
],'Default Type', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'name':fields.char('Memo', size=256, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'date':fields.date('Date', readonly=True, select=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)]}),
|
||||
'journal_id':fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}, change_default=1),
|
||||
'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',
|
||||
@@ -229,6 +229,7 @@ class account_voucher(osv.osv):
|
||||
#duplicated field for display purposes
|
||||
'currency_id2': fields.function(_currency_id, type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, multi="currency"),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'company_currency': fields.related('company_id','currency_id', type='many2one', relation='res.currency', string='Currency', readonly=True),
|
||||
'state':fields.selection(
|
||||
[('draft','Draft'),
|
||||
('proforma','Pro-forma'),
|
||||
@@ -256,7 +257,7 @@ class account_voucher(osv.osv):
|
||||
'date_due': fields.date('Due Date', readonly=True, select=True, states={'draft':[('readonly',False)]}),
|
||||
'payment_option':fields.selection([
|
||||
('without_writeoff', 'Keep Open'),
|
||||
('with_writeoff', 'Reconcile with Write-Off'),
|
||||
('with_writeoff', 'Reconcile'),
|
||||
], 'Payment Difference', required=True, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'writeoff_acc_id': fields.many2one('account.account', 'Write-Off account', readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'comment': fields.char('Write-Off Comment', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
@@ -440,38 +441,33 @@ class account_voucher(osv.osv):
|
||||
|
||||
@return: Returns a dict which contains new values, and context
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if not journal_id:
|
||||
return {}
|
||||
if context is None:
|
||||
context = {}
|
||||
context_multi_currency = context.copy()
|
||||
if date:
|
||||
context_multi_currency.update({'date': date})
|
||||
|
||||
line_pool = self.pool.get('account.voucher.line')
|
||||
line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
|
||||
if line_ids:
|
||||
line_pool.unlink(cr, uid, line_ids)
|
||||
|
||||
currency_pool = self.pool.get('res.currency')
|
||||
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')
|
||||
line_pool = self.pool.get('account.voucher.line')
|
||||
#get default values
|
||||
vals = self.onchange_journal(cr, uid, ids, journal_id, [], False, partner_id, context=context)
|
||||
vals = vals.get('value',{})
|
||||
voucher_currency_id = vals.get('currency_id', voucher_currency_id)
|
||||
default = {
|
||||
'value':{'line_ids':[], 'line_dr_ids':[], 'line_cr_ids':[], 'pre_line': False, 'currency_id': voucher_currency_id},
|
||||
}
|
||||
|
||||
if not partner_id:
|
||||
return default
|
||||
#drop existing lines
|
||||
line_ids = ids and line_pool.search(cr, uid, [('voucher_id', 'in', ids)]) or []
|
||||
if line_ids:
|
||||
line_pool.unlink(cr, uid, line_ids, context=context)
|
||||
|
||||
if not partner_id and ids:
|
||||
line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])])
|
||||
if line_ids:
|
||||
line_pool.unlink(cr, uid, line_ids)
|
||||
if not partner_id:
|
||||
return default
|
||||
|
||||
journal = journal_pool.browse(cr, uid, journal_id, context=context)
|
||||
@@ -583,7 +579,7 @@ class account_voucher(osv.osv):
|
||||
|
||||
def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context=None):
|
||||
if not journal_id:
|
||||
return False
|
||||
return {}
|
||||
journal_pool = self.pool.get('account.journal')
|
||||
journal = journal_pool.browse(cr, uid, journal_id, context=context)
|
||||
account_id = journal.default_credit_account_id or journal.default_debit_account_id
|
||||
@@ -640,7 +636,6 @@ class account_voucher(osv.osv):
|
||||
raise osv.except_osv(_('Invalid action !'), _('Cannot delete Voucher(s) which are already opened or paid !'))
|
||||
return super(account_voucher, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
# TODO: may be we can remove this method if not used anyware
|
||||
def onchange_payment(self, cr, uid, ids, pay_now, journal_id, partner_id, ttype='sale'):
|
||||
res = {}
|
||||
if not partner_id:
|
||||
@@ -705,8 +700,6 @@ class account_voucher(osv.osv):
|
||||
voucher_currency = voucher.currency_id.id
|
||||
debit = 0.0
|
||||
credit = 0.0
|
||||
# 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 voucher.type in ('purchase', 'payment'):
|
||||
credit = currency_pool.compute(cr, uid, voucher_currency, company_currency, voucher.amount, context=context_multi_currency)
|
||||
elif voucher.type in ('sale', 'receipt'):
|
||||
@@ -738,11 +731,11 @@ class account_voucher(osv.osv):
|
||||
#create the move line for the currency difference
|
||||
if voucher.currency_rate_difference:
|
||||
if voucher.currency_rate_difference > 0:
|
||||
account_id = voucher.company_id.property_income_currency_exchange
|
||||
account_id = voucher.company_id.property_expense_currency_exchange
|
||||
if not account_id:
|
||||
raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Income Currency Rate' on the company! "))
|
||||
else:
|
||||
account_id = voucher.company_id.property_expense_currency_exchange
|
||||
account_id = voucher.company_id.property_income_currency_exchange
|
||||
if not account_id:
|
||||
raise osv.except_osv(_('Warning'),_("Unable to create accounting entry for currency rate difference. You have to configure the field 'Expense Currency Rate' on the company! "))
|
||||
|
||||
@@ -758,10 +751,9 @@ class account_voucher(osv.osv):
|
||||
'date': voucher.date,
|
||||
'date_maturity': voucher.date_due
|
||||
}
|
||||
|
||||
move_line_pool.create(cr, uid, currency_diff_line, context=context)
|
||||
rec_list_ids = []
|
||||
|
||||
rec_list_ids = []
|
||||
for line in voucher.line_ids:
|
||||
#create one move line per voucher line where amount is not 0.0
|
||||
if not line.amount:
|
||||
@@ -770,9 +762,6 @@ class account_voucher(osv.osv):
|
||||
if line.amount == line.amount_unreconciled:
|
||||
amount = line.move_line_id.amount_residual #residual amount in company currency
|
||||
else:
|
||||
#ctx = context_multi_currency.copy()
|
||||
#ctx.update({'date': line.date_original})
|
||||
#amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=ctx)
|
||||
amount = line.amount_in_company_currency
|
||||
move_line = {
|
||||
'journal_id': voucher.journal_id.id,
|
||||
@@ -815,6 +804,7 @@ class account_voucher(osv.osv):
|
||||
rec_list_ids.append(rec_ids)
|
||||
|
||||
if not currency_pool.is_zero(cr, uid, voucher.currency_id, voucher.writeoff_amount):
|
||||
#create one line for the write off if needed
|
||||
diff = currency_pool.compute(cr, uid, voucher_currency, company_currency, voucher.writeoff_amount, context=context_multi_currency)
|
||||
account_id = False
|
||||
write_off_name = ''
|
||||
@@ -831,9 +821,9 @@ class account_voucher(osv.osv):
|
||||
'move_id': move_id,
|
||||
'partner_id': voucher.partner_id.id,
|
||||
'date': voucher.date,
|
||||
'credit': diff > 0 and diff or 0.0,
|
||||
'debit': diff < 0 and -diff or 0.0,
|
||||
'amount_currency': company_currency <> voucher_currency and voucher.writeoff_amount or 0.0,
|
||||
'credit': diff > 0 and diff or 0.0,
|
||||
'amount_currency': company_currency <> voucher_currency and -voucher.writeoff_amount or 0.0,
|
||||
'currency_id': company_currency <> voucher_currency and voucher_currency or False,
|
||||
}
|
||||
move_line_pool.create(cr, uid, move_line)
|
||||
|
||||
@@ -301,7 +301,7 @@
|
||||
invisible="context.get('line_type', False)"
|
||||
string="Paid Amount"
|
||||
on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="currency_id" nolabel="1"/>
|
||||
<field name="currency_id" nolabel="1" invisible="1"/>
|
||||
<field name="date" colspan="4" select="1" invisible="context.get('line_type', False)" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
|
||||
<field name="reference" colspan="4" select="1" invisible="context.get('line_type', False)" string="Payment Ref"/>
|
||||
<field name="name" colspan="4" invisible="context.get('line_type', False)"/>
|
||||
@@ -320,32 +320,36 @@
|
||||
on_change="onchange_move_line_id(move_line_id)"
|
||||
domain="[('account_id.type','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
|
||||
/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]" invisible="1"/>
|
||||
<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" on_change="onchange_amount(amount)"/>
|
||||
<field name="currency_id" readonly="1"/>
|
||||
<field name="amount_in_voucher_currency" readonly="1"/>
|
||||
<field name="voucher_currency_id" readonly="1"/>
|
||||
<field name="amount_in_company_currency" readonly="1"/>
|
||||
<field name="company_currency_id" readonly="1"/>
|
||||
<field name="amount_original" readonly="1" invisible="1"/>
|
||||
<field name="amount_unreconciled" readonly="1"/>
|
||||
<field name="amount" on_change="onchange_amount(amount)"/>
|
||||
<field name="amount_in_voucher_currency" readonly="1" groups="base.group_no_one"/>
|
||||
<field name="voucher_currency_id" readonly="1" groups="base.group_no_one"/>
|
||||
<field name="amount_in_company_currency" readonly="1" invisible="1"/>
|
||||
<field name="company_currency_id" readonly="1" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="line_dr_ids" colspan="4" nolabel="1" attrs="{'invisible': [('pre_line','=',False)]}" default_get="{'journal_id':journal_id, 'partner_id':partner_id}" on_change="onchange_line_ids(line_dr_ids, line_cr_ids, amount, date)">
|
||||
<tree string="Credits" editable="bottom">
|
||||
<field name="move_line_id"/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]"/>
|
||||
<field name="date_original"/>
|
||||
<field name="amount_original"/>
|
||||
<field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
|
||||
<field name="amount" sum="Payment" on_change="onchange_amount(amount)"/>
|
||||
<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','in',('receivable','payable')), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
|
||||
/>
|
||||
<field name="account_id" groups="base.group_extended" domain="[('type','=','receivable')]" invisible="1"/>
|
||||
<field name="date_original" readonly="1"/>
|
||||
<field name="date_due" readonly="1"/>
|
||||
<field name="currency_id" readonly="1"/>
|
||||
<field name="amount_in_voucher_currency" readonly="1"/>
|
||||
<field name="voucher_currency_id" readonly="1"/>
|
||||
<field name="amount_in_company_currency" readonly="1"/>
|
||||
<field name="company_currency_id" readonly="1"/>
|
||||
<field name="amount_original" readonly="1" invisible="1"/>
|
||||
<field name="amount_unreconciled" readonly="1"/>
|
||||
<field name="amount" on_change="onchange_amount(amount)"/>
|
||||
<field name="amount_in_voucher_currency" readonly="1" groups="base.group_no_one"/>
|
||||
<field name="voucher_currency_id" readonly="1" groups="base.group_no_one"/>
|
||||
<field name="amount_in_company_currency" readonly="1" invisible="1"/>
|
||||
<field name="company_currency_id" readonly="1" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<group col="2" colspan="3">
|
||||
@@ -356,9 +360,11 @@
|
||||
<group col="4" colspan="1">
|
||||
<separator string="Payment Options" colspan="4"/>
|
||||
<field name="payment_option" required="1" colspan="4"/>
|
||||
<field name="currency_rate_difference" attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
<field name="company_currency" attrs="{'invisible':[('payment_option','!=','with_writeoff')]}" nolabel="1"/><newline/>
|
||||
<field name="writeoff_amount"
|
||||
attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
<field name="currency_id2" nolabel="1" attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/>
|
||||
<field name="currency_id2" nolabel="1" attrs="{'invisible':[('payment_option','!=','with_writeoff')]}"/><newline/>
|
||||
<field name="writeoff_acc_id"
|
||||
attrs="{'invisible':[('payment_option','!=','with_writeoff')], 'required':[('payment_option','=','with_writeoff')]}"
|
||||
domain="[('type','=','other')]" colspan="4"/>
|
||||
@@ -371,7 +377,6 @@
|
||||
<separator string="Other Information" colspan="2"/>
|
||||
<group col="4" colspan="1">
|
||||
<field name="number"/>
|
||||
<field name="currency_rate_difference"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
||||
Reference in New Issue
Block a user