Merged for financial improvements
bzr revid: hda@tinyerp.com-20091106075143-5y1tyxj41h5f9t1g
This commit is contained in:
@@ -170,7 +170,9 @@ class account_bank_statement(osv.osv):
|
||||
if line.state <> 'valid':
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('The account entries lines are not in valid state.'))
|
||||
|
||||
# for bank.statement.lines
|
||||
# In line we get reconcile_id on bank.ste.rec.
|
||||
# in bank stat.rec we get line_new_ids on bank.stat.rec.line
|
||||
for move in st.line_ids:
|
||||
move_id = account_move_obj.create(cr, uid, {
|
||||
'journal_id': st.journal_id.id,
|
||||
@@ -209,7 +211,7 @@ class account_bank_statement(osv.osv):
|
||||
'period_id': st.period_id.id,
|
||||
'currency_id': st.currency.id,
|
||||
}
|
||||
|
||||
|
||||
amount = res_currency_obj.compute(cr, uid, st.currency.id,
|
||||
company_currency_id, move.amount, context=context,
|
||||
account=acc_cur)
|
||||
@@ -245,6 +247,7 @@ class account_bank_statement(osv.osv):
|
||||
'statement_id': st.id,
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': st.period_id.id,
|
||||
|
||||
}, context=context)
|
||||
|
||||
# Fill the secondary amount/currency
|
||||
@@ -491,11 +494,14 @@ class account_bank_statement_reconcile_line(osv.osv):
|
||||
_name = "account.bank.statement.reconcile.line"
|
||||
_description = "Statement reconcile line"
|
||||
_columns = {
|
||||
'name': fields.char('Description', size=64),
|
||||
'name': fields.char('Description', size=64, required=True),
|
||||
'account_id': fields.many2one('account.account', 'Account', required=True),
|
||||
'line_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile'),
|
||||
'amount': fields.float('Amount', required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'name': lambda *a: 'Write-Off',
|
||||
}
|
||||
account_bank_statement_reconcile_line()
|
||||
|
||||
|
||||
|
||||
@@ -616,6 +616,7 @@ class account_move_line(osv.osv):
|
||||
'debit':debit,
|
||||
'credit':credit,
|
||||
'account_id':writeoff_acc_id,
|
||||
'analytic_account_id': context.get('analytic_id', False),
|
||||
'date':date,
|
||||
'partner_id':partner_id
|
||||
})
|
||||
@@ -624,7 +625,7 @@ class account_move_line(osv.osv):
|
||||
writeoff_move_id = self.pool.get('account.move').create(cr, uid, {
|
||||
'period_id': writeoff_period_id,
|
||||
'journal_id': writeoff_journal_id,
|
||||
|
||||
'date':date,
|
||||
'state': 'draft',
|
||||
'line_id': writeoff_lines
|
||||
})
|
||||
@@ -869,7 +870,7 @@ class account_move_line(osv.osv):
|
||||
'amount': vals['debit'] or vals['credit'],
|
||||
'general_account_id': vals['account_id'],
|
||||
'journal_id': journal.analytic_journal_id.id,
|
||||
'ref': vals['ref'],
|
||||
'ref': vals.get('ref', False),
|
||||
})]
|
||||
#else:
|
||||
# raise osv.except_osv(_('No analytic journal !'), _('Please set an analytic journal on this financial journal !'))
|
||||
|
||||
@@ -335,6 +335,7 @@
|
||||
<field name="date"/>
|
||||
<field name="ref"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id"/>
|
||||
<field name="type"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, parent.currency)"/>
|
||||
<field domain="[('journal_id','=',parent.journal_id)]" name="account_id"/>
|
||||
@@ -345,6 +346,7 @@
|
||||
<form string="Statement lines">
|
||||
<field name="date"/>
|
||||
<field name="name"/>
|
||||
<field name="account_id"/>
|
||||
<field name="type"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id, type, parent.currency)"/>
|
||||
<field domain="[('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]" name="account_id"/>
|
||||
|
||||
+43
-11
@@ -106,23 +106,41 @@ class account_invoice(osv.osv):
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
for inv in data_inv:
|
||||
debit = credit = 0.0
|
||||
context.update({'date':inv.date_invoice})
|
||||
context_unreconciled=context.copy()
|
||||
for lines in inv.move_lines:
|
||||
if lines.account_id.company_currency_id.id <> inv.currency_id.id:
|
||||
if lines.debit:
|
||||
debit += cur_obj.compute(cr, uid, lines.account_id.company_currency_id.id, inv.currency_id.id, lines.debit)
|
||||
if lines.credit:
|
||||
credit += cur_obj.compute(cr, uid, lines.account_id.company_currency_id.id, inv.currency_id.id, lines.credit)
|
||||
debit_tmp = lines.debit
|
||||
credit_tmp = lines.credit
|
||||
# If currency conversion needed
|
||||
if inv.company_id.currency_id.id <> inv.currency_id.id:
|
||||
# If invoice paid, compute currency amount according to invoice date
|
||||
# otherwise, take the line date
|
||||
if not inv.reconciled:
|
||||
context.update({'date':lines.date})
|
||||
context_unreconciled.update({'date':lines.date})
|
||||
# If amount currency setted, compute for debit and credit in company currency
|
||||
if lines.amount_currency < 0:
|
||||
credit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled))
|
||||
elif lines.amount_currency > 0:
|
||||
debit_tmp=abs(cur_obj.compute(cr, uid, lines.currency_id.id, inv.company_id.currency_id.id, lines.amount_currency, round=False,context=context_unreconciled))
|
||||
# Then, recomput into invoice currency to avoid rounding trouble !
|
||||
debit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, debit_tmp, round=False,context=context)
|
||||
credit += cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id, credit_tmp, round=False,context=context)
|
||||
else:
|
||||
debit += lines.debit
|
||||
credit += lines.credit
|
||||
|
||||
debit+=debit_tmp
|
||||
credit+=credit_tmp
|
||||
|
||||
if not inv.amount_total:
|
||||
result = 0.0
|
||||
elif inv.type in ('out_invoice','in_refund'):
|
||||
result = inv.amount_total * (1.0 - credit / (debit + inv.amount_total))
|
||||
amount = credit-debit
|
||||
result = inv.amount_total - amount
|
||||
else:
|
||||
result = inv.amount_total * (1.0 - debit / (credit + inv.amount_total))
|
||||
res[inv.id] = round(result,int(config['price_accuracy']))
|
||||
amount = debit-credit
|
||||
result = inv.amount_total - amount
|
||||
# Use is_zero function to avoid rounding trouble => should be fixed into ORM
|
||||
res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id,result) and result or 0.0
|
||||
|
||||
return res
|
||||
|
||||
def _get_lines(self, cr, uid, ids, name, arg, context=None):
|
||||
@@ -872,6 +890,16 @@ class account_invoice(osv.osv):
|
||||
date=context['date_p']
|
||||
else:
|
||||
date=time.strftime('%Y-%m-%d')
|
||||
|
||||
# Take the amount in currency and the currency of the payment
|
||||
if 'amount_currency' in context and context['amount_currency'] and 'currency_id' in context and context['currency_id']:
|
||||
amount_currency = context['amount_currency']
|
||||
currency_id = context['currency_id']
|
||||
else:
|
||||
amount_currency = False
|
||||
currency_id = False
|
||||
|
||||
# Pay attention to the sign for both debit/credit AND amount_currency
|
||||
l1 = {
|
||||
'debit': direction * pay_amount>0 and direction * pay_amount,
|
||||
'credit': direction * pay_amount<0 and - direction * pay_amount,
|
||||
@@ -879,6 +907,8 @@ class account_invoice(osv.osv):
|
||||
'partner_id': invoice.partner_id.id,
|
||||
'ref':invoice.number,
|
||||
'date': date,
|
||||
'currency_id':currency_id,
|
||||
'amount_currency':amount_currency and direction * amount_currency or 0.0,
|
||||
}
|
||||
l2 = {
|
||||
'debit': direction * pay_amount<0 and - direction * pay_amount,
|
||||
@@ -887,6 +917,8 @@ class account_invoice(osv.osv):
|
||||
'partner_id': invoice.partner_id.id,
|
||||
'ref':invoice.number,
|
||||
'date': date,
|
||||
'currency_id':currency_id,
|
||||
'amount_currency':amount_currency and - direction * amount_currency or 0.0,
|
||||
}
|
||||
|
||||
if not name:
|
||||
|
||||
@@ -25,6 +25,7 @@ import netsvc
|
||||
import pooler
|
||||
import time
|
||||
from tools.translate import _
|
||||
import tools
|
||||
|
||||
pay_form = '''<?xml version="1.0"?>
|
||||
<form string="Pay invoice">
|
||||
@@ -37,7 +38,7 @@ pay_form = '''<?xml version="1.0"?>
|
||||
</form>'''
|
||||
|
||||
pay_fields = {
|
||||
'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
|
||||
'amount': {'string': 'Amount paid', 'type':'float', 'required':True, 'digits': (16,int(tools.config['price_accuracy']))},
|
||||
'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
|
||||
'date': {'string': 'Payment date', 'type':'date', 'required':True, 'default':lambda *args: time.strftime('%Y-%m-%d')},
|
||||
'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
|
||||
@@ -53,18 +54,24 @@ def _pay_and_reconcile(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
cur_obj = pool.get('res.currency')
|
||||
amount = form['amount']
|
||||
context['analytic_id'] = form.get('analytic_id', False)
|
||||
|
||||
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
|
||||
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
|
||||
# Compute the amount in company's currency, with the journal currency (which is equal to payment currency)
|
||||
# when it is needed : If payment currency (according to selected journal.currency) is <> from company currency
|
||||
if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
|
||||
ctx = {'date':data['form']['date']}
|
||||
amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx)
|
||||
|
||||
currency_id = journal.currency.id
|
||||
# Put the paid amount in currency, and the currency, in the context if currency is different from company's currency
|
||||
context.update({'amount_currency':form['amount'],'currency_id':currency_id})
|
||||
|
||||
# Take the choosen date
|
||||
if form.has_key('comment'):
|
||||
context={'date_p':form['date'],'comment':form['comment']}
|
||||
context.update({'date_p':form['date'],'comment':form['comment']})
|
||||
else:
|
||||
context={'date_p':form['date'],'comment':False}
|
||||
context.update({'date_p':form['date'],'comment':False})
|
||||
|
||||
acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id
|
||||
if not acc_id:
|
||||
@@ -78,31 +85,53 @@ def _wo_check(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
invoice = pool.get('account.invoice').browse(cr, uid, data['id'], context)
|
||||
journal = pool.get('account.journal').browse(cr, uid, data['form']['journal_id'], context)
|
||||
if invoice.company_id.currency_id.id <> invoice.currency_id.id:
|
||||
return 'addendum'
|
||||
if journal.currency and (journal.currency.id <> invoice.currency_id.id):
|
||||
return 'addendum'
|
||||
if pool.get('res.currency').is_zero(cr, uid, invoice.currency_id,
|
||||
(data['form']['amount'] - invoice.amount_total)):
|
||||
cur_obj = pool.get('res.currency')
|
||||
# Here we need that:
|
||||
# The invoice total amount in company's currency <> paid amount in company currency
|
||||
# (according to the correct day rate, invoicing rate and payment rate are may be different)
|
||||
# => Ask to a write-off of the difference. This could happen even if both amount are equal,
|
||||
# because if the currency rate
|
||||
# Get the amount in company currency for the invoice (according to move lines)
|
||||
inv_amount_company_currency=invoice.move_id.amount
|
||||
# Get the current amount paid in company currency
|
||||
if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id:
|
||||
ctx = {'date':data['form']['date']}
|
||||
amount_paid = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, data['form']['amount'], round=True, context=ctx)
|
||||
else:
|
||||
amount_paid = data['form']['amount']
|
||||
# Get the old payment if there are some
|
||||
if invoice.payment_ids:
|
||||
debit=credit=0.0
|
||||
for payment in invoice.payment_ids:
|
||||
debit+=payment.debit
|
||||
credit+=payment.credit
|
||||
amount_paid+=abs(debit-credit)
|
||||
|
||||
# Test if there is a difference according to currency rouding setting
|
||||
if pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id,
|
||||
(amount_paid - inv_amount_company_currency)):
|
||||
return 'reconcile'
|
||||
return 'addendum'
|
||||
|
||||
_transaction_add_form = '''<?xml version="1.0"?>
|
||||
<form string="Information addendum">
|
||||
<separator string="Write-Off Move" colspan="4"/>
|
||||
<field name="writeoff_acc_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
|
||||
<field name="writeoff_journal_id"/>
|
||||
<field name="writeoff_acc_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/>
|
||||
<field name="comment"/>
|
||||
<separator string="Analytic" colspan="4"/>
|
||||
<field name="analytic_id"/>
|
||||
</form>'''
|
||||
|
||||
_transaction_add_fields = {
|
||||
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
|
||||
'writeoff_journal_id': {'string': 'Write-Off journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
|
||||
'comment': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
|
||||
'comment': {'string': 'Comment', 'type':'char', 'size': 64 , 'required':True},
|
||||
'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'},
|
||||
}
|
||||
|
||||
def _get_value_addendum(self, cr, uid, data, context={}):
|
||||
return {}
|
||||
return {'comment': _('Write-Off')}
|
||||
|
||||
def _get_period(self, cr, uid, data, context={}):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
@@ -25,6 +25,8 @@ import netsvc
|
||||
import time
|
||||
import osv
|
||||
import pooler
|
||||
from datetime import datetime
|
||||
from tools.translate import _
|
||||
|
||||
_transaction_form = '''<?xml version="1.0"?>
|
||||
<form string="Reconciliation">
|
||||
@@ -70,8 +72,18 @@ def _trans_rec_reconcile(self, cr, uid, data, context=None):
|
||||
|
||||
form = data['form']
|
||||
account_id = form.get('writeoff_acc_id', False)
|
||||
period_id = form.get('period_id', False)
|
||||
context['date_p'] = form.get('date_p', False)
|
||||
date = False
|
||||
if context['date_p']:
|
||||
date = datetime.strptime(context['date_p'], '%Y-%m-%d')
|
||||
ids = pool.get('account.period').find(cr, uid, dt=date, context=context)
|
||||
period_id = False
|
||||
if len(ids):
|
||||
period_id = ids[0]
|
||||
|
||||
journal_id = form.get('journal_id', False)
|
||||
context['comment'] = form.get('comment', False)
|
||||
context['analytic_id'] = form.get('analytic_id', False)
|
||||
account_move_line_obj.reconcile(cr, uid, data['ids'], 'manual', account_id,
|
||||
period_id, journal_id, context=context)
|
||||
return {}
|
||||
@@ -85,23 +97,24 @@ _transaction_add_form = '''<?xml version="1.0"?>
|
||||
<form string="Information addendum">
|
||||
<separator string="Write-Off Move" colspan="4"/>
|
||||
<field name="journal_id"/>
|
||||
<field name="period_id"/>
|
||||
<field name="writeoff_acc_id" domain="[('type', '<>', 'view')]"/>
|
||||
<field name="date_p"/>
|
||||
<field name="comment"/>
|
||||
<separator string="Analytic" colspan="4"/>
|
||||
<field name="analytic_id"/>
|
||||
</form>'''
|
||||
|
||||
_transaction_add_fields = {
|
||||
'journal_id': {'string': 'Write-Off Journal', 'type': 'many2one', 'relation':'account.journal', 'required':True},
|
||||
'period_id': {'string': 'Write-Off Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
|
||||
'writeoff_acc_id': {'string':'Write-Off account', 'type':'many2one', 'relation':'account.account', 'required':True},
|
||||
'date_p': {'string':'Date','type':'date'},
|
||||
'comment': {'string':'Comment','type':'char', 'size': 64, 'required':True},
|
||||
'analytic_id': {'string':'Analytic Account', 'type': 'many2one', 'relation':'account.analytic.account'},
|
||||
}
|
||||
|
||||
def _trans_rec_addendum(self, cr, uid, data, context={}):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
ids = pool.get('account.period').find(cr, uid, context=context)
|
||||
period_id = False
|
||||
if len(ids):
|
||||
period_id = ids[0]
|
||||
return {'period_id':period_id}
|
||||
date_p = time.strftime('%Y-%m-%d')
|
||||
return {'date_p':date_p, 'comment': _('Write-Off')}
|
||||
|
||||
|
||||
class wiz_reconcile(wizard.interface):
|
||||
|
||||
@@ -95,6 +95,7 @@ def create_payment(self, cr, uid, data, context):
|
||||
'partner_id': line.partner_id and line.partner_id.id or False,
|
||||
'communication': line.ref or '/',
|
||||
'date': date_to_pay,
|
||||
'currency': line.invoice and line.invoice.currency_id.id or False,
|
||||
}, context=context)
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user