예제 #1
0
    def doc_notification(self, req, db, token):

        # Status 1 is received every user connection to or disconnection from document co-editing.
        # Status 2 (3) is received 10 seconds after the document is closed for editing by the last user.
        # Status 4 is received after the document is closed for editing with no
        # changes by the last user.

        if req.JsonRawRequest['status'] == 1:
            return {"error": 0}
        if req.JsonRawRequest['status'] == 4:
            return {"error": 0}

        registry = RegistryManager.get(db)
        with registry.cursor() as cr:
            try:
                # find user via token
                u = registry.get('res.users')
                u_id = u.search(cr, openerp.SUPERUSER_ID,
                                [('auth_token', '=', token)])

                a = registry.get('ir.attachment')
                a.download_and_overwrite(cr, u_id[0],
                                         req.JsonRawRequest['key'],
                                         req.JsonRawRequest['url'])
            except Exception, e:
                # signup error
                _logger.exception("Auth: %s" % str(e))
예제 #2
0
    def download_attachment_pdf(self, model, id, method, attachment_id,
                                auth_token, db, **kw):
        # FIXME use /web/binary/saveas directly

        dbname = db
        registry = RegistryManager.get(dbname)
        Model = registry.get('project.project')
        with registry.cursor() as cr:
            try:
                # find user via token
                u = registry.get('res.users')
                u_id = u.search(cr, openerp.SUPERUSER_ID,
                                [('auth_token', '=', auth_token)])

                res = getattr(Model, method)(cr, u_id[0], int(id),
                                             int(attachment_id))
                if res:
                    filecontent = base64.b64decode(res.get('base64'))
                    filename = res.get('filename')
                    content_type = mimetypes.guess_type(filename)
                    if filecontent and filename:
                        return request.make_response(
                            filecontent,
                            headers=[('Content-Type', content_type[0]
                                      or 'application/pdf'),
                                     ('Content-Disposition',
                                      content_disposition(filename).replace(
                                          "attachment;", "inline;"))]
                        )  # open pdf files inline instead of downloading them
            except Exception, e:
                # signup error
                _logger.exception("OAuth2: %s" % str(e))
예제 #3
0
def module_installed_bypass_session(dbname):
    loadable = http.addons_manifest.keys()
    modules = {}
    try:
        registry = openerp.modules.registry.RegistryManager.get(dbname)
        with registry.cursor() as cr:
            m = registry.get('ir.module.module')
            # TODO The following code should move to ir.module.module.list_installed_modules()
            domain = [('state','=','installed'), ('name','in', loadable)]
            ids = m.search(cr, 1, [('state','=','installed'), ('name','in', loadable)])
            for module in m.read(cr, 1, ids, ['name', 'dependencies_id']):
                modules[module['name']] = []
                deps = module.get('dependencies_id')
                if deps:
                    deps_read = registry.get('ir.module.module.dependency').read(cr, 1, deps, ['name'])
                    dependencies = [i['name'] for i in deps_read]
                    modules[module['name']] = dependencies
    except Exception,e:
        pass
예제 #4
0
def module_installed_bypass_session(dbname):
    loadable = http.addons_manifest.keys()
    modules = {}
    try:
        registry = openerp.modules.registry.RegistryManager.get(dbname)
        with registry.cursor() as cr:
            m = registry.get('ir.module.module')
            # TODO The following code should move to ir.module.module.list_installed_modules()
            domain = [('state','=','installed'), ('name','in', loadable)]
            ids = m.search(cr, 1, [('state','=','installed'), ('name','in', loadable)])
            for module in m.read(cr, 1, ids, ['name', 'dependencies_id']):
                modules[module['name']] = []
                deps = module.get('dependencies_id')
                if deps:
                    deps_read = registry.get('ir.module.module.dependency').read(cr, 1, deps, ['name'])
                    dependencies = [i['name'] for i in deps_read]
                    modules[module['name']] = dependencies
    except Exception,e:
        pass
예제 #5
0
    def poll(self,
             last=None,
             users_watch=None,
             db=None,
             uid=None,
             password=None,
             uuid=None):
        assert_uuid(uuid)
        if not openerp.evented:
            raise Exception("Not usable in a server not running gevent")
        from openerp.addons.im.watcher import ImWatcher
        if db is not None:
            openerp.service.security.check(db, uid, password)
        else:
            uid = request.session.uid
            db = request.session.db

        registry = openerp.modules.registry.RegistryManager.get(db)
        with registry.cursor() as cr:
            registry.get('im.user').im_connect(cr,
                                               uid,
                                               uuid=uuid,
                                               context=request.context)
            my_id = registry.get('im.user').get_my_id(cr, uid, uuid,
                                                      request.context)
        num = 0
        while True:
            with registry.cursor() as cr:
                res = registry.get('im.message').get_messages(
                    cr,
                    uid,
                    last,
                    users_watch,
                    uuid=uuid,
                    context=request.context)
            if num >= 1 or len(res["res"]) > 0:
                return res
            last = res["last"]
            num += 1
            ImWatcher.get_watcher(res["dbname"]).stop(my_id, users_watch or [],
                                                      POLL_TIMER)
