summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqdp-launchpad@tinyerp.com <>2011-01-05 14:46:54 +0100
committerqdp-launchpad@tinyerp.com <>2011-01-05 14:46:54 +0100
commitb0b8fe2aafa0ce8af1925c790937cb8097f3a259 (patch)
tree5ec2e9f753d9aa6ed8d913c1deb3c2895eec8635
parent359d6d5c9216b044ff87a436ee74b149c57d32f9 (diff)
[IMP] account: defined new fields (amount_residual and amount_residual_currency) as function to compute the residual amount (resp. in company currency and in the currency of teh move line) direclty on the account.move.line object (to refactor the code). Changed the residual amount of the account.invoice in order to reuse the code depicted above. +few changes to improve the translations
bzr revid: qdp-launchpad@tinyerp.com-20110105134654-bils0yz2w1vwjtpy
-rw-r--r--addons/account/account_move_line.py53
-rw-r--r--addons/account/invoice.py34
-rw-r--r--addons/account/report/common_report_header.py10
3 files changed, 66 insertions, 31 deletions
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index 704287cdd6f..9b4af85164e 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -100,6 +100,57 @@ class account_move_line(osv.osv):
return query
+ def _amount_residual(self, cr, uid, ids, field_names, args, context=None):
+ """
+ This function returns the residual amount on a receivable or payable account.move.line.
+ By default, it returns an amount in the currency of this journal entry (maybe different
+ of the company currency), but if you pass 'residual_in_company_currency' = True in the
+ context then the returned amount will be in company currency.
+ """
+ res = {}
+ if context is None:
+ context = {}
+ cur_obj = self.pool.get('res.currency')
+ for move_line in self.browse(cr, uid, ids, context=context):
+ res[move_line.id] = {
+ 'amount_residual': 0.0,
+ 'amount_residual_currency': 0.0,
+ }
+
+ if move_line.reconcile_id:
+ continue
+ if not move_line.account_id.type in ('payable', 'receivable'):
+ #this function does not suport to be used on move lines not related to payable or receivable accounts
+ continue
+
+ if move_line.currency_id:
+ move_line_total = move_line.amount_currency
+ sign = move_line.amount_currency < 0 and -1 or 1
+ else:
+ move_line_total = move_line.debit - move_line.credit
+ sign = (move_line.debit - move_line.credit) < 0 and -1 or 1
+ line_total_in_company_currency = move_line.debit - move_line.credit
+ context_unreconciled = context.copy()
+ if move_line.reconcile_partial_id:
+ for payment_line in move_line.reconcile_partial_id.line_partial_ids:
+ if payment_line.id == move_line.id:
+ continue
+ if payment_line.currency_id and move_line.currency_id and payment_line.currency_id.id == move_line.currency_id.id:
+ move_line_total += payment_line.amount_currency
+ else:
+ if move_line.currency_id:
+ context_unreconciled.update({'date': payment_line.date})
+ amount_in_foreign_currency = cur_obj.compute(cr, uid, move_line.company_id.currency_id.id, move_line.currency_id.id, (payment_line.debit - payment_line.credit), round=False, context=context_unreconciled)
+ move_line_total += amount_in_foreign_currency
+ else:
+ move_line_total += (payment_line.debit - payment_line.credit)
+ line_total_in_company_currency += (payment_line.debit - payment_line.credit)
+
+ result = move_line_total
+ res[move_line.id]['amount_residual_currency'] = sign * (move_line.currency_id and self.pool.get('res.currency').round(cr, uid, move_line.currency_id, result) or result)
+ res[move_line.id]['amount_residual'] = sign * line_total_in_company_currency
+ return res
+
def default_get(self, cr, uid, fields, context=None):
data = self._default_get(cr, uid, fields, context=context)
for f in data.keys():
@@ -433,6 +484,8 @@ class account_move_line(osv.osv):
'reconcile_id': fields.many2one('account.move.reconcile', 'Reconcile', readonly=True, ondelete='set null', select=2),
'reconcile_partial_id': fields.many2one('account.move.reconcile', 'Partial Reconcile', readonly=True, ondelete='set null', select=2),
'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency if it is a multi-currency entry.", digits_compute=dp.get_precision('Account')),
+ 'amount_residual_currency': fields.function(_amount_residual, method=True, string='Residual Amount', multi="residual", help="The residual amount on a receivable or payable of a journal entry expressed in its currency (maybe different of the company currency)."),
+ 'amount_residual': fields.function(_amount_residual, method=True, string='Residual Amount', multi="residual", help="The residual amount on a receivable or payable of a journal entry expressed in the company currency."),
'currency_id': fields.many2one('res.currency', 'Currency', help="The optional other currency if it is a multi-currency entry."),
'period_id': fields.many2one('account.period', 'Period', required=True, select=2),
'journal_id': fields.many2one('account.journal', 'Journal', required=True, select=1),
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index f094e1c5f3b..f9bf0b26efc 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -88,32 +88,14 @@ class account_invoice(osv.osv):
return [('none', _('Free Reference'))]
def _amount_residual(self, cr, uid, ids, name, args, context=None):
- res = {}
- if context is None:
- context = {}
-
- cur_obj = self.pool.get('res.currency')
- data_inv = self.browse(cr, uid, ids, context=context)
- for inv in data_inv:
- if inv.reconciled:
- res[inv.id] = 0.0
- continue
- inv_total = inv.amount_total
- context_unreconciled = context.copy()
- for lines in inv.move_lines:
- if lines.currency_id and lines.currency_id.id == inv.currency_id.id:
- if inv.type in ('out_invoice','in_refund'):
- inv_total += lines.amount_currency
- else:
- inv_total -= lines.amount_currency
- else:
- context_unreconciled.update({'date': lines.date})
- amount_in_invoice_currency = cur_obj.compute(cr, uid, inv.company_id.currency_id.id, inv.currency_id.id,abs(lines.debit-lines.credit),round=False,context=context_unreconciled)
- inv_total -= amount_in_invoice_currency
-
- result = inv_total
- res[inv.id] = self.pool.get('res.currency').round(cr, uid, inv.currency_id, result)
- return res
+ result = {}
+ for invoice in self.browse(cr, uid, ids, context=context):
+ result[invoice.id] = 0.0
+ if invoice.move_id:
+ for m in invoice.move_id.line_id:
+ if m.account_id.type in ('receivable','payable'):
+ result[invoice.id] = m.amount_residual_currency
+ return result
# Give Journal Items related to the payment reconciled to this invoice
# Return ids of partial and total payments related to the selected invoices
diff --git a/addons/account/report/common_report_header.py b/addons/account/report/common_report_header.py
index 809cb38e879..48e26e839d3 100644
--- a/addons/account/report/common_report_header.py
+++ b/addons/account/report/common_report_header.py
@@ -64,8 +64,8 @@ class common_report_header(object):
def _get_target_move(self, data):
if data.get('form', False) and data['form'].get('target_move', False):
if data['form']['target_move'] == 'all':
- return 'All Entries'
- return 'All Posted Entries'
+ return _('All Entries')
+ return _('All Posted Entries')
return ''
def _get_end_date(self, data):
@@ -94,10 +94,10 @@ class common_report_header(object):
def _get_filter(self, data):
if data.get('form', False) and data['form'].get('filter', False):
if data['form']['filter'] == 'filter_date':
- return 'Date'
+ return _('Date')
elif data['form']['filter'] == 'filter_period':
- return 'Periods'
- return 'No Filter'
+ return _('Periods')
+ return _('No Filter')
def _sum_debit_period(self, period_id, journal_id=None):
journals = journal_id or self.journal_ids