[FIX] account, invoice analysis report: fixed 2 bugs in multi-currency environments (1) wrong currency rate chosen for transformation into base currency because of missing 'order by' statement; (2) re-transformation of amounts into user's currency instead of leaving them in base currency (rate=1)
bzr revid: qdp-launchpad@openerp.com-20121015112530-6bbo1xia2f3i5fzf
This commit is contained in:
parent
90066e17f4
commit
b5b9bc9872
|
@ -20,6 +20,7 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
import decimal_precision as dp
|
||||||
from osv import fields,osv
|
from osv import fields,osv
|
||||||
|
|
||||||
class account_invoice_report(osv.osv):
|
class account_invoice_report(osv.osv):
|
||||||
|
@ -27,6 +28,31 @@ class account_invoice_report(osv.osv):
|
||||||
_description = "Invoices Statistics"
|
_description = "Invoices Statistics"
|
||||||
_auto = False
|
_auto = False
|
||||||
_rec_name = 'date'
|
_rec_name = 'date'
|
||||||
|
|
||||||
|
def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names, args, context=None):
|
||||||
|
"""Compute the amounts in the currency of the user
|
||||||
|
"""
|
||||||
|
if context is None:
|
||||||
|
context={}
|
||||||
|
currency_obj = self.pool.get('res.currency')
|
||||||
|
currency_rate_obj = self.pool.get('res.currency.rate')
|
||||||
|
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||||
|
currency_rate_id = currency_rate_obj.search(cr, uid, [('rate', '=', 1)], limit=1, context=context)[0]
|
||||||
|
base_currency_id = currency_rate_obj.browse(cr, uid, currency_rate_id, context=context).currency_id.id
|
||||||
|
res = {}
|
||||||
|
ctx = context.copy()
|
||||||
|
for item in self.browse(cr, uid, ids, context=context):
|
||||||
|
ctx['date'] = item.date
|
||||||
|
price_total = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.price_total, context=ctx)
|
||||||
|
price_average = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.price_average, context=ctx)
|
||||||
|
residual = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.residual, context=ctx)
|
||||||
|
res[item.id] = {
|
||||||
|
'user_currency_price_total': price_total,
|
||||||
|
'user_currency_price_average': price_average,
|
||||||
|
'user_currency_residual': residual,
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'date': fields.date('Date', readonly=True),
|
'date': fields.date('Date', readonly=True),
|
||||||
'year': fields.char('Year', size=4, readonly=True),
|
'year': fields.char('Year', size=4, readonly=True),
|
||||||
|
@ -47,7 +73,9 @@ class account_invoice_report(osv.osv):
|
||||||
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
||||||
'user_id': fields.many2one('res.users', 'Salesperson', readonly=True),
|
'user_id': fields.many2one('res.users', 'Salesperson', readonly=True),
|
||||||
'price_total': fields.float('Total Without Tax', readonly=True),
|
'price_total': fields.float('Total Without Tax', readonly=True),
|
||||||
|
'user_currency_price_total': fields.function(_compute_amounts_in_user_currency, string="Total Without Tax", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
|
||||||
'price_average': fields.float('Average Price', readonly=True, group_operator="avg"),
|
'price_average': fields.float('Average Price', readonly=True, group_operator="avg"),
|
||||||
|
'user_currency_price_average': fields.function(_compute_amounts_in_user_currency, string="Average Price", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
|
||||||
'currency_rate': fields.float('Currency Rate', readonly=True),
|
'currency_rate': fields.float('Currency Rate', readonly=True),
|
||||||
'nbr':fields.integer('# of Lines', readonly=True),
|
'nbr':fields.integer('# of Lines', readonly=True),
|
||||||
'type': fields.selection([
|
'type': fields.selection([
|
||||||
|
@ -69,6 +97,7 @@ class account_invoice_report(osv.osv):
|
||||||
'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
|
'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
|
||||||
'partner_bank_id': fields.many2one('res.partner.bank', 'Bank Account',readonly=True),
|
'partner_bank_id': fields.many2one('res.partner.bank', 'Bank Account',readonly=True),
|
||||||
'residual': fields.float('Total Residual', readonly=True),
|
'residual': fields.float('Total Residual', readonly=True),
|
||||||
|
'user_currency_residual': fields.function(_compute_amounts_in_user_currency, string="Total Residual", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
|
||||||
'delay_to_pay': fields.float('Avg. Delay To Pay', readonly=True, group_operator="avg"),
|
'delay_to_pay': fields.float('Avg. Delay To Pay', readonly=True, group_operator="avg"),
|
||||||
'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
|
'due_delay': fields.float('Avg. Due Delay', readonly=True, group_operator="avg"),
|
||||||
}
|
}
|
||||||
|
@ -161,7 +190,7 @@ class account_invoice_report(osv.osv):
|
||||||
left join product_uom u on (u.id=ail.uos_id),
|
left join product_uom u on (u.id=ail.uos_id),
|
||||||
res_currency_rate cr
|
res_currency_rate cr
|
||||||
where cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)
|
where cr.id in (select id from res_currency_rate cr2 where (cr2.currency_id = ai.currency_id)
|
||||||
and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) limit 1)
|
and ((ai.date_invoice is not null and cr.name <= ai.date_invoice) or (ai.date_invoice is null and cr.name <= NOW())) order by name desc limit 1)
|
||||||
group by ail.product_id,
|
group by ail.product_id,
|
||||||
ai.date_invoice,
|
ai.date_invoice,
|
||||||
ai.id,
|
ai.id,
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
<field name="nbr" sum="# of Lines"/>
|
<field name="nbr" sum="# of Lines"/>
|
||||||
<field name="product_qty" sum="Qty"/>
|
<field name="product_qty" sum="Qty"/>
|
||||||
<!-- <field name="reconciled" sum="# Reconciled"/> -->
|
<!-- <field name="reconciled" sum="# Reconciled"/> -->
|
||||||
<field name="price_total" sum="Total Without Tax"/>
|
<field name="user_currency_price_total" sum="Total Without Tax"/>
|
||||||
<field name="residual" sum="Total Residual" invisible="context.get('residual_invisible',False)"/>
|
<field name="user_currency_residual" sum="Total Residual" invisible="context.get('residual_invisible',False)"/>
|
||||||
<field name="due_delay" sum="Avg. Due Delay" invisible="context.get('residual_invisible',False)"/>
|
<field name="due_delay" sum="Avg. Due Delay" invisible="context.get('residual_invisible',False)"/>
|
||||||
<field name="delay_to_pay" sum="Avg. Delay To Pay" invisible="context.get('residual_invisible',False)"/>
|
<field name="delay_to_pay" sum="Avg. Delay To Pay" invisible="context.get('residual_invisible',False)"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<graph string="Invoices Analysis" type="bar">
|
<graph string="Invoices Analysis" type="bar">
|
||||||
<field name="product_id"/>
|
<field name="product_id"/>
|
||||||
<field name="price_total"/>
|
<field name="user_currency_price_total"/>
|
||||||
</graph>
|
</graph>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
Loading…
Reference in New Issue