[ADD] allow exchange rate setting settings in easy reconcile

This commit is contained in:
vrenaville
2014-11-27 10:48:21 +01:00
parent 4f6a872d2b
commit fe3cfe406c
3 changed files with 52 additions and 0 deletions

View File

@@ -215,10 +215,32 @@ class EasyReconcileBase(orm.AbstractModel):
if set(line_ids) == partial_line_ids:
return True, False
# We need to give a writeoff_acc_id
# in case we have a multi currency lines
# to reconcile.
# If amount in currency is equal between
# lines to reconcile
# it will do a full reconcile instead of a partial reconcile
# and make a write-off for exchange
if rec.account_id.currency_id:
if sum_credit > sum_debit:
writeoff_account_id = rec.income_exchange_account_id.id
else:
writeoff_account_id = rec.expense_exchange_account_id.id
period_id = self.pool.get('account.period').find(
cr, uid, dt=date, context=context)[0]
if rec.analytic_account_id:
rec_ctx['analytic_id'] = rec.analytic_account_id.id
else:
writeoff_account_id = False
period_id = False
ml_obj.reconcile_partial(
cr, uid,
line_ids,
type='manual',
writeoff_acc_id=writeoff_account_id,
writeoff_period_id=period_id,
writeoff_journal_id=rec.journal_id.id,
context=rec_ctx)
return True, False
return False, False

View File

@@ -47,6 +47,14 @@ class EasyReconcileOptions(orm.AbstractModel):
('newest_debit', 'Date of most recent debit')
]
def _get_account_currency(self, cr, uid, ids, field_name, arg,
context=None):
result = {}
for line in self.browse(cr, uid, ids, context=context):
# Always provide second currency
result[line.id] = bool(line.task_id.account.currency_id.id)
return result
_columns = {
'write_off': fields.float('Write off allowed'),
'account_lost_id': fields.many2one(
@@ -63,6 +71,16 @@ class EasyReconcileOptions(orm.AbstractModel):
'analytic_account_id': fields.many2one(
'account.analytic.account', 'Analytic Account',
help="Analytic account for the write-off"),
'account_has_currency': fields.function(
_get_account_currency,
type='boolean',
string='has currency',
help="Check if related account has currency."),
'income_exchange_account_id': fields.many2one(
'account.account', 'Gain Exchange Rate Account'),
'expense_exchange_account_id': fields.many2one(
'account.account', 'Loss Exchange Rate Account'),
}
_defaults = {
@@ -210,6 +228,12 @@ class AccountEasyReconcile(orm.Model):
rec_method.account_profit_id.id),
'analytic_account_id': (rec_method.analytic_account_id and
rec_method.analytic_account_id.id),
'income_exchange_account_id':
(rec_method.income_exchange_account_id and
rec_method.income_exchange_account_id.id),
'expense_exchange_account_id':
(rec_method.income_exchange_account_id and
rec_method.income_exchange_account_id.id),
'journal_id': (rec_method.journal_id and
rec_method.journal_id.id),
'date_base_on': rec_method.date_base_on,

View File

@@ -129,6 +129,9 @@ The lines should have the same amount (with the write-off) and the same referenc
<field name="write_off"/>
<field name="account_lost_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="account_profit_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="account_has_currency" invisible="1"/>
<field name="income_exchange_account_id" attrs="{'required':[('account_has_currency','=',True)],'invisible':[('account_has_currency','=',False)]}"/>
<field name="expense_exchange_account_id" attrs="{'required':[('account_has_currency','=',True)],'invisible':[('account_has_currency','=',False)]}"/>
<field name="journal_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="date_base_on"/>
@@ -147,6 +150,9 @@ The lines should have the same amount (with the write-off) and the same referenc
<field name="write_off"/>
<field name="account_lost_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="account_profit_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="account_has_currency" invisible="1"/>
<field name="income_exchange_account_id" attrs="{'required':[('account_has_currency','=',True)]}"/>
<field name="expense_exchange_account_id" attrs="{'required':[('account_has_currency','=',True)]}"/>
<field name="journal_id" attrs="{'required':[('write_off','>',0)]}"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="date_base_on"/>