From 05fc9a67335d5a96752d828defa066d4fdabe301 Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Fri, 25 Feb 2022 12:51:42 +0000 Subject: [PATCH] [IMP] *: use _read_group instead of read_group This commit modifies most of the usages of read_group and uses _read_group instead. _read_group doesn't join automatically on the many2one fields when no order_by is specified, making it more performant when the "name" of the many2one is not relevant, which is the case for most back-end cases closes odoo/odoo#84908 Task-id: 2479334 Related: odoo/enterprise#24877 Signed-off-by: Raphael Collet --- addons/account/models/account_account.py | 4 ++-- .../account/models/account_analytic_line.py | 4 ++-- .../models/account_journal_dashboard.py | 2 +- .../account/models/account_reconcile_model.py | 2 +- addons/account/models/partner.py | 2 +- .../account_debit_note/models/account_move.py | 2 +- addons/account_fleet/models/fleet_vehicle.py | 2 +- addons/coupon/models/coupon_program.py | 2 +- addons/crm/models/crm_lead.py | 4 ++-- addons/crm/models/crm_lost_reason.py | 2 +- addons/crm/models/crm_team.py | 6 ++--- addons/crm/models/res_partner.py | 2 +- addons/crm/models/utm.py | 2 +- .../models/crm_iap_lead_mining_request.py | 2 +- addons/event_booth/models/event_event.py | 2 +- addons/event_booth_sale/models/sale_order.py | 2 +- addons/event_crm/models/event_event.py | 2 +- addons/event_sale/models/event_event.py | 2 +- addons/event_sale/models/sale_order.py | 2 +- addons/fleet/models/fleet_vehicle_model.py | 2 +- .../models/gamification_karma_rank.py | 2 +- addons/hr/models/hr_department.py | 2 +- addons/hr/models/hr_job.py | 2 +- addons/hr_contract/models/hr_employee.py | 2 +- addons/hr_contract/models/resource.py | 2 +- addons/hr_expense/models/hr_department.py | 2 +- addons/hr_expense/models/hr_expense.py | 4 ++-- addons/hr_fleet/models/employee.py | 2 +- .../models/fleet_vehicle_assignation_log.py | 2 +- addons/hr_holidays/models/hr_department.py | 6 ++--- addons/hr_holidays/models/hr_employee.py | 4 ++-- .../models/hr_leave_accrual_plan.py | 4 ++-- addons/hr_holidays/models/hr_leave_type.py | 6 ++--- addons/hr_recruitment/models/hr_department.py | 4 ++-- addons/hr_recruitment/models/hr_job.py | 4 ++-- .../hr_recruitment/models/hr_recruitment.py | 4 ++-- addons/hr_recruitment/models/res_users.py | 4 ++-- addons/hr_timesheet/models/project.py | 4 ++-- .../hr_work_entry_holidays/models/hr_leave.py | 2 +- addons/im_livechat/models/digest.py | 2 +- .../im_livechat/models/im_livechat_channel.py | 2 +- addons/link_tracker/models/link_tracker.py | 2 +- addons/link_tracker/models/utm.py | 2 +- addons/lunch/models/lunch_product_category.py | 2 +- addons/mail/models/mail_channel.py | 2 +- addons/mail/models/mail_thread.py | 2 +- addons/mail_group/models/mail_group.py | 6 ++--- addons/maintenance/models/maintenance.py | 4 ++-- addons/mass_mailing/models/utm_campaign.py | 2 +- .../models/mailing_mailing.py | 2 +- .../models/mailing_mailing.py | 4 ++-- addons/mrp/models/mrp_production.py | 6 ++--- addons/mrp/models/mrp_routing.py | 2 +- addons/mrp/models/mrp_workcenter.py | 10 ++++---- addons/mrp/models/mrp_workorder.py | 2 +- addons/mrp/models/product.py | 2 +- addons/mrp/models/stock_picking.py | 2 +- addons/payment/models/account_payment.py | 2 +- addons/payment/models/payment_transaction.py | 2 +- addons/payment/models/res_partner.py | 2 +- addons/point_of_sale/models/pos_session.py | 6 ++--- addons/point_of_sale/models/res_partner.py | 2 +- addons/pos_sale/models/crm_team.py | 2 +- addons/project/models/analytic_account.py | 2 +- addons/project/models/project.py | 16 ++++++------- addons/project/models/res_partner.py | 2 +- addons/project_hr_expense/models/project.py | 2 +- addons/project_purchase/models/project.py | 2 +- .../models/resource_calendar_leaves.py | 6 ++--- addons/purchase/models/product.py | 2 +- addons/purchase/models/res_partner.py | 4 ++-- addons/rating/models/rating_mixin.py | 2 +- addons/sale/models/crm_team.py | 4 ++-- addons/sale/models/product_product.py | 4 ++-- addons/sale/models/res_partner.py | 2 +- addons/sale/models/utm_campaign.py | 2 +- addons/sale_expense/models/sale_order.py | 2 +- addons/sale_management/models/digest.py | 2 +- addons/sale_timesheet/models/account_move.py | 6 ++--- addons/sale_timesheet/models/project.py | 6 ++--- addons/sale_timesheet/models/sale_order.py | 2 +- addons/stock/models/product.py | 24 +++++++++---------- addons/stock/models/stock_location.py | 8 +++---- addons/stock/models/stock_lot.py | 2 +- addons/stock/models/stock_move.py | 6 ++--- addons/stock/models/stock_orderpoint.py | 8 +++---- addons/stock/models/stock_picking.py | 6 ++--- addons/stock/models/stock_quant.py | 4 ++-- addons/stock/models/stock_warehouse.py | 2 +- .../stock/report/report_stock_forecasted.py | 4 ++-- addons/stock_account/models/product.py | 2 +- .../models/stock_picking.py | 2 +- addons/survey/models/res_partner.py | 2 +- addons/survey/models/survey_survey.py | 8 +++---- addons/website/models/website_visitor.py | 4 ++-- .../models/crm_reveal_rule.py | 2 +- .../models/res_partner.py | 4 ++-- .../website_event/models/website_visitor.py | 2 +- .../models/event_event.py | 2 +- .../website_event_meet/models/event_event.py | 2 +- .../website_event_track/models/event_event.py | 2 +- .../website_event_track/models/event_track.py | 2 +- .../models/website_visitor.py | 2 +- addons/website_forum/models/forum.py | 4 ++-- addons/website_sale/controllers/backend.py | 6 ++--- addons/website_sale/models/crm_team.py | 2 +- .../models/website_snippet_filter.py | 2 +- addons/website_sale/models/website_visitor.py | 2 +- addons/website_sale_digital/models/product.py | 2 +- .../models/slide_channel.py | 2 +- addons/website_slides/models/res_partner.py | 2 +- addons/website_slides/models/slide_channel.py | 8 +++---- addons/website_slides/models/slide_slide.py | 6 ++--- 113 files changed, 194 insertions(+), 194 deletions(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index 15a6fc5181d..5bd4555e8c2 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -48,7 +48,7 @@ class AccountAccount(models.Model): @api.constrains('user_type_id') def _check_user_type_id_unique_current_year_earning(self): data_unaffected_earnings = self.env.ref('account.data_unaffected_earnings') - result = self.read_group([('user_type_id', '=', data_unaffected_earnings.id)], ['company_id'], ['company_id']) + result = self._read_group([('user_type_id', '=', data_unaffected_earnings.id)], ['company_id'], ['company_id']) for res in result: if res.get('company_id_count', 0) >= 2: account_unaffected_earnings = self.search([('company_id', '=', res['company_id'][0]), @@ -312,7 +312,7 @@ class AccountAccount(models.Model): def _compute_current_balance(self): balances = { read['account_id'][0]: read['balance'] - for read in self.env['account.move.line'].read_group( + for read in self.env['account.move.line']._read_group( domain=[('account_id', 'in', self.ids)], fields=['balance', 'account_id'], groupby=['account_id'], diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index 58395a38b38..9f67e339d8a 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -37,7 +37,7 @@ class AccountAnalyticAccount(models.Model): ('move_id.move_type', 'in', sale_types), ('analytic_account_id', 'in', self.ids) ] - groups = self.env['account.move.line'].read_group(domain, ['move_id:count_distinct'], ['analytic_account_id']) + groups = self.env['account.move.line']._read_group(domain, ['move_id:count_distinct'], ['analytic_account_id']) moves_count_mapping = dict((g['analytic_account_id'][0], g['move_id']) for g in groups) for account in self: account.invoice_count = moves_count_mapping.get(account.id, 0) @@ -50,7 +50,7 @@ class AccountAnalyticAccount(models.Model): ('move_id.move_type', 'in', purchase_types), ('analytic_account_id', 'in', self.ids) ] - groups = self.env['account.move.line'].read_group(domain, ['move_id:count_distinct'], ['analytic_account_id']) + groups = self.env['account.move.line']._read_group(domain, ['move_id:count_distinct'], ['analytic_account_id']) moves_count_mapping = dict((g['analytic_account_id'][0], g['move_id']) for g in groups) for account in self: account.vendor_bill_count = moves_count_mapping.get(account.id, 0) diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index bdf6aeb065b..fc3844a9e6d 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -76,7 +76,7 @@ class account_journal(models.Model): def _compute_entries_count(self): res = { r['journal_id'][0]: r['journal_id_count'] - for r in self.env['account.move'].read_group( + for r in self.env['account.move']._read_group( domain=[('journal_id', 'in', self.ids)], fields=['journal_id'], groupby=['journal_id'], diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index a0546f14309..a98f5275b5f 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -281,7 +281,7 @@ class AccountReconcileModel(models.Model): return action def _compute_number_entries(self): - data = self.env['account.move.line'].read_group([('reconcile_model_id', 'in', self.ids)], ['reconcile_model_id'], 'reconcile_model_id') + data = self.env['account.move.line']._read_group([('reconcile_model_id', 'in', self.ids)], ['reconcile_model_id'], 'reconcile_model_id') mapped_data = dict([(d['reconcile_model_id'][0], d['reconcile_model_id_count']) for d in data]) for model in self: model.number_entries = mapped_data.get(model.id, 0) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 42732cf3793..f06a86cab56 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -504,7 +504,7 @@ class ResPartner(models.Model): return '%s, %s' % (res, order_by_field % field) if res else order_by_field def _compute_bank_count(self): - bank_data = self.env['res.partner.bank'].read_group([('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id']) + bank_data = self.env['res.partner.bank']._read_group([('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id']) mapped_data = dict([(bank['partner_id'][0], bank['partner_id_count']) for bank in bank_data]) for partner in self: partner.bank_account_count = mapped_data.get(partner.id, 0) diff --git a/addons/account_debit_note/models/account_move.py b/addons/account_debit_note/models/account_move.py index 75b5768da14..177e6236a2c 100644 --- a/addons/account_debit_note/models/account_move.py +++ b/addons/account_debit_note/models/account_move.py @@ -13,7 +13,7 @@ class AccountMove(models.Model): @api.depends('debit_note_ids') def _compute_debit_count(self): - debit_data = self.env['account.move'].read_group([('debit_origin_id', 'in', self.ids)], + debit_data = self.env['account.move']._read_group([('debit_origin_id', 'in', self.ids)], ['debit_origin_id'], ['debit_origin_id']) data_map = {datum['debit_origin_id'][0]: datum['debit_origin_id_count'] for datum in debit_data} for inv in self: diff --git a/addons/account_fleet/models/fleet_vehicle.py b/addons/account_fleet/models/fleet_vehicle.py index 02c200b3385..b88946e9248 100644 --- a/addons/account_fleet/models/fleet_vehicle.py +++ b/addons/account_fleet/models/fleet_vehicle.py @@ -16,7 +16,7 @@ class FleetVehicle(models.Model): self.bill_count = 0 return - moves = self.env['account.move.line'].read_group( + moves = self.env['account.move.line']._read_group( domain=[ ('vehicle_id', 'in', self.ids), ('move_id.state', '!=', 'cancel'), diff --git a/addons/coupon/models/coupon_program.py b/addons/coupon/models/coupon_program.py index 69d0092bac7..e5b55603a44 100644 --- a/addons/coupon/models/coupon_program.py +++ b/addons/coupon/models/coupon_program.py @@ -63,7 +63,7 @@ class CouponProgram(models.Model): @api.depends('coupon_ids') def _compute_coupon_count(self): - coupon_data = self.env['coupon.coupon'].read_group([('program_id', 'in', self.ids)], ['program_id'], ['program_id']) + coupon_data = self.env['coupon.coupon']._read_group([('program_id', 'in', self.ids)], ['program_id'], ['program_id']) mapped_data = dict([(m['program_id'][0], m['program_id_count']) for m in coupon_data]) for program in self: program.coupon_count = mapped_data.get(program.id, 0) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index c3969410969..ea389d6dc68 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -490,7 +490,7 @@ class Lead(models.Model): def _compute_calendar_event_count(self): if self.ids: - meeting_data = self.env['calendar.event'].sudo().read_group([ + meeting_data = self.env['calendar.event'].sudo()._read_group([ ('opportunity_id', 'in', self.ids) ], ['opportunity_id'], ['opportunity_id']) mapped_data = {m['opportunity_id'][0]: m['opportunity_id_count'] for m in meeting_data} @@ -762,7 +762,7 @@ class Lead(models.Model): # Remember date_deadline is required, we always have a value for it. Only # the earliest deadline per lead is kept. activity_asc = any('my_activity_date_deadline asc' in item for item in order_items) - my_lead_activities = self.env['mail.activity'].read_group( + my_lead_activities = self.env['mail.activity']._read_group( [('res_model', '=', self._name), ('user_id', '=', self.env.uid)], ['res_id', 'date_deadline:min'], ['res_id'], diff --git a/addons/crm/models/crm_lost_reason.py b/addons/crm/models/crm_lost_reason.py index 714a984db68..c44ab4d8745 100644 --- a/addons/crm/models/crm_lost_reason.py +++ b/addons/crm/models/crm_lost_reason.py @@ -13,7 +13,7 @@ class LostReason(models.Model): leads_count = fields.Integer('Leads Count', compute='_compute_leads_count') def _compute_leads_count(self): - lead_data = self.env['crm.lead'].with_context(active_test=False).read_group( + lead_data = self.env['crm.lead'].with_context(active_test=False)._read_group( [('lost_reason_id', 'in', self.ids)], ['lost_reason_id'], ['lost_reason_id'] diff --git a/addons/crm/models/crm_team.py b/addons/crm/models/crm_team.py index f883dba7e08..737b0f47628 100644 --- a/addons/crm/models/crm_team.py +++ b/addons/crm/models/crm_team.py @@ -70,7 +70,7 @@ class Team(models.Model): self.assignment_auto_enabled = auto_assign_enabled def _compute_lead_unassigned_count(self): - leads_data = self.env['crm.lead'].read_group([ + leads_data = self.env['crm.lead']._read_group([ ('team_id', 'in', self.ids), ('type', '=', 'lead'), ('user_id', '=', False), @@ -85,7 +85,7 @@ class Team(models.Model): team.lead_all_assigned_month_count = sum(member.lead_month_count for member in team.crm_team_member_ids) def _compute_opportunities_data(self): - opportunity_data = self.env['crm.lead'].read_group([ + opportunity_data = self.env['crm.lead']._read_group([ ('team_id', 'in', self.ids), ('probability', '<', 100), ('type', '=', 'opportunity'), @@ -97,7 +97,7 @@ class Team(models.Model): team.opportunities_amount = amounts.get(team.id, 0) def _compute_opportunities_overdue_data(self): - opportunity_data = self.env['crm.lead'].read_group([ + opportunity_data = self.env['crm.lead']._read_group([ ('team_id', 'in', self.ids), ('probability', '<', 100), ('type', '=', 'opportunity'), diff --git a/addons/crm/models/res_partner.py b/addons/crm/models/res_partner.py index a6ddbf0e568..36a7b1ef51f 100644 --- a/addons/crm/models/res_partner.py +++ b/addons/crm/models/res_partner.py @@ -39,7 +39,7 @@ class Partner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - opportunity_data = self.env['crm.lead'].with_context(active_test=False).read_group( + opportunity_data = self.env['crm.lead'].with_context(active_test=False)._read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id'] ) diff --git a/addons/crm/models/utm.py b/addons/crm/models/utm.py index 7d741a29e98..b92dcad6fe2 100644 --- a/addons/crm/models/utm.py +++ b/addons/crm/models/utm.py @@ -14,7 +14,7 @@ class UtmCampaign(models.Model): self.use_leads = self.env.user.has_group('crm.group_use_lead') def _compute_crm_lead_count(self): - lead_data = self.env['crm.lead'].with_context(active_test=False).read_group([ + lead_data = self.env['crm.lead'].with_context(active_test=False)._read_group([ ('campaign_id', 'in', self.ids)], ['campaign_id'], ['campaign_id']) mapped_data = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in lead_data} diff --git a/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py b/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py index c12be1e8ed3..5bfa68906ac 100644 --- a/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py +++ b/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py @@ -99,7 +99,7 @@ class CRMLeadMiningRequest(models.Model): @api.depends('lead_ids.lead_mining_request_id') def _compute_lead_count(self): if self.ids: - leads_data = self.env['crm.lead'].read_group( + leads_data = self.env['crm.lead']._read_group( [('lead_mining_request_id', 'in', self.ids)], ['lead_mining_request_id'], ['lead_mining_request_id']) else: diff --git a/addons/event_booth/models/event_event.py b/addons/event_booth/models/event_event.py index c9f5f8fa357..d07b9b69ae4 100644 --- a/addons/event_booth/models/event_event.py +++ b/addons/event_booth/models/event_event.py @@ -53,7 +53,7 @@ class Event(models.Model): event.event_booth_ids = command def _get_booth_stat_count(self): - elements = self.env['event.booth'].sudo().read_group( + elements = self.env['event.booth'].sudo()._read_group( [('event_id', 'in', self.ids)], ['event_id', 'state'], ['event_id', 'state'], lazy=False ) diff --git a/addons/event_booth_sale/models/sale_order.py b/addons/event_booth_sale/models/sale_order.py index 1569533272c..2cb8428f5aa 100644 --- a/addons/event_booth_sale/models/sale_order.py +++ b/addons/event_booth_sale/models/sale_order.py @@ -13,7 +13,7 @@ class SaleOrder(models.Model): @api.depends('event_booth_ids') def _compute_event_booth_count(self): if self.ids: - slot_data = self.env['event.booth'].read_group( + slot_data = self.env['event.booth']._read_group( [('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id'] ) diff --git a/addons/event_crm/models/event_event.py b/addons/event_crm/models/event_event.py index ac71958cd93..86d683eb588 100644 --- a/addons/event_crm/models/event_event.py +++ b/addons/event_crm/models/event_event.py @@ -17,7 +17,7 @@ class EventEvent(models.Model): @api.depends('lead_ids') def _compute_lead_count(self): - lead_data = self.env['crm.lead'].read_group( + lead_data = self.env['crm.lead']._read_group( [('event_id', 'in', self.ids)], ['event_id'], ['event_id'] ) diff --git a/addons/event_sale/models/event_event.py b/addons/event_sale/models/event_event.py index 5af548e193a..9ead7cb5b73 100644 --- a/addons/event_sale/models/event_event.py +++ b/addons/event_sale/models/event_event.py @@ -33,7 +33,7 @@ class Event(models.Model): date_now = fields.Datetime.now() sale_price_by_event = {} if self.ids: - event_subtotals = self.env['sale.order.line'].read_group( + event_subtotals = self.env['sale.order.line']._read_group( [('event_id', 'in', self.ids), ('price_subtotal', '!=', 0)], ['event_id', 'currency_id', 'price_subtotal:sum'], diff --git a/addons/event_sale/models/sale_order.py b/addons/event_sale/models/sale_order.py index 3919ae41b16..384f088ef69 100644 --- a/addons/event_sale/models/sale_order.py +++ b/addons/event_sale/models/sale_order.py @@ -39,7 +39,7 @@ class SaleOrder(models.Model): return action def _compute_attendee_count(self): - sale_orders_data = self.env['event.registration'].read_group( + sale_orders_data = self.env['event.registration']._read_group( [('sale_order_id', 'in', self.ids), ('state', '!=', 'cancel')], ['sale_order_id'], ['sale_order_id'] diff --git a/addons/fleet/models/fleet_vehicle_model.py b/addons/fleet/models/fleet_vehicle_model.py index 5e7c18c3be9..c3534afed9c 100644 --- a/addons/fleet/models/fleet_vehicle_model.py +++ b/addons/fleet/models/fleet_vehicle_model.py @@ -55,7 +55,7 @@ class FleetVehicleModel(models.Model): return res def _compute_vehicle_count(self): - group = self.env['fleet.vehicle'].read_group( + group = self.env['fleet.vehicle']._read_group( [('model_id', 'in', self.ids)], ['id', 'model_id'], groupby='model_id', lazy=False, ) count_by_model = {entry['model_id'][0]: entry['__count'] for entry in group} diff --git a/addons/gamification/models/gamification_karma_rank.py b/addons/gamification/models/gamification_karma_rank.py index 8e987076bfe..98b3974d03e 100644 --- a/addons/gamification/models/gamification_karma_rank.py +++ b/addons/gamification/models/gamification_karma_rank.py @@ -27,7 +27,7 @@ class KarmaRank(models.Model): @api.depends('user_ids') def _compute_rank_users_count(self): - requests_data = self.env['res.users'].read_group([('rank_id', '!=', False)], ['rank_id'], ['rank_id']) + requests_data = self.env['res.users']._read_group([('rank_id', '!=', False)], ['rank_id'], ['rank_id']) requests_mapped_data = dict((data['rank_id'][0], data['rank_id_count']) for data in requests_data) for rank in self: rank.rank_users_count = requests_mapped_data.get(rank.id, 0) diff --git a/addons/hr/models/hr_department.py b/addons/hr/models/hr_department.py index 8e8b7f688eb..747d64af354 100644 --- a/addons/hr/models/hr_department.py +++ b/addons/hr/models/hr_department.py @@ -53,7 +53,7 @@ class Department(models.Model): department.master_department_id = int(parent_path_values[department.id].split('/')[0]) def _compute_total_employee(self): - emp_data = self.env['hr.employee'].read_group([('department_id', 'in', self.ids)], ['department_id'], ['department_id']) + emp_data = self.env['hr.employee']._read_group([('department_id', 'in', self.ids)], ['department_id'], ['department_id']) result = dict((data['department_id'][0], data['department_id_count']) for data in emp_data) for department in self: department.total_employee = result.get(department.id, 0) diff --git a/addons/hr/models/hr_job.py b/addons/hr/models/hr_job.py index 5afc46c3dce..a9f0eda96a4 100644 --- a/addons/hr/models/hr_job.py +++ b/addons/hr/models/hr_job.py @@ -38,7 +38,7 @@ class Job(models.Model): @api.depends('no_of_recruitment', 'employee_ids.job_id', 'employee_ids.active') def _compute_employees(self): - employee_data = self.env['hr.employee'].read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) + employee_data = self.env['hr.employee']._read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) result = dict((data['job_id'][0], data['job_id_count']) for data in employee_data) for job in self: job.no_of_employee = result.get(job.id, 0) diff --git a/addons/hr_contract/models/hr_employee.py b/addons/hr_contract/models/hr_employee.py index b395c4dc27d..a418d375608 100644 --- a/addons/hr_contract/models/hr_employee.py +++ b/addons/hr_contract/models/hr_employee.py @@ -60,7 +60,7 @@ class Employee(models.Model): def _compute_contracts_count(self): # read_group as sudo, since contract count is displayed on form view - contract_data = self.env['hr.contract'].sudo().read_group([('employee_id', 'in', self.ids)], ['employee_id'], ['employee_id']) + contract_data = self.env['hr.contract'].sudo()._read_group([('employee_id', 'in', self.ids)], ['employee_id'], ['employee_id']) result = dict((data['employee_id'][0], data['employee_id_count']) for data in contract_data) for employee in self: employee.contracts_count = result.get(employee.id, 0) diff --git a/addons/hr_contract/models/resource.py b/addons/hr_contract/models/resource.py index ba000c4de18..52316b92636 100644 --- a/addons/hr_contract/models/resource.py +++ b/addons/hr_contract/models/resource.py @@ -29,7 +29,7 @@ class ResourceCalendar(models.Model): }) def _compute_contracts_count(self): - count_data = self.env['hr.contract'].read_group( + count_data = self.env['hr.contract']._read_group( [('resource_calendar_id', 'in', self.ids)], ['resource_calendar_id'], ['resource_calendar_id']) diff --git a/addons/hr_expense/models/hr_department.py b/addons/hr_expense/models/hr_department.py index 9bf09b2b068..85f7e8c2bf9 100644 --- a/addons/hr_expense/models/hr_department.py +++ b/addons/hr_expense/models/hr_department.py @@ -8,7 +8,7 @@ class HrDepartment(models.Model): _inherit = 'hr.department' def _compute_expense_sheets_to_approve(self): - expense_sheet_data = self.env['hr.expense.sheet'].read_group([('department_id', 'in', self.ids), ('state', '=', 'submit')], ['department_id'], ['department_id']) + expense_sheet_data = self.env['hr.expense.sheet']._read_group([('department_id', 'in', self.ids), ('state', '=', 'submit')], ['department_id'], ['department_id']) result = dict((data['department_id'][0], data['department_id_count']) for data in expense_sheet_data) for department in self: department.expense_sheets_to_approve_count = result.get(department.id, 0) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 6f767bb80bd..19bfbe7b5d8 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -212,7 +212,7 @@ class HrExpense(models.Model): expense.label_convert_rate = rate_txt def _compute_attachment_number(self): - attachment_data = self.env['ir.attachment'].read_group([('res_model', '=', 'hr.expense'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id']) + attachment_data = self.env['ir.attachment']._read_group([('res_model', '=', 'hr.expense'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id']) attachment = dict((data['res_id'], data['res_id_count']) for data in attachment_data) for expense in self: expense.attachment_number = attachment.get(expense._origin.id, 0) @@ -991,7 +991,7 @@ class HrExpenseSheet(models.Model): @api.depends('expense_line_ids') def _compute_expense_number(self): - read_group_result = self.env['hr.expense'].read_group([('sheet_id', 'in', self.ids)], ['sheet_id'], ['sheet_id']) + read_group_result = self.env['hr.expense']._read_group([('sheet_id', 'in', self.ids)], ['sheet_id'], ['sheet_id']) result = dict((data['sheet_id'][0], data['sheet_id_count']) for data in read_group_result) for sheet in self: sheet.expense_number = result.get(sheet.id, 0) diff --git a/addons/hr_fleet/models/employee.py b/addons/hr_fleet/models/employee.py index 4eafed46313..ae47a742805 100644 --- a/addons/hr_fleet/models/employee.py +++ b/addons/hr_fleet/models/employee.py @@ -28,7 +28,7 @@ class Employee(models.Model): } def _compute_employee_cars_count(self): - rg = self.env['fleet.vehicle.assignation.log'].read_group([ + rg = self.env['fleet.vehicle.assignation.log']._read_group([ ('driver_employee_id', 'in', self.ids), ], ['driver_employee_id'], ['driver_employee_id']) cars_count = {r['driver_employee_id'][0]: r['driver_employee_id_count'] for r in rg} diff --git a/addons/hr_fleet/models/fleet_vehicle_assignation_log.py b/addons/hr_fleet/models/fleet_vehicle_assignation_log.py index b67866980ab..97fe6b41a29 100644 --- a/addons/hr_fleet/models/fleet_vehicle_assignation_log.py +++ b/addons/hr_fleet/models/fleet_vehicle_assignation_log.py @@ -19,7 +19,7 @@ class FleetVehicleAssignationLog(models.Model): log.driver_employee_id = employee and employee[0] or False def _compute_attachment_number(self): - attachment_data = self.env['ir.attachment'].read_group([ + attachment_data = self.env['ir.attachment']._read_group([ ('res_model', '=', 'fleet.vehicle.assignation.log'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id']) attachment = dict((data['res_id'], data['res_id_count']) for data in attachment_data) diff --git a/addons/hr_holidays/models/hr_department.py b/addons/hr_holidays/models/hr_department.py index a6a818631cb..d3499f6cc48 100644 --- a/addons/hr_holidays/models/hr_department.py +++ b/addons/hr_holidays/models/hr_department.py @@ -25,15 +25,15 @@ class Department(models.Model): today_start = fields.Datetime.to_string(today_date) # get the midnight of the current utc day today_end = fields.Datetime.to_string(today_date + relativedelta(hours=23, minutes=59, seconds=59)) - leave_data = Requests.read_group( + leave_data = Requests._read_group( [('department_id', 'in', self.ids), ('state', '=', 'confirm')], ['department_id'], ['department_id']) - allocation_data = Allocations.read_group( + allocation_data = Allocations._read_group( [('department_id', 'in', self.ids), ('state', '=', 'confirm')], ['department_id'], ['department_id']) - absence_data = Requests.read_group( + absence_data = Requests._read_group( [('department_id', 'in', self.ids), ('state', 'not in', ['cancel', 'refuse']), ('date_from', '<=', today_end), ('date_to', '>=', today_start)], ['department_id'], ['department_id']) diff --git a/addons/hr_holidays/models/hr_employee.py b/addons/hr_holidays/models/hr_employee.py index 16b9dc985a2..d934e60a957 100644 --- a/addons/hr_holidays/models/hr_employee.py +++ b/addons/hr_holidays/models/hr_employee.py @@ -80,7 +80,7 @@ class HrEmployeeBase(models.AbstractModel): def _compute_allocation_count(self): # Don't get allocations that are expired current_date = datetime.date.today() - data = self.env['hr.leave.allocation'].read_group([ + data = self.env['hr.leave.allocation']._read_group([ ('employee_id', 'in', self.ids), ('holiday_status_id.active', '=', True), ('holiday_status_id.requires_allocation', '=', 'yes'), @@ -98,7 +98,7 @@ class HrEmployeeBase(models.AbstractModel): def _compute_allocation_remaining_display(self): current_date = datetime.date.today() - data_leave = self.env['hr.leave'].read_group([ + data_leave = self.env['hr.leave']._read_group([ ('employee_id', 'in', self.ids), ('holiday_status_id.active', '=', True), ('holiday_status_id.requires_allocation', '=', 'yes'), diff --git a/addons/hr_holidays/models/hr_leave_accrual_plan.py b/addons/hr_holidays/models/hr_leave_accrual_plan.py index de0c83cc8ac..1c1199da2f7 100644 --- a/addons/hr_holidays/models/hr_leave_accrual_plan.py +++ b/addons/hr_holidays/models/hr_leave_accrual_plan.py @@ -32,7 +32,7 @@ class AccrualPlan(models.Model): @api.depends('level_ids') def _compute_level_count(self): - level_read_group = self.env['hr.leave.accrual.level'].read_group( + level_read_group = self.env['hr.leave.accrual.level']._read_group( [('accrual_plan_id', 'in', self.ids)], fields=['accrual_plan_id'], groupby=['accrual_plan_id'], @@ -43,7 +43,7 @@ class AccrualPlan(models.Model): @api.depends('allocation_ids') def _compute_employee_count(self): - allocations_read_group = self.env['hr.leave.allocation'].read_group( + allocations_read_group = self.env['hr.leave.allocation']._read_group( [('accrual_plan_id', 'in', self.ids)], ['accrual_plan_id', 'employee_count:count_distinct(employee_id)'], ['accrual_plan_id'], diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 98bce4284c0..15872ffd283 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -361,7 +361,7 @@ class HolidaysType(models.Model): ('state', 'in', ('confirm', 'validate')), ] - grouped_res = self.env['hr.leave.allocation'].read_group( + grouped_res = self.env['hr.leave.allocation']._read_group( domain, ['holiday_status_id'], ['holiday_status_id'], @@ -379,7 +379,7 @@ class HolidaysType(models.Model): ('date_from', '<=', max_datetime), ('state', 'in', ('validate', 'validate1', 'confirm')), ] - grouped_res = self.env['hr.leave'].read_group( + grouped_res = self.env['hr.leave']._read_group( domain, ['holiday_status_id'], ['holiday_status_id'], @@ -389,7 +389,7 @@ class HolidaysType(models.Model): allocation.group_days_leave = grouped_dict.get(allocation.id, 0) def _compute_accrual_count(self): - accrual_allocations = self.env['hr.leave.accrual.plan'].read_group([('time_off_type_id', 'in', self.ids)], ['time_off_type_id'], ['time_off_type_id']) + accrual_allocations = self.env['hr.leave.accrual.plan']._read_group([('time_off_type_id', 'in', self.ids)], ['time_off_type_id'], ['time_off_type_id']) mapped_data = dict((data['time_off_type_id'][0], data['time_off_type_id_count']) for data in accrual_allocations) for leave_type in self: leave_type.accrual_count = mapped_data.get(leave_type.id, 0) diff --git a/addons/hr_recruitment/models/hr_department.py b/addons/hr_recruitment/models/hr_department.py index 66db1ca30b3..e365ac8d4b7 100644 --- a/addons/hr_recruitment/models/hr_department.py +++ b/addons/hr_recruitment/models/hr_department.py @@ -14,7 +14,7 @@ class HrDepartment(models.Model): compute='_compute_recruitment_stats', string='Expected Employee') def _compute_new_applicant_count(self): - applicant_data = self.env['hr.applicant'].read_group( + applicant_data = self.env['hr.applicant']._read_group( [('department_id', 'in', self.ids), ('stage_id.sequence', '<=', '1')], ['department_id'], ['department_id']) result = dict((data['department_id'][0], data['department_id_count']) for data in applicant_data) @@ -22,7 +22,7 @@ class HrDepartment(models.Model): department.new_applicant_count = result.get(department.id, 0) def _compute_recruitment_stats(self): - job_data = self.env['hr.job'].read_group( + job_data = self.env['hr.job']._read_group( [('department_id', 'in', self.ids)], ['no_of_hired_employee', 'no_of_recruitment', 'department_id'], ['department_id']) new_emp = dict((data['department_id'][0], data['no_of_hired_employee']) for data in job_data) diff --git a/addons/hr_recruitment/models/hr_job.py b/addons/hr_recruitment/models/hr_job.py index 6f7e0258eda..f308ac69656 100644 --- a/addons/hr_recruitment/models/hr_job.py +++ b/addons/hr_recruitment/models/hr_job.py @@ -85,13 +85,13 @@ class Job(models.Model): job.documents_count = len(job.document_ids) def _compute_all_application_count(self): - read_group_result = self.env['hr.applicant'].with_context(active_test=False).read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) + read_group_result = self.env['hr.applicant'].with_context(active_test=False)._read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) result = dict((data['job_id'][0], data['job_id_count']) for data in read_group_result) for job in self: job.all_application_count = result.get(job.id, 0) def _compute_application_count(self): - read_group_result = self.env['hr.applicant'].read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) + read_group_result = self.env['hr.applicant']._read_group([('job_id', 'in', self.ids)], ['job_id'], ['job_id']) result = dict((data['job_id'][0], data['job_id_count']) for data in read_group_result) for job in self: job.application_count = result.get(job.id, 0) diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index 94bd7da2624..77f2156dd00 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -85,7 +85,7 @@ class RecruitmentStage(models.Model): @api.depends('hired_stage') def _compute_is_warning_visible(self): - applicant_data = self.env['hr.applicant'].read_group([('stage_id', 'in', self.ids)], ['stage_id'], 'stage_id') + applicant_data = self.env['hr.applicant']._read_group([('stage_id', 'in', self.ids)], ['stage_id'], 'stage_id') applicants = dict((data['stage_id'][0], data['stage_id_count']) for data in applicant_data) for stage in self: if stage._origin.hired_stage and not stage.hired_stage and applicants.get(stage._origin.id): @@ -257,7 +257,7 @@ class Applicant(models.Model): applicant.meeting_display_text = _('Last Meeting') def _get_attachment_number(self): - read_group_res = self.env['ir.attachment'].read_group( + read_group_res = self.env['ir.attachment']._read_group( [('res_model', '=', 'hr.applicant'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id']) attach_data = dict((res['res_id'], res['res_id_count']) for res in read_group_res) diff --git a/addons/hr_recruitment/models/res_users.py b/addons/hr_recruitment/models/res_users.py index 9d7e83a17f5..77b1ae5cd2b 100644 --- a/addons/hr_recruitment/models/res_users.py +++ b/addons/hr_recruitment/models/res_users.py @@ -24,10 +24,10 @@ class ResUsers(models.Model): interviewer_group = self.env.ref('hr_recruitment.group_hr_recruitment_interviewer') recruitment_group = self.env.ref('hr_recruitment.group_hr_recruitment_user') - job_interviewers = self.env['hr.job'].read_group([('interviewer_ids', 'in', self.ids)], ['interviewer_ids'], ['interviewer_ids']) + job_interviewers = self.env['hr.job']._read_group([('interviewer_ids', 'in', self.ids)], ['interviewer_ids'], ['interviewer_ids']) user_ids = {j['interviewer_ids'][0] for j in job_interviewers} - application_interviewers = self.env['hr.applicant'].read_group([('interviewer_id', 'in', self.ids)], ['interviewer_id'], ['interviewer_id']) + application_interviewers = self.env['hr.applicant']._read_group([('interviewer_id', 'in', self.ids)], ['interviewer_id'], ['interviewer_id']) user_ids |= {a['interviewer_id'][0] for a in application_interviewers} # Remove users that are no longer interviewers on at least a job or an application diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 1a98c0ff9ef..4fc74ac6db4 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -83,7 +83,7 @@ class Project(models.Model): @api.depends('allow_timesheets', 'task_ids.planned_hours', 'task_ids.remaining_hours') def _compute_remaining_hours(self): - group_read = self.env['project.task'].read_group( + group_read = self.env['project.task']._read_group( domain=[('planned_hours', '!=', False), ('project_id', 'in', self.filtered('allow_timesheets').ids), '|', ('stage_id.fold', '=', False), ('stage_id', '=', False)], fields=['planned_hours:sum', 'remaining_hours:sum'], groupby='project_id') @@ -152,7 +152,7 @@ class Project(models.Model): @api.depends('timesheet_ids') def _compute_timesheet_count(self): - timesheet_read_group = self.env['account.analytic.line'].read_group( + timesheet_read_group = self.env['account.analytic.line']._read_group( [('project_id', 'in', self.ids)], ['project_id'], ['project_id'] diff --git a/addons/hr_work_entry_holidays/models/hr_leave.py b/addons/hr_work_entry_holidays/models/hr_leave.py index 3545c1d62b6..c0bfeb9ead8 100644 --- a/addons/hr_work_entry_holidays/models/hr_leave.py +++ b/addons/hr_work_entry_holidays/models/hr_leave.py @@ -108,7 +108,7 @@ class HrLeave(models.Model): # 2. Fetch overlapping work entries, grouped by employees start = min(self.mapped('date_from'), default=False) stop = max(self.mapped('date_to'), default=False) - work_entry_groups = self.env['hr.work.entry'].read_group([ + work_entry_groups = self.env['hr.work.entry']._read_group([ ('date_start', '<', stop), ('date_stop', '>', start), ('employee_id', 'in', self.employee_id.ids), diff --git a/addons/im_livechat/models/digest.py b/addons/im_livechat/models/digest.py index cfd7ed0863b..830178b382b 100644 --- a/addons/im_livechat/models/digest.py +++ b/addons/im_livechat/models/digest.py @@ -37,7 +37,7 @@ class Digest(models.Model): def _compute_kpi_livechat_response_value(self): for record in self: start, end, company = record._get_kpi_compute_parameters() - response_time = self.env['im_livechat.report.operator'].sudo().read_group([ + response_time = self.env['im_livechat.report.operator'].sudo()._read_group([ ('start_date', '>=', start), ('start_date', '<', end), ('partner_id', '=', self.env.user.partner_id.id)], ['partner_id', 'time_to_answer'], ['partner_id']) record.kpi_livechat_response_value = "%.2f" % sum([response['time_to_answer'] for response in response_time]) or 0 diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index fc1be753f39..fc62349114f 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -73,7 +73,7 @@ class ImLivechatChannel(models.Model): @api.depends('channel_ids') def _compute_nbr_channel(self): - data = self.env['mail.channel'].read_group([ + data = self.env['mail.channel']._read_group([ ('livechat_channel_id', 'in', self._ids), ('has_message', '=', True)], ['__count'], ['livechat_channel_id'], lazy=False) channel_count = {x['livechat_channel_id'][0]: x['__count'] for x in data} diff --git a/addons/link_tracker/models/link_tracker.py b/addons/link_tracker/models/link_tracker.py index b662077c37e..6b7cf27e88c 100644 --- a/addons/link_tracker/models/link_tracker.py +++ b/addons/link_tracker/models/link_tracker.py @@ -59,7 +59,7 @@ class LinkTracker(models.Model): @api.depends('link_click_ids.link_id') def _compute_count(self): if self.ids: - clicks_data = self.env['link.tracker.click'].read_group( + clicks_data = self.env['link.tracker.click']._read_group( [('link_id', 'in', self.ids)], ['link_id'], ['link_id'] diff --git a/addons/link_tracker/models/utm.py b/addons/link_tracker/models/utm.py index 75eff850150..1e7ccb50e02 100644 --- a/addons/link_tracker/models/utm.py +++ b/addons/link_tracker/models/utm.py @@ -11,7 +11,7 @@ class UtmCampaign(models.Model): click_count = fields.Integer(string="Number of clicks generated by the campaign", compute="_compute_clicks_count") def _compute_clicks_count(self): - click_data = self.env['link.tracker.click'].read_group( + click_data = self.env['link.tracker.click']._read_group( [('campaign_id', 'in', self.ids)], ['campaign_id'], ['campaign_id']) diff --git a/addons/lunch/models/lunch_product_category.py b/addons/lunch/models/lunch_product_category.py index 4a40cfb6307..bf204ece3c8 100644 --- a/addons/lunch/models/lunch_product_category.py +++ b/addons/lunch/models/lunch_product_category.py @@ -27,7 +27,7 @@ class LunchProductCategory(models.Model): image_1920 = fields.Image(default=_default_image) def _compute_product_count(self): - product_data = self.env['lunch.product'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) + product_data = self.env['lunch.product']._read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) data = {product['category_id'][0]: product['category_id_count'] for product in product_data} for category in self: category.product_count = data.get(category.id, 0) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index b5375e16fd3..88359753dd7 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -163,7 +163,7 @@ class Channel(models.Model): @api.depends('channel_partner_ids') def _compute_member_count(self): - read_group_res = self.env['mail.channel.partner'].read_group(domain=[('channel_id', 'in', self.ids)], fields=['channel_id'], groupby=['channel_id']) + read_group_res = self.env['mail.channel.partner']._read_group(domain=[('channel_id', 'in', self.ids)], fields=['channel_id'], groupby=['channel_id']) member_count_by_channel_id = {item['channel_id'][0]: item['channel_id_count'] for item in read_group_res} for channel in self: channel.member_count = member_count_by_channel_id.get(channel.id, 0) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 54fb13ad08f..7b82d1006bf 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -244,7 +244,7 @@ class MailThread(models.AbstractModel): return [('message_ids', 'in', message_ids)] def _compute_message_attachment_count(self): - read_group_var = self.env['ir.attachment'].read_group([('res_id', 'in', self.ids), ('res_model', '=', self._name)], + read_group_var = self.env['ir.attachment']._read_group([('res_id', 'in', self.ids), ('res_model', '=', self._name)], fields=['res_id'], groupby=['res_id']) diff --git a/addons/mail_group/models/mail_group.py b/addons/mail_group/models/mail_group.py index 7cbfa2cc1e1..1ea25039741 100644 --- a/addons/mail_group/models/mail_group.py +++ b/addons/mail_group/models/mail_group.py @@ -94,7 +94,7 @@ class MailGroup(models.Model): @api.depends('mail_group_message_ids.create_date', 'mail_group_message_ids.moderation_status') def _compute_mail_group_message_last_month_count(self): month_date = datetime.today() - relativedelta.relativedelta(months=1) - messages_data = self.env['mail.group.message'].read_group([ + messages_data = self.env['mail.group.message']._read_group([ ('mail_group_id', 'in', self.ids), ('create_date', '>=', fields.Datetime.to_string(month_date)), ('moderation_status', '=', 'accepted'), @@ -115,7 +115,7 @@ class MailGroup(models.Model): self.mail_group_message_count = 0 return - results = self.env['mail.group.message'].read_group( + results = self.env['mail.group.message']._read_group( [('mail_group_id', 'in', self.ids)], ['mail_group_id'], ['mail_group_id'], @@ -129,7 +129,7 @@ class MailGroup(models.Model): @api.depends('mail_group_message_ids.moderation_status') def _compute_mail_group_message_moderation_count(self): - results = self.env['mail.group.message'].read_group( + results = self.env['mail.group.message']._read_group( [('mail_group_id', 'in', self.ids), ('moderation_status', '=', 'pending_moderation')], ['mail_group_id'], ['mail_group_id'], diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index 003d7a5a2ca..9c7e8504d89 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -52,13 +52,13 @@ class MaintenanceEquipmentCategory(models.Model): fold = fields.Boolean(string='Folded in Maintenance Pipe', compute='_compute_fold', store=True) def _compute_equipment_count(self): - equipment_data = self.env['maintenance.equipment'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) + equipment_data = self.env['maintenance.equipment']._read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) mapped_data = dict([(m['category_id'][0], m['category_id_count']) for m in equipment_data]) for category in self: category.equipment_count = mapped_data.get(category.id, 0) def _compute_maintenance_count(self): - maintenance_data = self.env['maintenance.request'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) + maintenance_data = self.env['maintenance.request']._read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) mapped_data = dict([(m['category_id'][0], m['category_id_count']) for m in maintenance_data]) for category in self: category.maintenance_count = mapped_data.get(category.id, 0) diff --git a/addons/mass_mailing/models/utm_campaign.py b/addons/mass_mailing/models/utm_campaign.py index fefce0add5c..7913cc44bdc 100644 --- a/addons/mass_mailing/models/utm_campaign.py +++ b/addons/mass_mailing/models/utm_campaign.py @@ -50,7 +50,7 @@ class UtmCampaign(models.Model): @api.depends('mailing_mail_ids') def _compute_mailing_mail_count(self): if self.ids: - mailing_data = self.env['mailing.mailing'].read_group( + mailing_data = self.env['mailing.mailing']._read_group( [('campaign_id', 'in', self.ids), ('mailing_type', '=', 'mail')], ['campaign_id', 'ab_testing_enabled'], ['campaign_id', 'ab_testing_enabled'], diff --git a/addons/mass_mailing_crm/models/mailing_mailing.py b/addons/mass_mailing_crm/models/mailing_mailing.py index a2796d529f4..d156ec34fc6 100644 --- a/addons/mass_mailing_crm/models/mailing_mailing.py +++ b/addons/mass_mailing_crm/models/mailing_mailing.py @@ -16,7 +16,7 @@ class MassMailing(models.Model): self.use_leads = self.env.user.has_group('crm.group_use_lead') def _compute_crm_lead_count(self): - lead_data = self.env['crm.lead'].with_context(active_test=False).sudo().read_group( + lead_data = self.env['crm.lead'].with_context(active_test=False).sudo()._read_group( [('source_id', 'in', self.source_id.ids)], ['source_id'], ['source_id'], ) diff --git a/addons/mass_mailing_sale/models/mailing_mailing.py b/addons/mass_mailing_sale/models/mailing_mailing.py index 40e6091a98a..09ee25e4626 100644 --- a/addons/mass_mailing_sale/models/mailing_mailing.py +++ b/addons/mass_mailing_sale/models/mailing_mailing.py @@ -15,7 +15,7 @@ class MassMailing(models.Model): @api.depends('mailing_domain') def _compute_sale_quotation_count(self): - quotation_data = self.env['sale.order'].sudo().read_group( + quotation_data = self.env['sale.order'].sudo()._read_group( [('source_id', 'in', self.source_id.ids)], ['source_id'], ['source_id'], ) @@ -29,7 +29,7 @@ class MassMailing(models.Model): [('source_id', 'in', self.source_id.ids)], [('state', 'not in', ['draft', 'cancel'])] ]) - moves_data = self.env['account.move'].sudo().read_group( + moves_data = self.env['account.move'].sudo()._read_group( domain, ['source_id', 'amount_untaxed_signed'], ['source_id'], ) mapped_data = {datum['source_id'][0]: datum['amount_untaxed_signed'] for datum in moves_data} diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 245f3f7b2b5..1ed1f207d9d 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -341,7 +341,7 @@ class MrpProduction(models.Model): @api.depends('move_raw_ids.delay_alert_date') def _compute_delay_alert_date(self): - delay_alert_date_data = self.env['stock.move'].read_group([('id', 'in', self.move_raw_ids.ids), ('delay_alert_date', '!=', False)], ['delay_alert_date:max'], 'raw_material_production_id') + delay_alert_date_data = self.env['stock.move']._read_group([('id', 'in', self.move_raw_ids.ids), ('delay_alert_date', '!=', False)], ['delay_alert_date:max'], 'raw_material_production_id') delay_alert_date_data = {data['raw_material_production_id'][0]: data['delay_alert_date'] for data in delay_alert_date_data} for production in self: production.delay_alert_date = delay_alert_date_data.get(production.id, False) @@ -421,7 +421,7 @@ class MrpProduction(models.Model): def _compute_production_location(self): if not self.company_id: return - location_by_company = self.env['stock.location'].read_group([ + location_by_company = self.env['stock.location']._read_group([ ('company_id', 'in', self.company_id.ids), ('usage', '=', 'production') ], ['company_id', 'ids:array_agg(id)'], ['company_id']) @@ -511,7 +511,7 @@ class MrpProduction(models.Model): return True def _compute_scrap_move_count(self): - data = self.env['stock.scrap'].read_group([('production_id', 'in', self.ids)], ['production_id'], ['production_id']) + data = self.env['stock.scrap']._read_group([('production_id', 'in', self.ids)], ['production_id'], ['production_id']) count_data = dict((item['production_id'][0], item['production_id_count']) for item in data) for production in self: production.scrap_count = count_data.get(production.id, 0) diff --git a/addons/mrp/models/mrp_routing.py b/addons/mrp/models/mrp_routing.py index c105ff91a66..157a6066ca1 100644 --- a/addons/mrp/models/mrp_routing.py +++ b/addons/mrp/models/mrp_routing.py @@ -82,7 +82,7 @@ class MrpRoutingWorkcenter(models.Model): operation.time_cycle = operation.time_cycle_manual def _compute_workorder_count(self): - data = self.env['mrp.workorder'].read_group([ + data = self.env['mrp.workorder']._read_group([ ('operation_id', 'in', self.ids), ('state', '=', 'done')], ['operation_id'], ['operation_id']) count_data = dict((item['operation_id'][0], item['operation_id_count']) for item in data) diff --git a/addons/mrp/models/mrp_workcenter.py b/addons/mrp/models/mrp_workcenter.py index 3dcf86f53dc..fa7cbff0ec6 100644 --- a/addons/mrp/models/mrp_workcenter.py +++ b/addons/mrp/models/mrp_workcenter.py @@ -86,12 +86,12 @@ class MrpWorkcenter(models.Model): result = {wid: {} for wid in self._ids} result_duration_expected = {wid: 0 for wid in self._ids} # Count Late Workorder - data = MrpWorkorder.read_group( + data = MrpWorkorder._read_group( [('workcenter_id', 'in', self.ids), ('state', 'in', ('pending', 'waiting', 'ready')), ('date_planned_start', '<', datetime.datetime.now().strftime('%Y-%m-%d'))], ['workcenter_id'], ['workcenter_id']) count_data = dict((item['workcenter_id'][0], item['workcenter_id_count']) for item in data) # Count All, Pending, Ready, Progress Workorder - res = MrpWorkorder.read_group( + res = MrpWorkorder._read_group( [('workcenter_id', 'in', self.ids)], ['workcenter_id', 'state', 'duration_expected'], ['workcenter_id', 'state'], lazy=False) @@ -129,7 +129,7 @@ class MrpWorkcenter(models.Model): def _compute_blocked_time(self): # TDE FIXME: productivity loss type should be only losses, probably count other time logs differently ?? - data = self.env['mrp.workcenter.productivity'].read_group([ + data = self.env['mrp.workcenter.productivity']._read_group([ ('date_start', '>=', fields.Datetime.to_string(datetime.datetime.now() - relativedelta.relativedelta(months=1))), ('workcenter_id', 'in', self.ids), ('date_end', '!=', False), @@ -141,7 +141,7 @@ class MrpWorkcenter(models.Model): def _compute_productive_time(self): # TDE FIXME: productivity loss type should be only losses, probably count other time logs differently - data = self.env['mrp.workcenter.productivity'].read_group([ + data = self.env['mrp.workcenter.productivity']._read_group([ ('date_start', '>=', fields.Datetime.to_string(datetime.datetime.now() - relativedelta.relativedelta(months=1))), ('workcenter_id', 'in', self.ids), ('date_end', '!=', False), @@ -160,7 +160,7 @@ class MrpWorkcenter(models.Model): order.oee = 0.0 def _compute_performance(self): - wo_data = self.env['mrp.workorder'].read_group([ + wo_data = self.env['mrp.workorder']._read_group([ ('date_start', '>=', fields.Datetime.to_string(datetime.datetime.now() - relativedelta.relativedelta(months=1))), ('workcenter_id', 'in', self.ids), ('state', '=', 'done')], ['duration_expected', 'workcenter_id', 'duration'], ['workcenter_id'], lazy=False) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index a247a32edc0..003a189de0c 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -375,7 +375,7 @@ class MrpWorkorder(models.Model): order.is_user_working = False def _compute_scrap_move_count(self): - data = self.env['stock.scrap'].read_group([('workorder_id', 'in', self.ids)], ['workorder_id'], ['workorder_id']) + data = self.env['stock.scrap']._read_group([('workorder_id', 'in', self.ids)], ['workorder_id'], ['workorder_id']) count_data = dict((item['workorder_id'][0], item['workorder_id_count']) for item in data) for workorder in self: workorder.scrap_count = count_data.get(workorder.id, 0) diff --git a/addons/mrp/models/product.py b/addons/mrp/models/product.py index 4ecb8d0a52c..3aec1df2259 100644 --- a/addons/mrp/models/product.py +++ b/addons/mrp/models/product.py @@ -146,7 +146,7 @@ class ProductProduct(models.Model): date_from = fields.Datetime.to_string(fields.datetime.now() - timedelta(days=365)) #TODO: state = done? domain = [('state', '=', 'done'), ('product_id', 'in', self.ids), ('date_planned_start', '>', date_from)] - read_group_res = self.env['mrp.production'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']) + read_group_res = self.env['mrp.production']._read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']) mapped_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in read_group_res]) for product in self: if not product.id: diff --git a/addons/mrp/models/stock_picking.py b/addons/mrp/models/stock_picking.py index b6e125a014f..1ae50bc0787 100644 --- a/addons/mrp/models/stock_picking.py +++ b/addons/mrp/models/stock_picking.py @@ -35,7 +35,7 @@ class StockPickingType(models.Model): 'count_mo_late': [('date_planned_start', '<', fields.Date.today()), ('state', '=', 'confirmed')], } for field in domains: - data = self.env['mrp.production'].read_group(domains[field] + + data = self.env['mrp.production']._read_group(domains[field] + [('state', 'not in', ('done', 'cancel')), ('picking_type_id', 'in', self.ids)], ['picking_type_id'], ['picking_type_id']) count = {x['picking_type_id'] and x['picking_type_id'][0]: x['picking_type_id_count'] for x in data} diff --git a/addons/payment/models/account_payment.py b/addons/payment/models/account_payment.py index 94b08289b01..678c8f4bd1e 100644 --- a/addons/payment/models/account_payment.py +++ b/addons/payment/models/account_payment.py @@ -83,7 +83,7 @@ class AccountPayment(models.Model): payment.use_electronic_payment_method = payment.payment_method_code in codes def _compute_refunds_count(self): - rg_data = self.env['account.payment'].read_group( + rg_data = self.env['account.payment']._read_group( domain=[ ('source_payment_id', 'in', self.ids), ('payment_transaction_id.operation', '=', 'refund') diff --git a/addons/payment/models/payment_transaction.py b/addons/payment/models/payment_transaction.py index 8280ba71a4c..c1aa6cdb622 100644 --- a/addons/payment/models/payment_transaction.py +++ b/addons/payment/models/payment_transaction.py @@ -144,7 +144,7 @@ class PaymentTransaction(models.Model): tx.invoices_count = tx_data.get(tx.id, 0) def _compute_refunds_count(self): - rg_data = self.env['payment.transaction'].read_group( + rg_data = self.env['payment.transaction']._read_group( domain=[('source_transaction_id', 'in', self.ids), ('operation', '=', 'refund')], fields=['source_transaction_id'], groupby=['source_transaction_id'], diff --git a/addons/payment/models/res_partner.py b/addons/payment/models/res_partner.py index 4a9af3c1ce9..f58d74d618a 100644 --- a/addons/payment/models/res_partner.py +++ b/addons/payment/models/res_partner.py @@ -13,7 +13,7 @@ class ResPartner(models.Model): @api.depends('payment_token_ids') def _compute_payment_token_count(self): - payments_data = self.env['payment.token'].read_group( + payments_data = self.env['payment.token']._read_group( [('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id'] ) partners_data = {payment_data['partner_id'][0]: payment_data['partner_id_count'] diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 8c97abeb5f9..396265e7334 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -116,7 +116,7 @@ class PosSession(models.Model): cash_payment_method = session.payment_method_ids.filtered('is_cash_count')[:1] if cash_payment_method: total_cash_payment = 0.0 - result = self.env['pos.payment'].read_group([('session_id', '=', session.id), ('payment_method_id', '=', cash_payment_method.id)], ['amount'], ['session_id']) + result = self.env['pos.payment']._read_group([('session_id', '=', session.id), ('payment_method_id', '=', cash_payment_method.id)], ['amount'], ['session_id']) if result: total_cash_payment = result[0]['amount'] session.cash_register_total_entry_encoding = session.cash_register_id.total_entry_encoding + ( @@ -131,13 +131,13 @@ class PosSession(models.Model): @api.depends('order_ids.payment_ids.amount') def _compute_total_payments_amount(self): - result = self.env['pos.payment'].read_group([('session_id', 'in', self.ids)], ['amount'], ['session_id']) + result = self.env['pos.payment']._read_group([('session_id', 'in', self.ids)], ['amount'], ['session_id']) session_amount_map = dict((data['session_id'][0], data['amount']) for data in result) for session in self: session.total_payments_amount = session_amount_map.get(session.id) or 0 def _compute_order_count(self): - orders_data = self.env['pos.order'].read_group([('session_id', 'in', self.ids)], ['session_id'], ['session_id']) + orders_data = self.env['pos.order']._read_group([('session_id', 'in', self.ids)], ['session_id'], ['session_id']) sessions_data = {order_data['session_id'][0]: order_data['session_id_count'] for order_data in orders_data} for session in self: session.order_count = sessions_data.get(session.id, 0) diff --git a/addons/point_of_sale/models/res_partner.py b/addons/point_of_sale/models/res_partner.py index 39917239744..1539a35e461 100644 --- a/addons/point_of_sale/models/res_partner.py +++ b/addons/point_of_sale/models/res_partner.py @@ -19,7 +19,7 @@ class ResPartner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - pos_order_data = self.env['pos.order'].read_group( + pos_order_data = self.env['pos.order']._read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id'] ) diff --git a/addons/pos_sale/models/crm_team.py b/addons/pos_sale/models/crm_team.py index 7e2659e891c..8ffd32d0b2e 100644 --- a/addons/pos_sale/models/crm_team.py +++ b/addons/pos_sale/models/crm_team.py @@ -19,7 +19,7 @@ class CrmTeam(models.Model): team.pos_sessions_open_count = self.env['pos.session'].search_count([('config_id.crm_team_id', '=', team.id), ('state', '=', 'opened')]) def _compute_pos_order_amount_total(self): - data = self.env['report.pos.order'].read_group([ + data = self.env['report.pos.order']._read_group([ ('session_id.state', '=', 'opened'), ('config_id.crm_team_id', 'in', self.ids), ], ['price_total:sum', 'config_id'], ['config_id']) diff --git a/addons/project/models/analytic_account.py b/addons/project/models/analytic_account.py index fe103d3f7c2..97df4a95770 100644 --- a/addons/project/models/analytic_account.py +++ b/addons/project/models/analytic_account.py @@ -14,7 +14,7 @@ class AccountAnalyticAccount(models.Model): @api.depends('project_ids') def _compute_project_count(self): - project_data = self.env['project.project'].read_group([('analytic_account_id', 'in', self.ids)], ['analytic_account_id'], ['analytic_account_id']) + project_data = self.env['project.project']._read_group([('analytic_account_id', 'in', self.ids)], ['analytic_account_id'], ['analytic_account_id']) mapping = {m['analytic_account_id'][0]: m['analytic_account_id_count'] for m in project_data} for account in self: account.project_count = mapping.get(account.id, 0) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 328f1779bdc..2b4804a67e2 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -109,7 +109,7 @@ class ProjectTaskType(models.Model): self = self.with_context(active_test=False) # retrieves all the projects with a least 1 task in that stage # a task can be in a stage even if the project is not assigned to the stage - readgroup = self.with_context(active_test=False).env['project.task'].read_group([('stage_id', 'in', self.ids)], ['project_id'], ['project_id']) + readgroup = self.with_context(active_test=False).env['project.task']._read_group([('stage_id', 'in', self.ids)], ['project_id'], ['project_id']) project_ids = list(set([project['project_id'][0] for project in readgroup] + self.project_ids.ids)) wizard = self.with_context(project_ids=project_ids).env['project.task.type.delete.wizard'].create({ @@ -187,7 +187,7 @@ class Project(models.Model): project.doc_count = docs_count.get(project.id, 0) def _compute_task_count(self): - task_data = self.env['project.task'].read_group( + task_data = self.env['project.task']._read_group( [('project_id', 'in', self.ids), '|', ('stage_id.fold', '=', False), @@ -401,7 +401,7 @@ class Project(models.Model): @api.depends('milestone_ids') def _compute_milestone_count(self): - read_group = self.env['project.milestone'].read_group([('project_id', 'in', self.ids)], ['project_id'], ['project_id']) + read_group = self.env['project.milestone']._read_group([('project_id', 'in', self.ids)], ['project_id'], ['project_id']) mapped_count = {group['project_id'][0]: group['project_id_count'] for group in read_group} for project in self: project.milestone_count = mapped_count.get(project.id, 0) @@ -409,7 +409,7 @@ class Project(models.Model): @api.depends('milestone_ids', 'milestone_ids.is_reached', 'milestone_ids.deadline') def _compute_is_milestone_exceeded(self): today = fields.Date.context_today(self) - read_group = self.env['project.milestone'].read_group([ + read_group = self.env['project.milestone']._read_group([ ('project_id', 'in', self.ids), ('is_reached', '=', False), ('deadline', '<', today)], ['project_id'], ['project_id']) @@ -448,7 +448,7 @@ class Project(models.Model): @api.depends('collaborator_ids', 'privacy_visibility') def _compute_collaborator_count(self): project_sharings = self.filtered(lambda project: project.privacy_visibility == 'portal') - collaborator_read_group = self.env['project.collaborator'].read_group( + collaborator_read_group = self.env['project.collaborator']._read_group( [('project_id', 'in', project_sharings.ids)], ['project_id'], ['project_id'], @@ -548,7 +548,7 @@ class Project(models.Model): if vals.get('privacy_visibility'): self._change_privacy_visibility() if 'name' in vals and self.analytic_account_id: - projects_read_group = self.env['project.project'].read_group( + projects_read_group = self.env['project.project']._read_group( [('analytic_account_id', 'in', self.analytic_account_id.ids)], ['analytic_account_id'], ['analytic_account_id'] @@ -1306,7 +1306,7 @@ class Task(models.Model): def _compute_recurring_count(self): self.recurring_count = 0 recurring_tasks = self.filtered(lambda l: l.recurrence_id) - count = self.env['project.task'].read_group([('recurrence_id', 'in', recurring_tasks.recurrence_id.ids)], ['id'], 'recurrence_id') + count = self.env['project.task']._read_group([('recurrence_id', 'in', recurring_tasks.recurrence_id.ids)], ['id'], 'recurrence_id') tasks_count = {c.get('recurrence_id')[0]: c.get('recurrence_id_count') for c in count} for task in recurring_tasks: task.recurring_count = tasks_count.get(task.recurrence_id.id, 0) @@ -1316,7 +1316,7 @@ class Task(models.Model): tasks_with_dependency = self.filtered('allow_task_dependencies') (self - tasks_with_dependency).dependent_tasks_count = 0 if tasks_with_dependency: - group_dependent = self.env['project.task'].read_group([ + group_dependent = self.env['project.task']._read_group([ ('depend_on_ids', 'in', tasks_with_dependency.ids), ], ['depend_on_ids'], ['depend_on_ids']) dependent_tasks_count_dict = { diff --git a/addons/project/models/res_partner.py b/addons/project/models/res_partner.py index 9e2be59d16b..26998e10827 100644 --- a/addons/project/models/res_partner.py +++ b/addons/project/models/res_partner.py @@ -17,7 +17,7 @@ class ResPartner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - task_data = self.env['project.task'].read_group( + task_data = self.env['project.task']._read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id'] ) diff --git a/addons/project_hr_expense/models/project.py b/addons/project_hr_expense/models/project.py index 3a9b2fe9a54..3968877af7e 100644 --- a/addons/project_hr_expense/models/project.py +++ b/addons/project_hr_expense/models/project.py @@ -10,7 +10,7 @@ class Project(models.Model): @api.depends('analytic_account_id') def _compute_expenses_count(self): - expenses_data = self.env['hr.expense'].read_group([ + expenses_data = self.env['hr.expense']._read_group([ ('analytic_account_id', '!=', False), ('analytic_account_id', 'in', self.analytic_account_id.ids) ], diff --git a/addons/project_purchase/models/project.py b/addons/project_purchase/models/project.py index bda605ab325..0fa33167953 100644 --- a/addons/project_purchase/models/project.py +++ b/addons/project_purchase/models/project.py @@ -11,7 +11,7 @@ class Project(models.Model): @api.depends('analytic_account_id') def _compute_purchase_orders_count(self): - purchase_orders_data = self.env['purchase.order.line'].read_group([ + purchase_orders_data = self.env['purchase.order.line']._read_group([ ('account_analytic_id', '!=', False), ('account_analytic_id', 'in', self.analytic_account_id.ids) ], ['account_analytic_id', 'order_id:count_distinct'], ['account_analytic_id']) diff --git a/addons/project_timesheet_holidays/models/resource_calendar_leaves.py b/addons/project_timesheet_holidays/models/resource_calendar_leaves.py index 61e2f6feac4..90bef97cfcd 100644 --- a/addons/project_timesheet_holidays/models/resource_calendar_leaves.py +++ b/addons/project_timesheet_holidays/models/resource_calendar_leaves.py @@ -32,7 +32,7 @@ class ResourceCalendarLeaves(models.Model): } } """ - leaves_read_group = self.env['resource.calendar.leaves'].read_group( + leaves_read_group = self.env['resource.calendar.leaves']._read_group( [('id', 'in', self.ids)], ['calendar_id', 'ids:array_agg(id)', 'resource_ids:array_agg(resource_id)', 'min_date_from:min(date_from)', 'max_date_to:max(date_to)'], ['calendar_id'], @@ -79,7 +79,7 @@ class ResourceCalendarLeaves(models.Model): If the employee has already a time off in the same day then no timesheet should be created. """ work_hours_data = self._work_time_per_day() - employees_groups = self.env['hr.employee'].read_group( + employees_groups = self.env['hr.employee']._read_group( [('resource_calendar_id', 'in', self.calendar_id.ids)], ['resource_calendar_id', 'ids:array_agg(id)'], ['resource_calendar_id']) @@ -99,7 +99,7 @@ class ResourceCalendarLeaves(models.Model): elif d > max_date: max_date = d - holidays_read_group = self.env['hr.leave'].read_group([ + holidays_read_group = self.env['hr.leave']._read_group([ ('employee_id', 'in', list(employee_ids_set)), ('date_from', '<=', max_date), ('date_to', '>=', min_date), diff --git a/addons/purchase/models/product.py b/addons/purchase/models/product.py index ad0d4196ecd..60409ec2a3c 100644 --- a/addons/purchase/models/product.py +++ b/addons/purchase/models/product.py @@ -61,7 +61,7 @@ class ProductProduct(models.Model): ('product_id', 'in', self.ids), ('order_id.date_approve', '>=', date_from) ] - order_lines = self.env['purchase.order.line'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']) + order_lines = self.env['purchase.order.line']._read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']) purchased_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in order_lines]) for product in self: if not product.id: diff --git a/addons/purchase/models/res_partner.py b/addons/purchase/models/res_partner.py index 8267e5a5255..355b8c93e01 100644 --- a/addons/purchase/models/res_partner.py +++ b/addons/purchase/models/res_partner.py @@ -14,7 +14,7 @@ class res_partner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - purchase_order_groups = self.env['purchase.order'].read_group( + purchase_order_groups = self.env['purchase.order']._read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id'] ) @@ -33,7 +33,7 @@ class res_partner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - supplier_invoice_groups = self.env['account.move'].read_group( + supplier_invoice_groups = self.env['account.move']._read_group( domain=[('partner_id', 'in', all_partners.ids), ('move_type', 'in', ('in_invoice', 'in_refund'))], fields=['partner_id'], groupby=['partner_id'] diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py index 3018e28762b..ecc661f376b 100644 --- a/addons/rating/models/rating_mixin.py +++ b/addons/rating/models/rating_mixin.py @@ -65,7 +65,7 @@ class RatingMixin(models.AbstractModel): since the query is different, to avoid computing if it is not necessary""" domain = expression.AND([self._rating_domain(), [('rating', '>=', rating_data.RATING_LIMIT_MIN)]]) # See `_compute_rating_percentage_satisfaction` above - read_group_res = self.env['rating.rating'].read_group(domain, ['res_id', 'rating'], groupby=['res_id', 'rating'], lazy=False) + read_group_res = self.env['rating.rating']._read_group(domain, ['res_id', 'rating'], groupby=['res_id', 'rating'], lazy=False) default_grades = {'great': 0, 'okay': 0, 'bad': 0} grades_per_record = {record_id: default_grades.copy() for record_id in self.ids} diff --git a/addons/sale/models/crm_team.py b/addons/sale/models/crm_team.py index 8428cef5401..b3a3eed9d0e 100644 --- a/addons/sale/models/crm_team.py +++ b/addons/sale/models/crm_team.py @@ -60,7 +60,7 @@ class CrmTeam(models.Model): remaining.quotations_count = 0 def _compute_sales_to_invoice(self): - sale_order_data = self.env['sale.order'].read_group([ + sale_order_data = self.env['sale.order']._read_group([ ('team_id', 'in', self.ids), ('invoice_status','=','to invoice'), ], ['team_id'], ['team_id']) @@ -95,7 +95,7 @@ class CrmTeam(models.Model): def _compute_sale_order_count(self): data_map = {} if self.ids: - sale_order_data = self.env['sale.order'].read_group([ + sale_order_data = self.env['sale.order']._read_group([ ('team_id', 'in', self.ids), ('state', '!=', 'cancel'), ], ['team_id'], ['team_id']) diff --git a/addons/sale/models/product_product.py b/addons/sale/models/product_product.py index 5b0a9e082fc..eb2c9083448 100644 --- a/addons/sale/models/product_product.py +++ b/addons/sale/models/product_product.py @@ -25,7 +25,7 @@ class ProductProduct(models.Model): ('product_id', 'in', self.ids), ('date', '>=', date_from), ] - for group in self.env['sale.report'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']): + for group in self.env['sale.report']._read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']): r[group['product_id'][0]] = group['product_uom_qty'] for product in self: if not product.id: @@ -58,7 +58,7 @@ class ProductProduct(models.Model): def _filter_to_unlink(self): domain = [('product_id', 'in', self.ids)] - lines = self.env['sale.order.line'].read_group(domain, ['product_id'], ['product_id']) + lines = self.env['sale.order.line']._read_group(domain, ['product_id'], ['product_id']) linked_product_ids = [group['product_id'][0] for group in lines] return super(ProductProduct, self - self.browse(linked_product_ids))._filter_to_unlink() diff --git a/addons/sale/models/res_partner.py b/addons/sale/models/res_partner.py index d77abad7559..c280d4b4cd3 100644 --- a/addons/sale/models/res_partner.py +++ b/addons/sale/models/res_partner.py @@ -18,7 +18,7 @@ class ResPartner(models.Model): all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) - sale_order_groups = self.env['sale.order'].read_group( + sale_order_groups = self.env['sale.order']._read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id'] ) diff --git a/addons/sale/models/utm_campaign.py b/addons/sale/models/utm_campaign.py index 720b4024a57..c5f222c7f69 100644 --- a/addons/sale/models/utm_campaign.py +++ b/addons/sale/models/utm_campaign.py @@ -15,7 +15,7 @@ class UtmCampaign(models.Model): currency_id = fields.Many2one('res.currency', related='company_id.currency_id', string='Currency') def _compute_quotation_count(self): - quotation_data = self.env['sale.order'].read_group([ + quotation_data = self.env['sale.order']._read_group([ ('campaign_id', 'in', self.ids)], ['campaign_id'], ['campaign_id']) data_map = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in quotation_data} diff --git a/addons/sale_expense/models/sale_order.py b/addons/sale_expense/models/sale_order.py index fef55214523..4fc225006d4 100644 --- a/addons/sale_expense/models/sale_order.py +++ b/addons/sale_expense/models/sale_order.py @@ -22,7 +22,7 @@ class SaleOrder(models.Model): @api.depends('expense_ids') def _compute_expense_count(self): - expense_data = self.env['hr.expense'].read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id']) + expense_data = self.env['hr.expense']._read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id']) mapped_data = dict([(item['sale_order_id'][0], item['sale_order_id_count']) for item in expense_data]) for sale_order in self: sale_order.expense_count = mapped_data.get(sale_order.id, 0) diff --git a/addons/sale_management/models/digest.py b/addons/sale_management/models/digest.py index 8828ad98a77..7782cb765db 100644 --- a/addons/sale_management/models/digest.py +++ b/addons/sale_management/models/digest.py @@ -16,7 +16,7 @@ class Digest(models.Model): raise AccessError(_("Do not have access, skip this data for user's digest email")) for record in self: start, end, company = record._get_kpi_compute_parameters() - all_channels_sales = self.env['sale.report'].read_group([ + all_channels_sales = self.env['sale.report']._read_group([ ('date', '>=', start), ('date', '<', end), ('state', 'not in', ['draft', 'cancel', 'sent']), diff --git a/addons/sale_timesheet/models/account_move.py b/addons/sale_timesheet/models/account_move.py index 9e395f1736a..19d00163ae4 100644 --- a/addons/sale_timesheet/models/account_move.py +++ b/addons/sale_timesheet/models/account_move.py @@ -20,7 +20,7 @@ class AccountMove(models.Model): if not self.user_has_groups('hr_timesheet.group_hr_timesheet_user'): self.timesheet_total_duration = 0 return - group_data = self.env['account.analytic.line'].read_group([ + group_data = self.env['account.analytic.line']._read_group([ ('timesheet_invoice_id', 'in', self.ids) ], ['timesheet_invoice_id', 'unit_amount'], ['timesheet_invoice_id']) timesheet_unit_amount_dict = defaultdict(float) @@ -31,7 +31,7 @@ class AccountMove(models.Model): @api.depends('timesheet_ids') def _compute_timesheet_count(self): - timesheet_data = self.env['account.analytic.line'].read_group([('timesheet_invoice_id', 'in', self.ids)], ['timesheet_invoice_id'], ['timesheet_invoice_id']) + timesheet_data = self.env['account.analytic.line']._read_group([('timesheet_invoice_id', 'in', self.ids)], ['timesheet_invoice_id'], ['timesheet_invoice_id']) mapped_data = dict([(t['timesheet_invoice_id'][0], t['timesheet_invoice_id_count']) for t in timesheet_data]) for invoice in self: invoice.timesheet_count = mapped_data.get(invoice.id, 0) @@ -110,7 +110,7 @@ class AccountMoveLine(models.Model): for move_line in move_line_read_group: sale_line_ids_per_move[move_line['move_id'][0]] += self.env['sale.order.line'].browse(move_line['sale_line_ids']) - timesheet_read_group = self.sudo().env['account.analytic.line'].read_group([ + timesheet_read_group = self.sudo().env['account.analytic.line']._read_group([ ('timesheet_invoice_id.move_type', '=', 'out_invoice'), ('timesheet_invoice_id.state', '=', 'draft'), ('timesheet_invoice_id', 'in', self.move_id.ids)], diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 3cc0faaecd4..36d94d23ddf 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -112,7 +112,7 @@ class Project(models.Model): @api.depends('analytic_account_id', 'timesheet_ids') def _compute_billable_percentage(self): - timesheets_read_group = self.env['account.analytic.line'].read_group([('project_id', 'in', self.ids)], ['project_id', 'so_line', 'unit_amount'], ['project_id', 'so_line'], lazy=False) + timesheets_read_group = self.env['account.analytic.line']._read_group([('project_id', 'in', self.ids)], ['project_id', 'so_line', 'unit_amount'], ['project_id', 'so_line'], lazy=False) timesheets_by_project = defaultdict(list) for res in timesheets_read_group: timesheets_by_project[res['project_id'][0]].append((res['unit_amount'], bool(res['so_line']))) @@ -142,7 +142,7 @@ class Project(models.Model): @api.depends('pricing_type', 'allow_timesheets', 'allow_billable', 'sale_line_employee_ids', 'sale_line_employee_ids.employee_id') def _compute_warning_employee_rate(self): projects = self.filtered(lambda p: p.allow_billable and p.allow_timesheets and p.pricing_type == 'employee_rate') - employees = self.env['account.analytic.line'].read_group([('task_id', 'in', projects.task_ids.ids)], ['employee_id', 'project_id'], ['employee_id', 'project_id'], ['employee_id', 'project_id'], lazy=False) + employees = self.env['account.analytic.line']._read_group([('task_id', 'in', projects.task_ids.ids)], ['employee_id', 'project_id'], ['employee_id', 'project_id'], ['employee_id', 'project_id'], lazy=False) dict_project_employee = defaultdict(list) for line in employees: dict_project_employee[line['project_id'][0]] += [line['employee_id'][0]] if line['employee_id'] else [] @@ -376,7 +376,7 @@ class Project(models.Model): 'revenues': 0.0 } - profitability = self.env['project.profitability.report'].read_group( + profitability = self.env['project.profitability.report']._read_group( [('project_id', '=', self.id)], ['project_id', 'amount_untaxed_to_invoice', diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py index 5831d048885..1eb8e43424f 100644 --- a/addons/sale_timesheet/models/sale_order.py +++ b/addons/sale_timesheet/models/sale_order.py @@ -45,7 +45,7 @@ class SaleOrder(models.Model): if not self.user_has_groups('hr_timesheet.group_hr_timesheet_user'): self.update({'timesheet_total_duration': 0}) return - group_data = self.env['account.analytic.line'].sudo().read_group([ + group_data = self.env['account.analytic.line'].sudo()._read_group([ ('order_id', 'in', self.ids) ], ['order_id', 'unit_amount'], ['order_id']) timesheet_unit_amount_dict = defaultdict(float) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 1e7b130b893..b86fa90d766 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -172,15 +172,15 @@ class Product(models.Model): Quant = self.env['stock.quant'].with_context(active_test=False) domain_move_in_todo = [('state', 'in', ('waiting', 'confirmed', 'assigned', 'partially_available'))] + domain_move_in domain_move_out_todo = [('state', 'in', ('waiting', 'confirmed', 'assigned', 'partially_available'))] + domain_move_out - moves_in_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_in_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) - moves_out_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_out_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) - quants_res = dict((item['product_id'][0], (item['quantity'], item['reserved_quantity'])) for item in Quant.read_group(domain_quant, ['product_id', 'quantity', 'reserved_quantity'], ['product_id'], orderby='id')) + moves_in_res = dict((item['product_id'][0], item['product_qty']) for item in Move._read_group(domain_move_in_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) + moves_out_res = dict((item['product_id'][0], item['product_qty']) for item in Move._read_group(domain_move_out_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id')) + quants_res = dict((item['product_id'][0], (item['quantity'], item['reserved_quantity'])) for item in Quant._read_group(domain_quant, ['product_id', 'quantity', 'reserved_quantity'], ['product_id'], orderby='id')) if dates_in_the_past: # Calculate the moves that were done before now to calculate back in time (as most questions will be recent ones) domain_move_in_done = [('state', '=', 'done'), ('date', '>', to_date)] + domain_move_in_done domain_move_out_done = [('state', '=', 'done'), ('date', '>', to_date)] + domain_move_out_done - moves_in_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_in_done, ['product_id', 'product_qty'], ['product_id'], orderby='id')) - moves_out_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_out_done, ['product_id', 'product_qty'], ['product_id'], orderby='id')) + moves_in_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move._read_group(domain_move_in_done, ['product_id', 'product_qty'], ['product_id'], orderby='id')) + moves_out_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move._read_group(domain_move_out_done, ['product_id', 'product_qty'], ['product_id'], orderby='id')) res = dict() for product in self.with_context(prefetch_fields=False): @@ -371,7 +371,7 @@ class Product(models.Model): domain_quant.append(('owner_id', '=', owner_id)) if package_id: domain_quant.append(('package_id', '=', package_id)) - quants_groupby = self.env['stock.quant'].read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id') + quants_groupby = self.env['stock.quant']._read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id') # check if we need include zero values in result include_zero = ( @@ -398,7 +398,7 @@ class Product(models.Model): return list(product_ids) def _compute_nbr_reordering_rules(self): - read_group_res = self.env['stock.warehouse.orderpoint'].read_group( + read_group_res = self.env['stock.warehouse.orderpoint']._read_group( [('product_id', 'in', self.ids)], ['product_id', 'product_min_qty', 'product_max_qty'], ['product_id']) @@ -593,7 +593,7 @@ class Product(models.Model): :rtype: defaultdict(float) """ domain_quant = expression.AND([self._get_domain_locations()[0], [('product_id', 'in', self.ids)]]) - quants_groupby = self.env['stock.quant'].read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id') + quants_groupby = self.env['stock.quant']._read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id') currents = defaultdict(float) for c in quants_groupby: currents[c['product_id'][0]] = c['quantity'] @@ -601,7 +601,7 @@ class Product(models.Model): def _filter_to_unlink(self): domain = [('product_id', 'in', self.ids)] - lines = self.env['stock.lot'].read_group(domain, ['product_id'], ['product_id']) + lines = self.env['stock.lot']._read_group(domain, ['product_id'], ['product_id']) linked_product_ids = [group['product_id'][0] for group in lines] return super(Product, self - self.browse(linked_product_ids))._filter_to_unlink() @@ -730,13 +730,13 @@ class ProductTemplate(models.Model): def _compute_nbr_moves(self): res = defaultdict(lambda: {'moves_in': 0, 'moves_out': 0}) - incoming_moves = self.env['stock.move.line'].read_group([ + incoming_moves = self.env['stock.move.line']._read_group([ ('product_id.product_tmpl_id', 'in', self.ids), ('state', '=', 'done'), ('picking_code', '=', 'incoming'), ('date', '>=', fields.Datetime.now() - relativedelta(years=1)) ], ['product_id'], ['product_id']) - outgoing_moves = self.env['stock.move.line'].read_group([ + outgoing_moves = self.env['stock.move.line']._read_group([ ('product_id.product_tmpl_id', 'in', self.ids), ('state', '=', 'done'), ('picking_code', '=', 'outgoing'), @@ -786,7 +786,7 @@ class ProductTemplate(models.Model): def _compute_nbr_reordering_rules(self): res = {k: {'nbr_reordering_rules': 0, 'reordering_min_qty': 0, 'reordering_max_qty': 0} for k in self.ids} - product_data = self.env['stock.warehouse.orderpoint'].read_group([('product_id.product_tmpl_id', 'in', self.ids)], ['product_id', 'product_min_qty', 'product_max_qty'], ['product_id']) + product_data = self.env['stock.warehouse.orderpoint']._read_group([('product_id.product_tmpl_id', 'in', self.ids)], ['product_id', 'product_min_qty', 'product_max_qty'], ['product_id']) for data in product_data: product = self.env['product.product'].browse([data['product_id'][0]]) product_tmpl_id = product.product_tmpl_id.id diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index d9bf30b4172..f857fc6c7c7 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -257,11 +257,11 @@ class Location(models.Model): qty_by_location = defaultdict(lambda: 0) if locations.storage_category_id: if package and package.package_type_id: - move_line_data = self.env['stock.move.line'].read_group([ + move_line_data = self.env['stock.move.line']._read_group([ ('result_package_id.package_type_id', '=', package_type.id), ('state', 'not in', ['draft', 'cancel', 'done']), ], ['result_package_id:count_distinct'], ['location_dest_id']) - quant_data = self.env['stock.quant'].read_group([ + quant_data = self.env['stock.quant']._read_group([ ('package_id.package_type_id', '=', package_type.id), ('location_id', 'in', locations.ids), ], ['package_id:count_distinct'], ['location_id']) @@ -270,12 +270,12 @@ class Location(models.Model): for values in quant_data: qty_by_location[values['location_id'][0]] += values['package_id'] else: - move_line_data = self.env['stock.move.line'].read_group([ + move_line_data = self.env['stock.move.line']._read_group([ ('product_id', '=', product.id), ('location_dest_id', 'in', locations.ids), ('state', 'not in', ['draft', 'done', 'cancel']) ], ['location_dest_id', 'product_id', 'reserved_qty:array_agg', 'qty_done:array_agg', 'product_uom_id:array_agg'], ['location_dest_id']) - quant_data = self.env['stock.quant'].read_group([ + quant_data = self.env['stock.quant']._read_group([ ('product_id', '=', product.id), ('location_id', 'in', locations.ids), ], ['location_id', 'product_id', 'quantity:sum'], ['location_id']) diff --git a/addons/stock/models/stock_lot.py b/addons/stock/models/stock_lot.py index b7da9a19d57..54b3fec8d07 100644 --- a/addons/stock/models/stock_lot.py +++ b/addons/stock/models/stock_lot.py @@ -78,7 +78,7 @@ class StockLot(models.Model): ('name', 'in', self.mapped('name'))] fields = ['company_id', 'product_id', 'name'] groupby = ['company_id', 'product_id', 'name'] - records = self.read_group(domain, fields, groupby, lazy=False) + records = self._read_group(domain, fields, groupby, lazy=False) error_message_lines = [] for rec in records: if rec['__count'] != 1: diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 5aed8c47f7b..bba0daa8d2d 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -329,7 +329,7 @@ class StockMove(models.Model): for move in self: move_lines_ids |= set(move._get_move_lines().ids) - data = self.env['stock.move.line'].read_group( + data = self.env['stock.move.line']._read_group( [('id', 'in', list(move_lines_ids))], ['move_id', 'product_uom_id', 'qty_done'], ['move_id', 'product_uom_id'], lazy=False @@ -391,7 +391,7 @@ class StockMove(models.Model): else: # compute result = {data['move_id'][0]: data['reserved_qty'] for data in - self.env['stock.move.line'].read_group([('move_id', 'in', self.ids)], ['move_id', 'reserved_qty'], ['move_id'])} + self.env['stock.move.line']._read_group([('move_id', 'in', self.ids)], ['move_id', 'reserved_qty'], ['move_id'])} for move in self: move.reserved_availability = move.product_id.uom_id._compute_quantity( result.get(move.id, 0.0), move.product_uom, rounding_method='HALF-UP') @@ -493,7 +493,7 @@ class StockMove(models.Model): domain_suggest = [('move_id', 'in', self.ids), ('lot_id', '!=', False), ('qty_done', '!=', 0.0)] lots_by_move_id_list = [] for domain in [domain_nosuggest, domain_suggest]: - lots_by_move_id = self.env['stock.move.line'].read_group( + lots_by_move_id = self.env['stock.move.line']._read_group( domain, ['move_id', 'lot_ids:array_agg(lot_id)'], ['move_id'], ) diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 68debf702dc..cc53fef272f 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -277,7 +277,7 @@ class StockWarehouseOrderpoint(models.Model): orderpoints generated when openning the replenish report. """ self = self.filtered(lambda o: not o.route_id) - rules_groups = self.env['stock.rule'].read_group([ + rules_groups = self.env['stock.rule']._read_group([ ('route_id.product_selectable', '!=', False), ('location_dest_id', 'in', self.location_id.ids), ('action', 'in', ['pull_push', 'pull']) @@ -325,7 +325,7 @@ class StockWarehouseOrderpoint(models.Model): all_warehouse_ids = [] # Take 3 months since it's the max for the forecast report to_date = add(fields.date.today(), months=3) - qty_by_product_warehouse = self.env['report.stock.quantity'].read_group( + qty_by_product_warehouse = self.env['report.stock.quantity']._read_group( [('date', '=', to_date), ('state', '=', 'forecast')], ['product_id', 'product_qty', 'warehouse_id'], ['product_id', 'warehouse_id'], lazy=False) @@ -374,7 +374,7 @@ class StockWarehouseOrderpoint(models.Model): dummy, qty_by_product_wh = self.env['product.product'].browse(product_ids)._get_quantity_in_progress(warehouse_ids=warehouse_ids) rounding = self.env['decimal.precision'].precision_get('Product Unit of Measure') # Group orderpoint by product-warehouse - orderpoint_by_product_warehouse = self.env['stock.warehouse.orderpoint'].read_group( + orderpoint_by_product_warehouse = self.env['stock.warehouse.orderpoint']._read_group( [('id', 'in', orderpoints.ids)], ['product_id', 'warehouse_id', 'qty_to_order:sum'], ['product_id', 'warehouse_id'], lazy=False) @@ -398,7 +398,7 @@ class StockWarehouseOrderpoint(models.Model): lot_stock_id_by_warehouse = {w['id']: w['lot_stock_id'][0] for w in lot_stock_id_by_warehouse} # With archived ones to avoid `product_location_check` SQL constraints - orderpoint_by_product_location = self.env['stock.warehouse.orderpoint'].with_context(active_test=False).read_group( + orderpoint_by_product_location = self.env['stock.warehouse.orderpoint'].with_context(active_test=False)._read_group( [('id', 'in', orderpoints.ids)], ['product_id', 'location_id', 'ids:array_agg(id)'], ['product_id', 'location_id'], lazy=False) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 6df190d9b1b..c0a8d6c59a9 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -143,7 +143,7 @@ class PickingType(models.Model): 'count_picking_backorders': [('backorder_id', '!=', False), ('state', 'in', ('confirmed', 'assigned', 'waiting'))], } for field in domains: - data = self.env['stock.picking'].read_group(domains[field] + + data = self.env['stock.picking']._read_group(domains[field] + [('state', 'not in', ('done', 'cancel')), ('picking_type_id', 'in', self.ids)], ['picking_type_id'], ['picking_type_id']) count = { @@ -438,7 +438,7 @@ class Picking(models.Model): @api.depends('move_ids.delay_alert_date') def _compute_delay_alert_date(self): - delay_alert_date_data = self.env['stock.move'].read_group([('id', 'in', self.move_ids.ids), ('delay_alert_date', '!=', False)], ['delay_alert_date:max'], 'picking_id') + delay_alert_date_data = self.env['stock.move']._read_group([('id', 'in', self.move_ids.ids), ('delay_alert_date', '!=', False)], ['delay_alert_date:max'], 'picking_id') delay_alert_date_data = {data['picking_id'][0]: data['delay_alert_date'] for data in delay_alert_date_data} for picking in self: picking.delay_alert_date = delay_alert_date_data.get(picking.id, False) @@ -590,7 +590,7 @@ class Picking(models.Model): def _compute_has_packages(self): domain = [('picking_id', 'in', self.ids), ('result_package_id', '!=', False)] - cnt_by_picking = self.env['stock.move.line'].read_group(domain, ['picking_id'], ['picking_id']) + cnt_by_picking = self.env['stock.move.line']._read_group(domain, ['picking_id'], ['picking_id']) cnt_by_picking = {d['picking_id'][0]: d['picking_id_count'] for d in cnt_by_picking} for picking in self: picking.has_packages = bool(cnt_by_picking.get(picking.id, False)) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index e00242fe675..a910040fd1d 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -136,7 +136,7 @@ class StockQuant(models.Model): """ We look at the stock move lines associated with every quant to get the last count date. """ self.last_count_date = False - groups = self.env['stock.move.line'].read_group( + groups = self.env['stock.move.line']._read_group( [ ('state', '=', 'done'), ('is_inventory', '=', True), @@ -207,7 +207,7 @@ class StockQuant(models.Model): def _compute_sn_duplicated(self): self.sn_duplicated = False domain = [('tracking', '=', 'serial'), ('lot_id', 'in', self.lot_id.ids), ('location_id.usage', 'in', ['internal', 'transit'])] - results = self.read_group(domain, ['lot_id'], ['lot_id']) + results = self._read_group(domain, ['lot_id'], ['lot_id']) duplicated_sn_ids = [x['lot_id'][0] for x in results if x['lot_id_count'] > 1] quants_with_duplicated_sn = self.env['stock.quant'].search([('lot_id', 'in', duplicated_sn_ids)]) quants_with_duplicated_sn.sn_duplicated = True diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index d37ea02a73f..9885cdc3ebd 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -281,7 +281,7 @@ class Warehouse(models.Model): return res def _check_multiwarehouse_group(self): - cnt_by_company = self.env['stock.warehouse'].sudo().read_group([('active', '=', True)], ['company_id'], groupby=['company_id']) + cnt_by_company = self.env['stock.warehouse'].sudo()._read_group([('active', '=', True)], ['company_id'], groupby=['company_id']) if cnt_by_company: max_cnt = max(cnt_by_company, key=lambda k: k['company_id_count']) group_user = self.env.ref('base.group_user') diff --git a/addons/stock/report/report_stock_forecasted.py b/addons/stock/report/report_stock_forecasted.py index 2dd4fa42737..44c49a15121 100644 --- a/addons/stock/report/report_stock_forecasted.py +++ b/addons/stock/report/report_stock_forecasted.py @@ -45,8 +45,8 @@ class ReplenishmentReport(models.AbstractModel): def _compute_draft_quantity_count(self, product_template_ids, product_variant_ids, wh_location_ids): in_domain, out_domain = self._move_draft_domain(product_template_ids, product_variant_ids, wh_location_ids) - incoming_moves = self.env['stock.move'].read_group(in_domain, ['product_qty:sum'], 'product_id') - outgoing_moves = self.env['stock.move'].read_group(out_domain, ['product_qty:sum'], 'product_id') + incoming_moves = self.env['stock.move']._read_group(in_domain, ['product_qty:sum'], 'product_id') + outgoing_moves = self.env['stock.move']._read_group(out_domain, ['product_qty:sum'], 'product_id') in_sum = sum(move['product_qty'] for move in incoming_moves) out_sum = sum(move['product_qty'] for move in outgoing_moves) return { diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 6662cb4c953..3da76270bf1 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -117,7 +117,7 @@ class ProductProduct(models.Model): if self.env.context.get('to_date'): to_date = fields.Datetime.to_datetime(self.env.context['to_date']) domain.append(('create_date', '<=', to_date)) - groups = self.env['stock.valuation.layer'].read_group(domain, ['value:sum', 'quantity:sum'], ['product_id']) + groups = self.env['stock.valuation.layer']._read_group(domain, ['value:sum', 'quantity:sum'], ['product_id']) products = self.browse() for group in groups: product = self.browse(group['product_id'][0]) diff --git a/addons/stock_picking_batch/models/stock_picking.py b/addons/stock_picking_batch/models/stock_picking.py index be8f0ffeb27..615428de098 100644 --- a/addons/stock_picking_batch/models/stock_picking.py +++ b/addons/stock_picking_batch/models/stock_picking.py @@ -34,7 +34,7 @@ class StockPickingType(models.Model): 'count_picking_wave': [('is_wave', '=', True)], } for field in domains: - data = self.env['stock.picking.batch'].read_group(domains[field] + + data = self.env['stock.picking.batch']._read_group(domains[field] + [('state', 'not in', ('done', 'cancel')), ('picking_type_id', 'in', self.ids)], ['picking_type_id'], ['picking_type_id']) count = { diff --git a/addons/survey/models/res_partner.py b/addons/survey/models/res_partner.py index 1c7a5e1ec6c..d8c12f6c8f5 100644 --- a/addons/survey/models/res_partner.py +++ b/addons/survey/models/res_partner.py @@ -12,7 +12,7 @@ class ResPartner(models.Model): @api.depends('is_company') def _compute_certifications_count(self): - read_group_res = self.env['survey.user_input'].sudo().read_group( + read_group_res = self.env['survey.user_input'].sudo()._read_group( [('partner_id', 'in', self.ids), ('scoring_success', '=', True)], ['partner_id'], 'partner_id' ) diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index e9033f1636f..c85453e99d7 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -193,7 +193,7 @@ class Survey(models.Model): UserInput = self.env['survey.user_input'] base_domain = ['&', ('survey_id', 'in', self.ids), ('test_entry', '!=', True)] - read_group_res = UserInput.read_group(base_domain, ['survey_id', 'state'], ['survey_id', 'state', 'scoring_percentage', 'scoring_success'], lazy=False) + read_group_res = UserInput._read_group(base_domain, ['survey_id', 'state'], ['survey_id', 'state', 'scoring_percentage', 'scoring_success'], lazy=False) for item in read_group_res: stat[item['survey_id'][0]]['answer_count'] += item['__count'] stat[item['survey_id'][0]]['answer_score_avg_total'] += item['scoring_percentage'] @@ -254,7 +254,7 @@ class Survey(models.Model): for survey in self: answer_count = 0 - input_count = self.env['survey.user_input'].read_group( + input_count = self.env['survey.user_input']._read_group( [('survey_id', '=', survey.id), ('is_session_answer', '=', True), ('state', '!=', 'done'), @@ -275,7 +275,7 @@ class Survey(models.Model): context of sessions, so it should not matter too much. """ for survey in self: answer_count = 0 - input_line_count = self.env['survey.user_input.line'].read_group( + input_line_count = self.env['survey.user_input.line']._read_group( [('question_id', '=', survey.session_question_id.id), ('survey_id', '=', survey.id), ('create_date', '>=', survey.session_start_time)], @@ -1017,7 +1017,7 @@ class Survey(models.Model): ('state', '=', 'done'), ('test_entry', '=', False) ] - count_data_success = self.env['survey.user_input'].sudo().read_group(user_input_domain, ['scoring_success', 'id:count_distinct'], ['scoring_success']) + count_data_success = self.env['survey.user_input'].sudo()._read_group(user_input_domain, ['scoring_success', 'id:count_distinct'], ['scoring_success']) completed_count = self.env['survey.user_input'].sudo().search_count(user_input_domain + [('state', "=", "done")]) scoring_success_count = 0 diff --git a/addons/website/models/website_visitor.py b/addons/website/models/website_visitor.py index 8b3cae7807c..4a651d72e0c 100644 --- a/addons/website/models/website_visitor.py +++ b/addons/website/models/website_visitor.py @@ -94,7 +94,7 @@ class WebsiteVisitor(models.Model): @api.depends('website_track_ids') def _compute_page_statistics(self): - results = self.env['website.track'].read_group( + results = self.env['website.track']._read_group( [('visitor_id', 'in', self.ids), ('url', '!=', False)], ['visitor_id', 'page_id', 'url'], ['visitor_id', 'page_id', 'url'], lazy=False) mapped_data = {} for result in results: @@ -113,7 +113,7 @@ class WebsiteVisitor(models.Model): @api.depends('website_track_ids.page_id') def _compute_last_visited_page_id(self): - results = self.env['website.track'].read_group([('visitor_id', 'in', self.ids)], + results = self.env['website.track']._read_group([('visitor_id', 'in', self.ids)], ['visitor_id', 'page_id', 'visit_datetime:max'], ['visitor_id', 'page_id'], lazy=False) mapped_data = {result['visitor_id'][0]: result['page_id'][0] for result in results if result['page_id']} diff --git a/addons/website_crm_iap_reveal/models/crm_reveal_rule.py b/addons/website_crm_iap_reveal/models/crm_reveal_rule.py index 9a4bb7c30d7..9d924c46ce4 100644 --- a/addons/website_crm_iap_reveal/models/crm_reveal_rule.py +++ b/addons/website_crm_iap_reveal/models/crm_reveal_rule.py @@ -67,7 +67,7 @@ class CRMRevealRule(models.Model): ] def _compute_lead_count(self): - leads = self.env['crm.lead'].read_group([ + leads = self.env['crm.lead']._read_group([ ('reveal_rule_id', 'in', self.ids) ], fields=['reveal_rule_id', 'type'], groupby=['reveal_rule_id', 'type'], lazy=False) mapping = {(lead['reveal_rule_id'][0], lead['type']): lead['__count'] for lead in leads} diff --git a/addons/website_crm_partner_assign/models/res_partner.py b/addons/website_crm_partner_assign/models/res_partner.py index b4cf6c5da12..86434e736ad 100644 --- a/addons/website_crm_partner_assign/models/res_partner.py +++ b/addons/website_crm_partner_assign/models/res_partner.py @@ -45,7 +45,7 @@ class ResPartner(models.Model): if not self.ids: self.implemented_partner_count = 0 return - rg_result = self.env['res.partner'].read_group( + rg_result = self.env['res.partner']._read_group( [('assigned_partner_id', 'in', self.ids), ('is_published', '=', True)], ['assigned_partner_id'], @@ -64,7 +64,7 @@ class ResPartner(models.Model): super()._compute_opportunity_count() assign_counts = {} if self.ids: - opportunity_data = self.env['crm.lead'].with_context(active_test=False).read_group( + opportunity_data = self.env['crm.lead'].with_context(active_test=False)._read_group( [('partner_assigned_id', 'in', self.ids)], ['partner_assigned_id'], ['partner_assigned_id'] ) diff --git a/addons/website_event/models/website_visitor.py b/addons/website_event/models/website_visitor.py index 26285436847..e64ea1c2b53 100644 --- a/addons/website_event/models/website_visitor.py +++ b/addons/website_event/models/website_visitor.py @@ -24,7 +24,7 @@ class WebsiteVisitor(models.Model): @api.depends('event_registration_ids') def _compute_event_registration_count(self): if self.ids: - read_group_res = self.env['event.registration'].read_group( + read_group_res = self.env['event.registration']._read_group( [('visitor_id', 'in', self.ids)], ['visitor_id'], ['visitor_id']) visitor_mapping = dict( diff --git a/addons/website_event_exhibitor/models/event_event.py b/addons/website_event_exhibitor/models/event_event.py index dc2ec8618b8..0ddf80ad004 100644 --- a/addons/website_event_exhibitor/models/event_event.py +++ b/addons/website_event_exhibitor/models/event_event.py @@ -20,7 +20,7 @@ class EventEvent(models.Model): domain=[('menu_type', '=', 'exhibitor')]) def _compute_sponsor_count(self): - data = self.env['event.sponsor'].read_group([], ['event_id'], ['event_id']) + data = self.env['event.sponsor']._read_group([], ['event_id'], ['event_id']) result = dict((data['event_id'][0], data['event_id_count']) for data in data) for event in self: event.sponsor_count = result.get(event.id, 0) diff --git a/addons/website_event_meet/models/event_event.py b/addons/website_event_meet/models/event_event.py index af44e8e6664..7dfe6ff4fb5 100644 --- a/addons/website_event_meet/models/event_event.py +++ b/addons/website_event_meet/models/event_event.py @@ -27,7 +27,7 @@ class Event(models.Model): @api.depends("meeting_room_ids") def _compute_meeting_room_count(self): - meeting_room_count = self.env["event.meeting.room"].sudo().read_group( + meeting_room_count = self.env["event.meeting.room"].sudo()._read_group( domain=[("event_id", "in", self.ids)], fields=["id:count"], groupby=["event_id"], diff --git a/addons/website_event_track/models/event_event.py b/addons/website_event_track/models/event_event.py index eab7bb04cd6..4c78750cd1a 100644 --- a/addons/website_event_track/models/event_event.py +++ b/addons/website_event_track/models/event_event.py @@ -24,7 +24,7 @@ class Event(models.Model): compute='_compute_tracks_tag_ids', store=True) def _compute_track_count(self): - data = self.env['event.track'].read_group([('stage_id.is_cancel', '!=', True)], ['event_id'], ['event_id']) + data = self.env['event.track']._read_group([('stage_id.is_cancel', '!=', True)], ['event_id'], ['event_id']) result = dict((data['event_id'][0], data['event_id_count']) for data in data) for event in self: event.track_count = result.get(event.id, 0) diff --git a/addons/website_event_track/models/event_track.py b/addons/website_event_track/models/event_track.py index 86d96e18ebc..ed64c00aa64 100644 --- a/addons/website_event_track/models/event_track.py +++ b/addons/website_event_track/models/event_track.py @@ -332,7 +332,7 @@ class Track(models.Model): @api.depends('event_track_visitor_ids.visitor_id', 'event_track_visitor_ids.is_wishlisted') def _compute_wishlist_visitor_ids(self): - results = self.env['event.track.visitor'].read_group( + results = self.env['event.track.visitor']._read_group( [('track_id', 'in', self.ids), ('is_wishlisted', '=', True)], ['track_id', 'visitor_id:array_agg'], ['track_id'] diff --git a/addons/website_event_track/models/website_visitor.py b/addons/website_event_track/models/website_visitor.py index e5d1abf55ad..65c80077553 100644 --- a/addons/website_event_track/models/website_visitor.py +++ b/addons/website_event_track/models/website_visitor.py @@ -24,7 +24,7 @@ class WebsiteVisitor(models.Model): @api.depends('event_track_visitor_ids.track_id', 'event_track_visitor_ids.is_wishlisted') def _compute_event_track_wishlisted_ids(self): - results = self.env['event.track.visitor'].read_group( + results = self.env['event.track.visitor']._read_group( [('visitor_id', 'in', self.ids), ('is_wishlisted', '=', True)], ['visitor_id', 'track_id:array_agg'], ['visitor_id'] diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 73dda8e29ea..4a6941ecc8e 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -160,7 +160,7 @@ class Forum(models.Model): return result = dict.fromkeys(self.ids, default_stats) - read_group_res = self.env['forum.post'].read_group( + read_group_res = self.env['forum.post']._read_group( [('forum_id', 'in', self.ids), ('state', 'in', ('active', 'close')), ('parent_id', '=', False)], ['forum_id', 'views', 'child_count', 'favourite_count'], groupby=['forum_id'], @@ -433,7 +433,7 @@ class Post(models.Model): @api.depends('vote_ids.vote') def _get_vote_count(self): - read_group_res = self.env['forum.post.vote'].read_group([('post_id', 'in', self._ids)], ['post_id', 'vote'], ['post_id', 'vote'], lazy=False) + read_group_res = self.env['forum.post.vote']._read_group([('post_id', 'in', self._ids)], ['post_id', 'vote'], ['post_id', 'vote'], lazy=False) result = dict.fromkeys(self._ids, 0) for data in read_group_res: result[data['post_id'][0]] += data['__count'] * int(data['vote']) diff --git a/addons/website_sale/controllers/backend.py b/addons/website_sale/controllers/backend.py index bff9790fe8b..96b6d935499 100644 --- a/addons/website_sale/controllers/backend.py +++ b/addons/website_sale/controllers/backend.py @@ -136,17 +136,17 @@ class WebsiteSaleBackend(WebsiteBackend): ('date_order', '<=', date_to) ] - orders_data_groupby_campaign_id = request.env['sale.order'].read_group( + orders_data_groupby_campaign_id = request.env['sale.order']._read_group( domain=sale_utm_domain + [('campaign_id', '!=', False)], fields=['amount_total', 'id', 'campaign_id'], groupby='campaign_id') - orders_data_groupby_medium_id = request.env['sale.order'].read_group( + orders_data_groupby_medium_id = request.env['sale.order']._read_group( domain=sale_utm_domain + [('medium_id', '!=', False)], fields=['amount_total', 'id', 'medium_id'], groupby='medium_id') - orders_data_groupby_source_id = request.env['sale.order'].read_group( + orders_data_groupby_source_id = request.env['sale.order']._read_group( domain=sale_utm_domain + [('source_id', '!=', False)], fields=['amount_total', 'id', 'source_id'], groupby='source_id') diff --git a/addons/website_sale/models/crm_team.py b/addons/website_sale/models/crm_team.py index 6badbbcaf54..1f6b349ffba 100644 --- a/addons/website_sale/models/crm_team.py +++ b/addons/website_sale/models/crm_team.py @@ -27,7 +27,7 @@ class CrmTeam(models.Model): amounts = {} website_teams = self.filtered(lambda team: team.website_ids) if website_teams: - abandoned_carts_data = self.env['sale.order'].read_group([ + abandoned_carts_data = self.env['sale.order']._read_group([ ('is_abandoned_cart', '=', True), ('cart_recovery_email_sent', '=', False), ('team_id', 'in', website_teams.ids), diff --git a/addons/website_sale/models/website_snippet_filter.py b/addons/website_sale/models/website_snippet_filter.py index a44ee16be4e..5d1d7f3d448 100644 --- a/addons/website_sale/models/website_snippet_filter.py +++ b/addons/website_sale/models/website_snippet_filter.py @@ -101,7 +101,7 @@ class WebsiteSnippetFilter(models.Model): visitor = self.env['website.visitor']._get_visitor_from_request() if visitor: excluded_products = website.sale_get_order().order_line.product_id.ids - tracked_products = self.env['website.track'].sudo().read_group( + tracked_products = self.env['website.track'].sudo()._read_group( [('visitor_id', '=', visitor.id), ('product_id', '!=', False), ('product_id.website_published', '=', True), ('product_id', 'not in', excluded_products)], ['product_id', 'visit_datetime:max'], ['product_id'], limit=limit, orderby='visit_datetime DESC') products_ids = [product['product_id'][0] for product in tracked_products] diff --git a/addons/website_sale/models/website_visitor.py b/addons/website_sale/models/website_visitor.py index 37d7af38781..42704ff4c95 100644 --- a/addons/website_sale/models/website_visitor.py +++ b/addons/website_sale/models/website_visitor.py @@ -20,7 +20,7 @@ class WebsiteVisitor(models.Model): @api.depends('website_track_ids') def _compute_product_statistics(self): - results = self.env['website.track'].read_group( + results = self.env['website.track']._read_group( [('visitor_id', 'in', self.ids), ('product_id', '!=', False), '|', ('product_id.company_id', 'in', self.env.companies.ids), ('product_id.company_id', '=', False)], ['visitor_id', 'product_id'], ['visitor_id', 'product_id'], diff --git a/addons/website_sale_digital/models/product.py b/addons/website_sale_digital/models/product.py index c642f1aca69..ec6329b80c0 100644 --- a/addons/website_sale_digital/models/product.py +++ b/addons/website_sale_digital/models/product.py @@ -10,7 +10,7 @@ class ProductTemplate(models.Model): attachment_count = fields.Integer(compute='_compute_attachment_count', string="File") def _compute_attachment_count(self): - attachment_data = self.env['ir.attachment'].read_group([('res_model', '=', self._name), ('res_id', 'in', self.ids), ('product_downloadable', '=', True)], ['res_id'], ['res_id']) + attachment_data = self.env['ir.attachment']._read_group([('res_model', '=', self._name), ('res_id', 'in', self.ids), ('product_downloadable', '=', True)], ['res_id'], ['res_id']) mapped_data = dict([(data['res_id'], data['res_id_count']) for data in attachment_data]) for product_template in self: product_template.attachment_count = mapped_data.get(product_template.id, 0) diff --git a/addons/website_sale_slides/models/slide_channel.py b/addons/website_sale_slides/models/slide_channel.py index da503a966ef..e1817ba25cd 100644 --- a/addons/website_sale_slides/models/slide_channel.py +++ b/addons/website_sale_slides/models/slide_channel.py @@ -34,7 +34,7 @@ class Channel(models.Model): ] rg_data = dict( (item['product_id'][0], item['price_total']) - for item in self.env['sale.report'].read_group(domain, ['product_id', 'price_total'], ['product_id']) + for item in self.env['sale.report']._read_group(domain, ['product_id', 'price_total'], ['product_id']) ) for channel in self: channel.product_sale_revenues = rg_data.get(channel.product_id.id, 0) diff --git a/addons/website_slides/models/res_partner.py b/addons/website_slides/models/res_partner.py index 7787e7d3b70..d1001e492b7 100644 --- a/addons/website_slides/models/res_partner.py +++ b/addons/website_slides/models/res_partner.py @@ -38,7 +38,7 @@ class ResPartner(models.Model): @api.depends('is_company') def _compute_slide_channel_count(self): - read_group_res = self.env['slide.channel.partner'].sudo().read_group( + read_group_res = self.env['slide.channel.partner'].sudo()._read_group( [('partner_id', 'in', self.ids)], ['partner_id'], 'partner_id' ) diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 28e85a4fada..507b13f695d 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -46,7 +46,7 @@ class ChannelUsersRelation(models.Model): ] def _recompute_completion(self): - read_group_res = self.env['slide.slide.partner'].sudo().read_group( + read_group_res = self.env['slide.slide.partner'].sudo()._read_group( ['&', '&', ('channel_id', 'in', self.mapped('channel_id').ids), ('partner_id', 'in', self.mapped('partner_id').ids), ('completed', '=', True), @@ -286,14 +286,14 @@ class Channel(models.Model): @api.depends('channel_partner_ids.channel_id') def _compute_members_count(self): - read_group_res = self.env['slide.channel.partner'].sudo().read_group([('channel_id', 'in', self.ids)], ['channel_id'], 'channel_id') + read_group_res = self.env['slide.channel.partner'].sudo()._read_group([('channel_id', 'in', self.ids)], ['channel_id'], 'channel_id') data = dict((res['channel_id'][0], res['channel_id_count']) for res in read_group_res) for channel in self: channel.members_count = data.get(channel.id, 0) @api.depends('channel_partner_ids.channel_id', 'channel_partner_ids.completed') def _compute_members_done_count(self): - read_group_res = self.env['slide.channel.partner'].sudo().read_group(['&', ('channel_id', 'in', self.ids), ('completed', '=', True)], ['channel_id'], 'channel_id') + read_group_res = self.env['slide.channel.partner'].sudo()._read_group(['&', ('channel_id', 'in', self.ids), ('completed', '=', True)], ['channel_id'], 'channel_id') data = dict((res['channel_id'][0], res['channel_id_count']) for res in read_group_res) for channel in self: channel.members_done_count = data.get(channel.id, 0) @@ -336,7 +336,7 @@ class Channel(models.Model): default_vals.update(dict((key, 0) for key in keys)) result = dict((cid, dict(default_vals)) for cid in self.ids) - read_group_res = self.env['slide.slide'].read_group( + read_group_res = self.env['slide.slide']._read_group( [('active', '=', True), ('is_published', '=', True), ('channel_id', 'in', self.ids), ('is_category', '=', False)], ['channel_id', 'slide_category', 'likes', 'dislikes', 'total_views', 'completion_time'], groupby=['channel_id', 'slide_category'], diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index 93f909d91de..16e7039542d 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -310,7 +310,7 @@ class Slide(models.Model): @api.depends('slide_partner_ids.slide_id') def _compute_slide_views(self): # TODO awa: tried compute_sudo, for some reason it doesn't work in here... - read_group_res = self.env['slide.slide.partner'].sudo().read_group( + read_group_res = self.env['slide.slide.partner'].sudo()._read_group( [('slide_id', 'in', self.ids)], ['slide_id'], groupby=['slide_id'] @@ -324,7 +324,7 @@ class Slide(models.Model): mapped_data = {} if self.ids: - read_group_res = self.env['slide.embed'].read_group( + read_group_res = self.env['slide.embed']._read_group( [('slide_id', 'in', self.ids)], ['count_views'], ['slide_id'] @@ -344,7 +344,7 @@ class Slide(models.Model): keys = ['nbr_%s' % slide_category for slide_category in self.env['slide.slide']._fields['slide_category'].get_values(self.env)] default_vals = dict((key, 0) for key in keys + ['total_slides']) - res = self.env['slide.slide'].read_group( + res = self.env['slide.slide']._read_group( [('is_published', '=', True), ('category_id', 'in', self.ids), ('is_category', '=', False)], ['category_id', 'slide_category'], ['category_id', 'slide_category'], lazy=False)