[MRG] improved sale analysis report to convert amount in cureent user currency:lp:~openerp-dev/openobject-addons/trunk-salesteam-kanban-tpa-improve-chirag
bzr revid: tpa@tinyerp.com-20130808091035-4smdbjrxi3jpomcc
This commit is contained in:
@@ -27,6 +27,17 @@ class sale_report(osv.osv):
|
||||
_description = "Sales Orders Statistics"
|
||||
_auto = False
|
||||
_rec_name = 'date'
|
||||
def _compute_total_in_user_currency(self, cr, uid, ids, field_names=[], args={}, context=None):
|
||||
"""Compute the Price total in the currency of the user
|
||||
"""
|
||||
res = {}
|
||||
currency_obj = self.pool.get('res.currency')
|
||||
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
|
||||
for item in self.browse(cr, uid, ids, context=context):
|
||||
res[item.id] = {
|
||||
'user_price_total': currency_obj.compute(cr, uid, item.pricelist_id.currency_id.id, user_currency_id, item.price_total, context=context),
|
||||
}
|
||||
return res
|
||||
_columns = {
|
||||
'date': fields.date('Date Order', readonly=True),
|
||||
'date_confirm': fields.date('Date Confirm', readonly=True),
|
||||
@@ -57,6 +68,7 @@ class sale_report(osv.osv):
|
||||
], 'Order Status', readonly=True),
|
||||
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', readonly=True),
|
||||
'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
|
||||
'user_price_total': fields.function(_compute_total_in_user_currency, string="Total Price", type='float',digits=(16,2), multi="_compute_amounts", readonly=True),
|
||||
}
|
||||
_order = 'date desc'
|
||||
|
||||
@@ -113,6 +125,16 @@ class sale_report(osv.osv):
|
||||
"""
|
||||
return group_by_str
|
||||
|
||||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
|
||||
res = super(sale_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby)
|
||||
for group in res:
|
||||
group['user_price_total'] = 0
|
||||
group_ids = self.search(cr, uid, group.get('__domain'),context=context)
|
||||
record = self._compute_total_in_user_currency(cr, uid, group_ids, context=context)
|
||||
for id, rec in record.iteritems():
|
||||
group['user_price_total'] += rec['user_price_total']
|
||||
return res
|
||||
|
||||
def init(self, cr):
|
||||
# self._table = sale_report
|
||||
tools.drop_view_if_exists(cr, self._table)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<field name="nbr" sum="# of Lines"/>
|
||||
<field name="product_uom_qty" sum="# of Qty"/>
|
||||
<field name="product_uom" invisible="not context.get('set_visible',False)"/>
|
||||
<field name="price_total" sum="Total Price"/>
|
||||
<field name="user_price_total" sum="Total Price"/>
|
||||
<field name="delay" sum="Commitment Delay"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="analytic_account_id" invisible="1" groups="analytic.group_analytic_accounting"/>
|
||||
|
||||
Reference in New Issue
Block a user