예제 #6
0
파일: im.py 프로젝트: Ichag/openerp-addons
    def poll(self, last=None, users_watch=None, db=None, uid=None, password=None, uuid=None):
        assert_uuid(uuid)
        if not openerp.evented:
            raise Exception("Not usable in a server not running gevent")
        from openerp.addons.im.watcher import ImWatcher
        if db is not None:
            openerp.service.security.check(db, uid, password)
        else:
            uid = request.session.uid
            db = request.session.db

        registry = openerp.modules.registry.RegistryManager.get(db)
        with registry.cursor() as cr:
            registry.get('im.user').im_connect(cr, uid, uuid=uuid, context=request.context)
            my_id = registry.get('im.user').get_my_id(cr, uid, uuid, request.context)
        num = 0
        while True:
            with registry.cursor() as cr:
                res = registry.get('im.message').get_messages(cr, uid, last, users_watch, uuid=uuid, context=request.context)
            if num >= 1 or len(res["res"]) > 0:
                return res
            last = res["last"]
            num += 1
            ImWatcher.get_watcher(res["dbname"]).stop(my_id, users_watch or [], POLL_TIMER)
예제 #7
0
    def check_email(self, req, db):
        context = {}
        email = req.jsonrequest.get('email')
        if not email:
            return {"status": -1}

        registry = RegistryManager.get(db)

        with registry.cursor() as cr:
            try:
                p = registry.get('res.partner')
                p_id = p.search(cr, openerp.SUPERUSER_ID,
                                [('email', '=', email)])
                if len(p_id) == 0:  # email not found
                    return {"status": 0}
                else:
                    return {"status": 1}
            except Exception, e:
                return {"status": -1}
예제 #8
0
    def index(self, req, action, token):
        #         cr, uid, suid = request.cr, request.session.uid, openerp.SUPERUSER_ID
        action = simplejson.loads(action)

        report_srv = req.session.proxy("report")
        context = dict(req.context)
        context.update(action["context"])

        report_data = {}
        report_ids = context["active_ids"]
        if "report_type" in action:
            report_data["report_type"] = action["report_type"]
        if "datas" in action:
            if "ids" in action["datas"]:
                report_ids = action["datas"].pop("ids")
            report_data.update(action["datas"])

        report_id = report_srv.report(
            req.session._db,
            req.session._uid,
            req.session._password,
            action["report_name"],
            report_ids,
            report_data,
            context,
        )

        report_struct = None
        while True:
            report_struct = report_srv.report_get(req.session._db, req.session._uid, req.session._password, report_id)
            if report_struct["state"]:
                break

            time.sleep(self.POLLING_DELAY)

        report = base64.b64decode(report_struct["result"])
        if report_struct.get("code") == "zlib":
            report = zlib.decompress(report)
        report_mimetype = self.TYPES_MAPPING.get(report_struct["format"], "octet-stream")
        file_name = action.get("name", "report")
        if "name" not in action:
            reports = req.session.model("ir.actions.report.xml")
            res_id = reports.search([("report_name", "=", action["report_name"])], 0, False, False, context)
            if len(res_id) > 0:
                file_name = reports.read(res_id[0], ["name"], context)["name"]
            else:
                file_name = action["report_name"]
        file_name = "%s.%s" % (file_name, report_struct["format"])

        # Customization starts here
        if action["report_name"] == "Customer Invoice":

            registry = openerp.modules.registry.RegistryManager.get(req.session._db)
            with registry.cursor() as cr:
                inv_obj = registry.get("account.invoice")
                print "context.........", context, inv_obj
                for i in inv_obj.browse(cr, req.session._uid, context.get("active_ids")):
                    if "Logistics" in i.company_id.name:
                        file_name = "%s.%s" % ("Tax Invoice", report_struct["format"])

        return req.make_response(
            report,
            headers=[
                ("Content-Disposition", content_disposition(file_name, req)),
                ("Content-Type", report_mimetype),
                ("Content-Length", len(report)),
            ],
            cookies={"fileToken": token},
        )