Best Python code snippet using tavern
project_task_type_delete.py
Source:project_task_type_delete.py
1# -*- coding: utf-8 -*-2# Part of Odoo. See LICENSE file for full copyright and licensing details.3from odoo import api, fields, models, _4from odoo.exceptions import ValidationError5import ast6class ProjectTaskTypeDelete(models.TransientModel):7 _name = 'project.task.type.delete.wizard'8 _description = 'Project Stage Delete Wizard'9 project_ids = fields.Many2many('project.project', domain="['|', ('active', '=', False), ('active', '=', True)]", string='Projects', ondelete='cascade')10 stage_ids = fields.Many2many('project.task.type', string='Stages To Delete', ondelete='cascade')11 tasks_count = fields.Integer('Number of tasks', compute='_compute_tasks_count')12 stages_active = fields.Boolean(compute='_compute_stages_active')13 @api.depends('project_ids')14 def _compute_tasks_count(self):15 for wizard in self:16 wizard.tasks_count = self.with_context(active_test=False).env['project.task'].search_count([('stage_id', 'in', wizard.stage_ids.ids)])17 @api.depends('stage_ids')18 def _compute_stages_active(self):19 for wizard in self:20 wizard.stages_active = all(wizard.stage_ids.mapped('active'))21 def action_archive(self):22 if len(self.project_ids) <= 1:23 return self.action_confirm()24 return {25 'name': _('Confirmation'),26 'view_mode': 'form',27 'res_model': 'project.task.type.delete.wizard',28 'views': [(self.env.ref('project.view_project_task_type_delete_confirmation_wizard').id, 'form')],29 'type': 'ir.actions.act_window',30 'res_id': self.id,31 'target': 'new',32 'context': self.env.context,33 }34 def action_confirm(self):35 tasks = self.with_context(active_test=False).env['project.task'].search([('stage_id', 'in', self.stage_ids.ids)])36 tasks.write({'active': False})37 self.stage_ids.write({'active': False})38 return self._get_action()39 def action_unlink(self):40 self.stage_ids.unlink()41 return self._get_action()42 def _get_action(self):43 project_id = self.env.context.get('default_project_id')44 if project_id:45 action = self.env["ir.actions.actions"]._for_xml_id("project.action_view_task")46 action['domain'] = [('project_id', '=', project_id)]47 action['context'] = str({48 'pivot_row_groupby': ['user_id'],49 'default_project_id': project_id,50 })51 elif self.env.context.get('stage_view'):52 action = self.env["ir.actions.actions"]._for_xml_id("project.open_task_type_form")53 else:54 action = self.env["ir.actions.actions"]._for_xml_id("project.action_view_all_task")55 context = dict(ast.literal_eval(action.get('context')), active_test=True)56 action['context'] = context57 action['target'] = 'main'...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!