[IMP] anlaytic: display total of balance/credit/debit on group_by
Purpose ======= User not able to see his total balance per customer if user has several projects with same customer.. see here : https://www.odoo.com/web/content/3287924 Specification ============= User should be able to see the sum of the debit, credit and balance when group by partner The difficulty here is that debit,credit and balance are non-stored computed fields depending on the company and the date passed with the context. As these parameters depend on the user and the current date, we can't store the field. The simplest way to achieve this is to override the read_group method and compute the sum by hand when the values are aggregated (means when a group_by is applied).
This commit is contained in:
committed by
Yannick Tivisse
parent
1ce899d118
commit
ccaea94a66
@@ -59,6 +59,24 @@ class AccountAnalyticAccount(models.Model):
|
||||
_description = 'Analytic Account'
|
||||
_order = 'code, name asc'
|
||||
|
||||
@api.model
|
||||
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
|
||||
"""
|
||||
Override read_group to calculate the sum of the non-stored fields that depend on the user context
|
||||
"""
|
||||
res = super(AccountAnalyticAccount, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
|
||||
accounts = self.env['account.analytic.account']
|
||||
for line in res:
|
||||
if '__domain' in line:
|
||||
accounts = self.search(line['__domain'])
|
||||
if 'balance' in fields:
|
||||
line['balance'] = sum(accounts.mapped('balance'))
|
||||
if 'debit' in fields:
|
||||
line['debit'] = sum(accounts.mapped('debit'))
|
||||
if 'credit' in fields:
|
||||
line['credit'] = sum(accounts.mapped('credit'))
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _compute_debit_credit_balance(self):
|
||||
res_currency_obj = self.env['res.currency']
|
||||
|
||||
@@ -190,9 +190,9 @@
|
||||
<field name="partner_id"/>
|
||||
<field name="active" invisible="1"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="debit"/>
|
||||
<field name="credit"/>
|
||||
<field name="balance"/>
|
||||
<field name="debit" sum="Debit"/>
|
||||
<field name="credit" sum="Credit"/>
|
||||
<field name="balance" sum="Balance"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user