Files
odoo_source/addons/project/wizard/project_delete_wizard.py
T
Victor Feyens c482fdbf05 [IMP] various: improve code style and performance by improve `all()` usage
PURPOSE

Clean code. Be more performance oriented.

SPECIFICATIONS

Improvements applied in this commit

  * not all() --> any(not) for earlier returns;
  * all([generator]) --> all(generator) to avoid unnecessary list casting.
    This code construct is better managed by all;

This commit will probably not have a big performance effect on standard
production databases. However each performance and cleaning improvement
is welcomed.

LINKS

Task ID-2328619

closes odoo/odoo#56810

X-original-commit: 1cc6bb1231401ea7f501d2f5b5e9641ec8734850
Related: odoo/enterprise#12802
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-08-31 13:59:27 +00:00

29 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class ProjectDelete(models.TransientModel):
_name = 'project.delete.wizard'
_description = 'Project Delete Wizard'
project_ids = fields.Many2many('project.project', string='Projects')
task_count = fields.Integer(compute='_compute_task_count')
projects_archived = fields.Boolean(compute='_compute_projects_archived')
def _compute_projects_archived(self):
for wizard in self.with_context(active_test=False):
wizard.projects_archived = all(not p.active for p in wizard.project_ids)
def _compute_task_count(self):
for wizard in self:
wizard.task_count = sum(wizard.with_context(active_test=False).project_ids.mapped('task_count'))
def action_archive(self):
self.project_ids.write({'active': False})
def confirm_delete(self):
self.with_context(active_test=False).project_ids.unlink()
return self.env["ir.actions.actions"]._for_xml_id("project.open_view_project_all_config")