-
analytic_account_id
-
analytic_account_id.ids
-
analytic_account_id.id
|
if not self.analytic_account_id:
self.purchase_orders_count = 0
return
query = self.env['purchase.order.line']._search([])
query.add_where(
SQL(
"%s && %s",
[str(account_id) for account_id in self.analytic_account_id.ids],
self.env['purchase.order.line']._query_analytic_accounts(),
)
)
query_string, query_param = query.select(
r"""DISTINCT order_id, (regexp_matches(jsonb_object_keys(purchase_order_line.analytic_distribution), '\d+', 'g'))[1]::int as account_id"""
)
query_string = f"""
SELECT account_id, count(order_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()}
for project in self:
project.purchase_orders_count = data.get(project.analytic_account_id.id, 0)
|
|