Merge lp:~openerp-dev/openobject-addons/7.0-invoices-analysis-api into lp:openobject-addons/7.0

Proposed by qdp (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-invoices-analysis-api
Merge into: lp:openobject-addons/7.0
Diff against target: 90 lines (+23/-27)
2 files modified
account/report/account_invoice_report.py (+21/-27)
account/report/account_invoice_report_view.xml (+2/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-invoices-analysis-api
Reviewer Review Type Date Requested Status
qdp (OpenERP) Pending
Review via email: mp+142133@code.launchpad.net

This proposal supersedes a proposal from 2013-01-03.

Description of the change

This branch replace the old 7.0-bug-account-api because the previous one had too many unnecessary commit.

API

To post a comment you must log in.

Unmerged revisions

8525. By Arnaud Pineux (OpenERP)

[FIX] account_invoice_report: remove unused field and compute values in user currency

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/report/account_invoice_report.py'
2--- account/report/account_invoice_report.py 2012-12-19 10:57:58 +0000
3+++ account/report/account_invoice_report.py 2013-01-07 15:27:25 +0000
4@@ -29,30 +29,6 @@
5 _auto = False
6 _rec_name = 'date'
7
8- def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names, args, context=None):
9- """Compute the amounts in the currency of the user
10- """
11- if context is None:
12- context={}
13- currency_obj = self.pool.get('res.currency')
14- currency_rate_obj = self.pool.get('res.currency.rate')
15- user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
16- currency_rate_id = currency_rate_obj.search(cr, uid, [('rate', '=', 1)], limit=1, context=context)[0]
17- base_currency_id = currency_rate_obj.browse(cr, uid, currency_rate_id, context=context).currency_id.id
18- res = {}
19- ctx = context.copy()
20- for item in self.browse(cr, uid, ids, context=context):
21- ctx['date'] = item.date
22- price_total = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.price_total, context=ctx)
23- price_average = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.price_average, context=ctx)
24- residual = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.residual, context=ctx)
25- res[item.id] = {
26- 'user_currency_price_total': price_total,
27- 'user_currency_price_average': price_average,
28- 'user_currency_residual': residual,
29- }
30- return res
31-
32 _columns = {
33 'date': fields.date('Date', readonly=True),
34 'year': fields.char('Year', size=4, readonly=True),
35@@ -73,9 +49,7 @@
36 'company_id': fields.many2one('res.company', 'Company', readonly=True),
37 'user_id': fields.many2one('res.users', 'Salesperson', readonly=True),
38 'price_total': fields.float('Total Without Tax', readonly=True),
39- '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"),
40 'price_average': fields.float('Average Price', readonly=True, group_operator="avg"),
41- '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"),
42 'currency_rate': fields.float('Currency Rate', readonly=True),
43 'nbr':fields.integer('# of Lines', readonly=True),
44 'type': fields.selection([
45@@ -97,10 +71,30 @@
46 'account_line_id': fields.many2one('account.account', 'Account Line',readonly=True),
47 'partner_bank_id': fields.many2one('res.partner.bank', 'Bank Account',readonly=True),
48 'residual': fields.float('Total Residual', readonly=True),
49- 'user_currency_residual': fields.function(_compute_amounts_in_user_currency, string="Total Residual", type='float', digits_compute=dp.get_precision('Account'), multi="_compute_amounts"),
50 }
51 _order = 'date desc'
52
53+ def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
54+ ''' The field "price_total" is the total price in EUR but the read_group method will recompute on the fly this price.
55+ The price is recomputed in the user currency in order to be displayed in the view.
56+ '''
57+ if context is None:
58+ context = {}
59+ res = super(account_invoice_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby)
60+ currency_obj = self.pool.get('res.currency')
61+ currency_rate_obj = self.pool.get('res.currency.rate')
62+ user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
63+ currency_rate_id = currency_rate_obj.search(cr, uid, [('rate', '=', 1)], limit=1, context=context)[0]
64+ base_currency_id = currency_rate_obj.browse(cr, uid, currency_rate_id, context=context).currency_id.id
65+ for elmt in res:
66+ if "price_total" in elmt and elmt['price_total']:
67+ elmt['price_total'] = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, elmt['price_total'], context=context)
68+ if "price_average" in elmt and elmt['price_average']:
69+ elmt['price_average'] = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, elmt['price_average'], context=context)
70+ if "residual" in elmt and elmt['residual']:
71+ elmt['residual'] = currency_obj.compute(cr, uid, base_currency_id, user_currency_id, elmt['residual'], context=context)
72+ return res
73+
74 def _select(self):
75 select_str = """
76 SELECT sub.id, sub.date, sub.year, sub.month, sub.day, sub.product_id, sub.partner_id,
77
78=== modified file 'account/report/account_invoice_report_view.xml'
79--- account/report/account_invoice_report_view.xml 2012-12-24 14:20:46 +0000
80+++ account/report/account_invoice_report_view.xml 2013-01-07 15:27:25 +0000
81@@ -28,7 +28,9 @@
82 <field name="nbr" sum="# of Lines"/>
83 <field name="product_qty" sum="Qty"/>
84 <!-- <field name="reconciled" sum="# Reconciled"/> -->
85+ <field name="price_average" avg="Average Price"/>
86 <field name="price_total" sum="Total Without Tax"/>
87+ <field name="residual" sum="Total Residual"/>
88 </tree>
89 </field>
90 </record>