def _synchronize_cron(cr, registry): env = Environment(cr, SUPERUSER_ID, {'active_test': False}) cron = env.ref('crm_iap_lead_enrich.ir_cron_lead_enrichment') if cron: config = env['ir.config_parameter'].get_param( 'crm.iap.lead.enrich.setting', 'manual') cron.active = config != 'manual'
def post_init_hook(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) res_ids = env['ir.model.data'].search([ ('model', '=', 'ir.ui.menu'), ('module', '=', 'sale'), ]).mapped('res_id') env['ir.ui.menu'].browse(res_ids).update({'active': True})
def post_init_hook(cr, registry): _logger.info("Compute discount columns") env = Environment(cr, SUPERUSER_ID, {}) query = """ update sale_order_line set price_total_no_discount = price_total where discount = 0.0 """ cr.execute(query) query = """ update sale_order set price_total_no_discount = amount_total """ cr.execute(query) query = """ select distinct order_id from sale_order_line where discount > 0.0; """ cr.execute(query) order_ids = cr.fetchall() orders = env["sale.order"].search([("id", "in", order_ids)]) orders.mapped("order_line")._update_discount_display_fields()
def declined(self, db, token, action, id): registry = registry_get(db) with registry.cursor() as cr: env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].search([ ('access_token', '=', token), ('state', '!=', 'declined') ]) if attendee: attendee.do_decline() return self.view(db, token, action, id, view='form')
def poll(self, channels, last, options=None): if request.env.user.has_group('base.group_user'): ip_address = request.httprequest.remote_addr users_log = request.env['res.users.log'].search_count([ ('create_uid', '=', request.env.user.id), ('ip', '=', ip_address), ('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0))) ]) if not users_log: with registry(request.env.cr.dbname).cursor() as cr: env = Environment(cr, request.env.user.id, {}) env['res.users.log'].create({'ip': ip_address}) return super(BusController, self).poll(channels, last, options=options)
def _auth_method_calendar(cls): token = request.params['token'] dbname = request.params['db'] registry = harpiya.registry(dbname) error_message = False with registry.cursor() as cr: env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].sudo().search([('access_token', '=', token)], limit=1) if not attendee: error_message = """Invalid Invitation Token.""" elif request.session.uid and request.session.login != 'anonymous': # if valid session but user is not match user = env['res.users'].sudo().browse(request.session.uid) if attendee.partner_id != user.partner_id: error_message = """Invitation cannot be forwarded via email. This event/meeting belongs to %s and you are logged in as %s. Please ask organizer to add you.""" % (attendee.email, user.email) if error_message: raise BadRequest(error_message) return True
def view(self, db, token, action, id, view='calendar'): registry = registry_get(db) with registry.cursor() as cr: # Since we are in auth=none, create an env with SUPERUSER_ID env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].search([ ('access_token', '=', token), ('event_id', '=', int(id)) ]) if not attendee: return request.not_found() timezone = attendee.partner_id.tz lang = attendee.partner_id.lang or get_lang(request.env).code event = env['calendar.event'].with_context(tz=timezone, lang=lang).browse( int(id)) # If user is internal and logged, redirect to form view of event # otherwise, display the simplifyed web page with event informations if request.session.uid and request.env['res.users'].browse( request.session.uid).user_has_groups('base.group_user'): return werkzeug.utils.redirect( '/web?db=%s#id=%s&view_type=form&model=calendar.event' % (db, id)) # NOTE : we don't use request.render() since: # - we need a template rendering which is not lazy, to render before cursor closing # - we need to display the template in the language of the user (not possible with # request.render()) response_content = env['ir.ui.view'].with_context( lang=lang).render_template( 'calendar.invitation_page_anonymous', { 'event': event, 'attendee': attendee, }) return request.make_response(response_content, headers=[('Content-Type', 'text/html') ])