def plan_stat_button(self, domain, res_model='account.analytic.line'): action = { 'type': 'ir.actions.act_window', 'view_id': False, 'view_mode': 'tree,form', 'view_type': 'list', 'domain': domain, } if res_model == 'account.analytic.line': ts_view_tree_id = request.env.ref( 'hr_timesheet.hr_timesheet_line_tree').id ts_view_form_id = request.env.ref( 'hr_timesheet.hr_timesheet_line_form').id action = { 'name': _('Timesheets'), 'type': 'ir.actions.act_window', 'res_model': res_model, 'view_mode': 'tree,form', 'view_type': 'form', 'views': [[ts_view_tree_id, 'list'], [ts_view_form_id, 'form']], 'domain': domain, } elif res_model == 'project.task': action = request.env.ref('project.action_view_task').read()[0] action.update({ 'name': _('Tasks'), 'domain': domain, 'context': dict(request.env.context ), # erase original context to avoid default filter }) # if only one project, add it in the context as default value tasks = request.env['project.task'].sudo().search( literal_eval(domain)) if len(tasks.mapped('project_id')) == 1: action['context']['default_project_id'] = tasks.mapped( 'project_id')[0].id elif res_model == 'sale.order': action = clean_action( request.env.ref('sale.action_orders').read()[0]) action['domain'] = domain action['context'] = { 'create': False, 'edit': False, 'delete': False } # No CRUD operation when coming from overview elif res_model == 'account.invoice': action = clean_action( request.env.ref('account.action_invoice_tree1').read()[0]) action['domain'] = domain action['context'] = { 'create': False, 'edit': False, 'delete': False } # No CRUD operation when coming from overview return action
def plan_stat_button(self, domain=[], res_model='account.analytic.line', res_id=False): action = { 'type': 'ir.actions.act_window', 'view_id': False, 'view_mode': 'tree,form', 'view_type': 'list', 'domain': domain, } if res_model == 'project.project': view_form_id = request.env.ref('project.edit_project').id action = { 'name': _('Project'), 'type': 'ir.actions.act_window', 'res_model': res_model, 'view_mode': 'form', 'view_type': 'form', 'views': [[view_form_id, 'form']], 'res_id': res_id, } elif res_model == 'account.analytic.line': ts_view_tree_id = request.env.ref('hr_timesheet.hr_timesheet_line_tree').id ts_view_form_id = request.env.ref('hr_timesheet.hr_timesheet_line_form').id action = { 'name': _('Timesheets'), 'type': 'ir.actions.act_window', 'res_model': res_model, 'view_mode': 'tree,form', 'view_type': 'form', 'views': [[ts_view_tree_id, 'list'], [ts_view_form_id, 'form']], 'domain': domain, } elif res_model == 'project.task': action = request.env.ref('project.action_view_task').read()[0] action.update({ 'name': _('Tasks'), 'domain': domain, 'context': dict(request.env.context), # erase original context to avoid default filter }) # if only one project, add it in the context as default value tasks = request.env['project.task'].sudo().search(literal_eval(domain)) if len(tasks.mapped('project_id')) == 1: action['context']['default_project_id'] = tasks.mapped('project_id')[0].id elif res_model == 'sale.order': action = clean_action(request.env.ref('sale.action_orders').read()[0]) action['domain'] = domain action['context'] = {'create': False, 'edit': False, 'delete': False} # No CRUD operation when coming from overview elif res_model == 'account.invoice': action = clean_action(request.env.ref('account.action_invoice_tree1').read()[0]) action['domain'] = domain action['context'] = {'create': False, 'delete': False} # only edition of invoice from overview return action
def _clean_action(action, env): action_type = action.setdefault('type', 'ir.actions.act_window_close') if action_type in ('ir.actions.act_window.message', 'ir.actions.act_multi', 'ir.actions.act_view_reload'): return action else: return clean_action(action, env)
def incall_notify_by_login(self, number, login_list): assert isinstance(login_list, list), 'login_list must be a list' res = self.get_record_from_phone_number(number) users = self.env['res.users'].search([('login', 'in', login_list)]) logger.info('Notify incoming call from number %s to user IDs %s' % (number, users.ids)) action = self._prepare_incall_pop_action(res, number) action = clean_action(action) if action: for user in users: channel = 'notify_info_%s' % user.id bus_message = { 'message': _('Here is my message'), 'title': _('Incoming call'), 'action': action, # 'sticky': True, 'action_link_name': 'action_link_name', } self.sudo().env['bus.bus'].sendone(channel, bus_message) logger.debug('This action has been sent to user ID %d: %s' % (user.id, action)) if res: callerid = res[2] else: callerid = False return callerid
def trigger_actions(self, file_ids): model = self.env['ag_dms.file'] files = model.browse(file_ids) action_result = False for record in self: values = {} if record.set_directory: values['directory'] = record.set_directory.id if record.set_category: values['category'] = record.set_category.id if record.set_tags: values['tags'] = [(4, tag.id) for tag in record.set_tags] files.write(values) if record.set_category: for file in files: tags_to_remove = file.tags.filtered( lambda rec: rec.category and \ rec.category != file.category ) file.write({'tags': [(3, tag.id) for tag in tags_to_remove]}) action_result = self._run_action(record, files) server_action_context = {'active_model': files._name} if len(files) == 1: server_action_context['active_id'] = files.id if len(files) >= 1: server_action_context['active_ids'] = file_ids server_action = record.server_actions.with_context( **server_action_context).run() action_result = server_action if not action_result else action_result return clean_action(action_result) if action_result else False
def _to_action_data(model=None, *, action=None, views=None, res_id=None, domain=None, context=None): # pass in either action or (model, views) if action: assert model is None and views is None act = clean_action(action.read()[0]) model = act['res_model'] views = act['views'] # FIXME: search-view-id, possibly help? descr = { 'data-model': model, 'data-views': json.dumps(views), } if context is not None: # otherwise copy action's? descr['data-context'] = json.dumps(context) if res_id: descr['data-res-id'] = res_id elif domain: descr['data-domain'] = json.dumps(domain) return descr
def validate(self): '''Method called from the button action 'Validate' on the authentication wizard. ''' value = False userVerify = False try: userVerify = self.validate_credentials(self.password) if userVerify and self.env.context.get('action_auth_id'): action_id = self.env.context['action_auth_id'] Actions = request.env['ir.actions.actions'] base_action = Actions.browse([action_id]).read(['type']) if base_action: ctx = dict(request.context) action_type = base_action[0]['type'] if action_type == 'ir.actions.report.xml': ctx.update({'bin_size': True}) action = request.env[action_type].browse([action_id ]).read() if action: value = main.clean_action(action[0]) return value else: raise ValidationError("Incorrect Password") except ValidationError: raise ValidationError( "Incorrect Password. Please contact your administrator to enable the access." ) except Exception as e: _logger.warning("An error has occured while validating. Error %s" % (repr(e))) raise ValidationError( "There might be an error in re-directing the form or validating the Password. \nPlease remove the security on this Menu." )
def open_analytic_entries(self, options, params): action = self.env["ir.actions.actions"]._for_xml_id("analytic.account_analytic_line_action") action = clean_action(action, env=self.env) action['context'] = { 'active_id': int(params['id'].split('analytic_account_')[1]), } return action
def _to_action_data(model=None, *, action=None, views=None, res_id=None, domain=None, context=None): # pass in either action or (model, views) if action: assert model is None and views is None act = { field: value for field, value in action.sudo().read()[0].items() if field in action._get_readable_fields() } act = clean_action(act, env=action.env) model = act['res_model'] views = act['views'] # FIXME: search-view-id, possibly help? descr = { 'data-model': model, 'data-views': json.dumps(views), } if context is not None: # otherwise copy action's? descr['data-context'] = json.dumps(context) if res_id: descr['data-res-id'] = res_id elif domain: descr['data-domain'] = json.dumps(domain) return descr
def open_picking(self, options, params): action = self.env.ref("stock.view_picking_form").read()[0] action["views"] = [(self.env.ref("stock.view_picking_form").id, "form") ] action["res_id"] = int(params.get("id").split("_")[0]) action = clean_action(action) return action
def open_analytic_entries(self, options, params): action = self.env.ref( 'analytic.account_analytic_line_action').read()[0] action = clean_action(action) action['context'] = { 'active_id': int(params['id'].split('analytic_account_')[1]), } return action
def open_analytic_entries(self, options, params): aa_id = params.get('aa_id') action = self.env.ref( 'analytic.account_analytic_line_action').read()[0] action = clean_action(action) action['context'] = { 'active_id': aa_id, } return action
def open_invoices(self, options, params): partner_id = int(params.get('id').split('_')[0]) [action] = self.env.ref('account.action_invoice_tree1').read() action['context'] = self.env.context action['domain'] = [('partner_id', '=', partner_id), ('date', '<=', options.get('date').get('date_to')), ('date', '>=', options.get('date').get('date_from'))] action = clean_action(action) return action
def _notify_channel(self, channel_name_field, message, title, **options): if options.get('action'): options['action'] = clean_action(options['action']) bus_message = { 'message': message, 'title': title, } bus_message.update(options) notifications = [(getattr(record, channel_name_field), bus_message) for record in self] self.env['bus.bus'].sendmany(notifications)
def open_tax_lines(self, options, params): tax_id = int(params.get('id').split('_')[0]) [action ] = self.env.ref('account.action_move_line_select_tax_audit').read() action['context'] = self.env.context action['domain'] = [('tax_line_id', '=', tax_id), ('tax_exigible', '=', True), ('date', '<=', options.get('date').get('date_to')), ('date', '>=', options.get('date').get('date_from'))] action = clean_action(action) return action
def open_journal_items(self, options, params): action = self.env.ref('account.action_move_line_select').read()[0] action = clean_action(action) ctx = self.env.context.copy() if params and 'id' in params: active_id = params['id'] ctx.update({ 'search_default_account_id': [active_id], }) action['context'] = ctx return action
def open_tax(self, options, params=None): active_id = int(str(params.get('id')).split('_')[0]) domain = [('date', '>=', options.get('date').get('date_from')), ('date', '<=', options.get('date').get('date_to')), '|', ('tax_ids', 'in', [active_id]), ('tax_line_id', 'in', [active_id])] if not options.get('all_entries'): domain.append(('move_id.state', '=', 'posted')) action = self.env.ref('account.action_move_line_select_tax_audit').read()[0] ctx = self.env.context.copy() ctx.update({'active_id': active_id,}) action = clean_action(action) action['domain'] = domain action['context'] = ctx return action
def view_too_many(self, options, params=None): model, active_id = params.get('actionId').split(',') ctx = self.env.context.copy() if model == 'journal': action = self.env.ref('account.action_move_line_select').read()[0] ctx.update({ 'search_default_journal_id': [int(active_id)], 'default_journal_id': [int(active_id)], 'active_id': int(active_id), }) action = clean_action(action) action['context'] = ctx return action return super().view_too_many(options, params)
def call_button(self, model, method, args, domain_id=None, context_id=None): # check if the current model inherit from workflow.model parents = request.env[model]._inherit parents = [parents] if isinstance(parents, str) else (parents or []) if 'workflow.model' in parents: workflow = request.env['workflow.workflow'].search([('model_id','=',model)]) if workflow: action = request.env[model].trigger_transition(model, method, args, {}) else: action = self._call_kw(model, method, args, {}) if isinstance(action, dict) and action.get('type') != '': return main.clean_action(action) return False
def _notify_channel(self, channel_name_field, message, title, **options): if (self.env.uid != SUPERUSER_ID and any(user.id != self.env.uid for user in self)): raise exceptions.UserError( _('Sending a notification to another user is forbidden.')) if options.get('action'): options['action'] = clean_action(options['action']) bus_message = { 'message': message, 'title': title, } bus_message.update(options) notifications = [(getattr(record, channel_name_field), bus_message) for record in self] self.env['bus.bus'].sendmany(notifications)
def plan_stat_button(self, domain=None, res_model="account.analytic.line", res_id=False): if domain is None: domain = [] res = super(SaleTimesheetControllerNew, self).plan_stat_button(domain=domain, res_model=res_model, res_id=res_id) if res_model == "purchase.order": res = clean_action( request.env.ref("purchase.purchase_form_action").read()[0]) res["domain"] = domain res["context"] = {"create": False, "delete": False} return res
def _action_open_data(self, model, action=False, domain=False, **kwargs): self.ensure_one() if action: action = action.read([])[0] else: action = { 'name': self.name, 'type': 'ir.actions.act_window', 'res_model': model, 'view_mode': 'tree,form', } if domain: action['domain'] = domain return clean_action(action)
def _to_action_data(model=None, *, action=None, views=None, res_id=None, domain=None, context=None): # pass in either action or (model, views) if action: assert model is None and views is None act = clean_action(action.read()[0]) model = act['res_model'] views = act['views'] # FIXME: search-view-id, possibly help? descr = { 'data-model': model, 'data-views': json.dumps(views), } if context is not None: # otherwise copy action's? descr['data-context'] = json.dumps(context) if res_id: descr['data-res-id'] = res_id elif domain: descr['data-domain'] = json.dumps(domain) return descr
def load(self, **args): try: action_id = int(request.params.get('action_id')) Actions = request.env['ir.actions.actions'] value = False try: action_id = int(action_id) except ValueError: try: action = request.env.sudo().ref(action_id) assert action._name.startswith('ir.actions.') action_id = action.id except Exception: action_id = 0 # force failed read base_action = Actions.sudo().browse([action_id]).read(['type']) if base_action: ctx = dict(request.context) action_type = base_action[0]['type'] if action_type == 'ir.actions.report.xml': ctx.update({'bin_size': True}) request.context = ctx action = request.env[action_type].sudo().browse([action_id ]).read() if action: value = clean_action(action[0]) fields = request.env[value.get('res_model')].sudo().fields_get( allfields=None, attributes=None) views = request.env[value.get('res_model')].sudo().load_views( views=value.get('views')) return request.make_response( simplejson.dumps({ 'action': value, 'views': views, 'fields': fields })) except Exception: return request.make_response(simplejson.dumps({}))
def open_journal_items(self, options, params): action = self.env.ref('account.action_move_line_select').read()[0] action = clean_action(action) ctx = self.env.context.copy() if params and 'id' in params: active_id = params['id'] ctx.update({ 'search_default_account_id': [active_id], }) action['context'] = ctx if options: domain = expression.normalize_domain(safe_eval(action.get('domain', '[]'))) if options.get('analytic_accounts'): analytic_ids = [int(r) for r in options['analytic_accounts']] domain = expression.AND([domain, [('analytic_account_id', 'in', analytic_ids)]]) if options.get('date'): opt_date = options['date'] if opt_date.get('date_from'): domain = expression.AND([domain, [('date', '>=', opt_date['date_from'])]]) if opt_date.get('date_to'): domain = expression.AND([domain, [('date', '<=', opt_date['date_to'])]]) action['domain'] = domain return action
def _plan_get_stat_button(self): stat_buttons = super()._plan_get_stat_button() if not any(self.mapped('allow_forecast')): return stat_buttons action = clean_action(self.env.ref('project_forecast.project_forecast_action_by_project').read()[0]) context = literal_eval(action['context']) if len(self) == 1: context.update({'default_project_id': self.id}) context.update({'search_default_future': 0}) action['context'] = context stat_buttons.append({ 'name': _('Planning'), 'icon': 'fa fa-tasks', 'action': { 'data-model': 'planning.slot', 'data-domain': json.dumps([('project_id', 'in', self.ids)]), 'data-context': json.dumps(action['context']), 'data-views': json.dumps(action['views']) } }) return stat_buttons