Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Sales - Project
Entity: project.project
Compute Method: _compute_invoice_count
| Inputs | Method | Outputs |
|---|---|---|
|
- query = self.env['account.move.line']._search([('move_id.move_type', 'in', ['out_invoice', 'out_refund'])]) - query.add_where( - SQL( - "%s && %s", - [str(project.analytic_account_id.id) for project in self], - self.env['account.move.line']._query_analytic_accounts(), - ) - ) - query.order = None - query_string, query_param = query.select( - r"""DISTINCT move_id, (regexp_matches(jsonb_object_keys(account_move_line.analytic_distribution), '\d+', 'g'))[1]::int as account_id""" + data = self.env['account.move.line']._read_group( + [('move_id.move_type', 'in', ['out_invoice', 'out_refund']), ('analytic_distribution', 'in', self.account_id.ids)], + groupby=['analytic_distribution'], + aggregates=['__count'], ) - query_string = f""" - SELECT account_id, count(move_id) FROM - ({query_string}) distribution - GROUP BY account_id - """ - self._cr.execute(query_string, query_param) - data = {res['account_id']: res['count'] for res in self._cr.dictfetchall()} + data = {int(account_id): move_count for account_id, move_count in data} for project in self: - project.invoice_count = data.get(project.analytic_account_id.id, 0) + project.invoice_count = data.get(project.account_id.id, 0) |
|
