Exemplo n.º 1
0
    def startRequestsTimer(self):
        # Every X minutes check for new requests and put the number of open
        # requests in the appropiate space in the status bar
        frequency = Settings.value('koo.requests_refresh_interval', 5 * 60,
                                   int) * 1000
        if frequency > 0:
            self.requestsTimer.start(frequency)
        else:
            self.requestsTimer.stop()

        # Check for new Koo releases after logging in.
        self.checkNewRelease()

        # We always use the Subscriber as the class itself will handle
        # whether the module exists on the server or not
        self.subscriber = Rpc.Subscriber(Rpc.session, self)
        # Subscribe to changes to res.request (if 'koo' module is installed in the server).
        self.subscriber.subscribe('updated_model:res.request',
                                  self.updateRequestsStatus)
Exemplo n.º 2
0
    def __init__(self,
                 model,
                 res_id=False,
                 domain=None,
                 view_type=None,
                 view_ids=None,
                 context=None,
                 parent=None,
                 name=False):
        QWidget.__init__(self, parent)
        FormWidgetUi.__init__(self)
        self.setupUi(self)

        if domain is None:
            domain = []
        if view_ids is None:
            view_ids = []
        if context is None:
            context = {}

        # This variable holds the id used to update status (and show number of attachments)
        # If it doesn't change we won't update the number of attachments, avoiding some server
        # calls.
        self.previousId = False
        self.previousAttachments = False

        # Workaround: In some cases (detected in some CRM actions) view_type and view_ids
        # may contain duplicate entries. Here we remove duplicates (ensuring lists order is kept).
        if view_type:
            new_view_ids = []
            new_view_type = []
            for i in range(len(view_type)):
                if not view_type[i] in new_view_type:
                    if i < len(view_ids):
                        new_view_ids.append(view_ids[i])
                    new_view_type.append(view_type[i])
            view_ids = new_view_ids
            view_type = new_view_type

        if not view_type:
            view_type = ['form', 'tree']
        else:
            if view_type[0] in ['graph'] and not res_id:
                res_id = Rpc.session.execute('/object', 'execute', model,
                                             'search', domain)
        fields = {}
        self.model = model
        self.previousAction = None
        self.fields = fields
        self.domain = domain
        self.context = context
        self.viewTypes = view_type
        self.viewIds = view_ids

        self._switchViewMenu = QMenu(self)
        self._viewActionGroup = QActionGroup(self)
        self._viewActionGroup.setExclusive(True)
        for view in self.viewTypes:
            action = ViewFactory.viewAction(view, self)
            if not action:
                continue
            self.connect(action, SIGNAL('triggered()'), self.switchView)
            self._switchViewMenu.addAction(action)
            self._viewActionGroup.addAction(action)

        self.group = RecordGroup(self.model, context=self.context)
        if Settings.value('koo.sort_mode') == 'visible_items':
            self.group.setSortMode(RecordGroup.SortVisibleItems)
        self.group.setDomain(domain)
        self.connect(self.group, SIGNAL('modified'), self.notifyRecordModified)

        self.screen.setRecordGroup(self.group)
        self.screen.setEmbedded(False)
        self.connect(self.screen, SIGNAL('activated()'), self.switchToForm)
        self.connect(self.screen, SIGNAL('currentChanged()'),
                     self.updateStatus)
        self.connect(self.screen, SIGNAL('closed()'), self.closeWidget)
        self.connect(self.screen, SIGNAL('recordMessage(int,int,int)'),
                     self.updateRecordStatus)
        self.connect(self.screen, SIGNAL('statusMessage(QString)'),
                     self.updateStatus)

        self._allowOpenInNewWindow = True

        # Remove ids with False value
        self.screen.setupViews(view_type, view_ids)

        if name:
            self.name = name
        else:
            self.name = self.screen.currentView().title

        self.handlers = {
            'New': self.new,
            'Save': self.save,
            'Export': self.export,
            'Import': self.import_,
            'Delete': self.remove,
            'Find': self.search,
            'Previous': self.previous,
            'Next': self.__next__,
            'GoToResourceId': self.goto,
            'AccessLog': self.showLogs,
            'Reload': self.reload,
            'Switch': self.switchView,
            'Attach': self.showAttachments,
            'Duplicate': self.duplicate,
            'BatchInsert': self.batchInsert,
            'BatchUpdate': self.batchUpdate,
            'BatchButton': self.batchButton,
            'BatchUpdateField': self.batchUpdateField,
            'StoreViewSettings': self.storeViewSettings,
        }

        if res_id:
            if isinstance(res_id, int):
                res_id = [res_id]
            self.screen.load(res_id)
        else:
            if len(view_type) and view_type[0] == 'form':
                self.screen.new()

        self.updateSwitchView()

        self.reloadTimer = QTimer(self)
        self.connect(self.reloadTimer, SIGNAL('timeout()'), self.autoReload)
        self.pendingReload = False

        # We always use the Subscriber as the class itself will handle
        # whether the module exists on the server or not
        self.subscriber = Rpc.Subscriber(Rpc.session, self)
        if Settings.value('koo.auto_reload'):
            self.subscriber.subscribe('updated_model:%s' % model,
                                      self.autoReload)