[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 <rco@odoo.com>
This commit is contained in:
Vincent Schippefilt
2022-03-02 17:10:48 +00:00
committed by Raphael Collet
parent 4ef0c00b4b
commit 05fc9a6733
113 changed files with 194 additions and 194 deletions
+2 -2
View File
@@ -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'],
@@ -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)
@@ -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'],
@@ -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)
+1 -1
View File
@@ -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)
@@ -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:
+1 -1
View File
@@ -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'),
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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'],
+1 -1
View File
@@ -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']
+3 -3
View File
@@ -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'),
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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}
@@ -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:
+1 -1
View File
@@ -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
)
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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'],
+1 -1
View File
@@ -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']
+1 -1
View File
@@ -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}
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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'])
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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}
@@ -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)
+3 -3
View File
@@ -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'])
+2 -2
View File
@@ -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'),
@@ -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'],
+3 -3
View File
@@ -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)
@@ -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)
+2 -2
View File
@@ -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)
@@ -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)
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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']
@@ -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),
+1 -1
View File
@@ -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
@@ -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}
+1 -1
View File
@@ -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']
+1 -1
View File
@@ -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'])
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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'])
+3 -3
View File
@@ -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'],
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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'],
@@ -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'],
)
@@ -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}
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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)
+5 -5
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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'],
+1 -1
View File
@@ -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']
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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'])
+1 -1
View File
@@ -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)
+8 -8
View File
@@ -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 = {
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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)
],
+1 -1
View File
@@ -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'])
@@ -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),
+1 -1
View File
@@ -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:
+2 -2
View File
@@ -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']
+1 -1
View File
@@ -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}
+2 -2
View File
@@ -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'])
+2 -2
View File
@@ -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()
+1 -1
View File
@@ -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']
)
+1 -1
View File
@@ -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}
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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']),
+3 -3
View File
@@ -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)],
+3 -3
View File
@@ -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',
+1 -1
View File
@@ -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)
+12 -12
View File
@@ -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
+4 -4
View File
@@ -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'])
+1 -1
View File
@@ -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:
+3 -3
View File
@@ -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'],
)
+4 -4
View File
@@ -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)
+3 -3
View File
@@ -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))
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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')
@@ -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 {
+1 -1
View File
@@ -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])
@@ -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 = {
+1 -1
View File
@@ -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'
)
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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']}
@@ -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}
@@ -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']
)
@@ -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(
@@ -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)
@@ -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"],

Some files were not shown because too many files have changed in this diff Show More