Esempio n. 1
0
    def add(self):
        # As the 'add' button modifies the model we need to be sure all other fields/widgets
        # have been stored in the model. Otherwise the recordChanged() triggered
        # could make us lose changes.
        self.view.store()

        domain = self.record.domain(self.name)
        context = self.record.fieldContext(self.name)

        ids = Rpc.session.execute('/object', 'execute', self.attrs['relation'], 'name_search', str(
            self.uiText.text()), domain, 'ilike', context, False)
        ids = [x[0] for x in ids]
        if str(self.uiText.text()) == '' or len(ids) != 1:
            dialog = SearchDialog(
                self.attrs['relation'], sel_multi=True, ids=ids, domain=domain, context=context)
            if dialog.exec_() == QDialog.Rejected:
                self.uiText.clear()
                return
            ids = dialog.result

        self.screen.load(ids)
        self.screen.display()
        self.uiText.clear()
        # Manually set the current model and field as modified
        # This is not necessary in case of removing an item.
        # Maybe a better option should be found. But this one works just right.
        self.screen.group.recordChanged(None)
        self.screen.group.recordModified(None)
Esempio n. 2
0
    def search(self):
        domain = self.record.domain(self.name)
        context = self.record.fieldContext(self.name)
        if 'session' in context:
            context.update({'no_bbox_search': True})
        resource = str(self.uiModel.itemData(self.uiModel.currentIndex()))
        ids = Rpc.session.execute('/object', 'execute',
                                  resource, 'name_search',
                                  str(self.uiText.text()), domain, 'ilike',
                                  context, False)

        if len(ids) == 1:
            id, name = ids[0]
            self.record.setValue(self.name, (resource, (id, name)))
            self.display()
            return

        dialog = SearchDialog(resource,
                              sel_multi=False,
                              ids=[x[0] for x in ids],
                              context=context,
                              domain=domain)
        if dialog.exec_() == QDialog.Accepted and dialog.result:
            id = dialog.result[0]
            id, name = Rpc.session.execute('/object', 'execute', resource,
                                           'name_get', [id],
                                           Rpc.session.context)[0]
            self.record.setValue(self.name, (resource, (id, name)))
            self.display()
Esempio n. 3
0
 def search(self, name):
     domain = self.record.domain(self.name)
     context = self.record.fieldContext(self.name)
     ids = Rpc.session.execute('/object', 'execute', self.attrs['relation'],
                               'name_search', name, domain, 'ilike',
                               context, False)
     if ids and len(ids) == 1:
         self.record.setValue(self.name, ids[0])
         self.display()
     else:
         dialog = SearchDialog(self.attrs['relation'],
                               sel_multi=False,
                               ids=[x[0] for x in ids],
                               context=context,
                               domain=domain,
                               parent=self)
         if dialog.exec_() == QDialog.Accepted and dialog.result:
             id = dialog.result[0]
             name = Rpc.session.execute('/object', 'execute',
                                        self.attrs['relation'], 'name_get',
                                        [id], context)[0]
             self.record.setValue(self.name, name)
             self.display()
         else:
             self.clear()
Esempio n. 4
0
 def slotSearch(self):
     win = SearchDialog(self.action['res_model'],
                        domain=self.domain,
                        context=self.context)
     win.exec_()
     if win.result:
         self.screen.clear()
         self.screen.load(win.result)
Esempio n. 5
0
    def search(self, name):
        """
        This function searches the given name within the available records.
        If none or more than one possible name matches the search dialog is
        shown. If only one matches we set the value and don't even show the
        search dialog. This is also true if the function is called with
        "name=''" and only one record exists in the database (hence the call
        from open())

        :param name:
        :return:
        """
        domain = self.record.domain(self.name)
        context = self.record.fieldContext(self.name)
        if 'session' in context:
            context.update({'no_bbox_search': True})
        ids = Rpc.session.execute('/object', 'execute', self.attrs['relation'],
                                  'name_search', name, domain, 'ilike',
                                  context, False)
        if ids and len(ids) == 1:
            self.record.setValue(self.name, ids[0])
            self.display()
        else:
            l_ids = [x[0] for x in ids]
            dialog = SearchDialog(self.attrs['relation'],
                                  sel_multi=False,
                                  ids=l_ids,
                                  context=context,
                                  domain=domain,
                                  parent=self)
            if dialog.exec_() == QDialog.Accepted and dialog.result:
                if len(dialog.result) == 1:
                    ident = dialog.result[0]
                    name = Rpc.session.execute('/object', 'execute',
                                               self.attrs['relation'],
                                               'name_get', [ident], context)[0]
                    self.record.setValue(self.name, name)
                    self.display()
                else:
                    self.clear()
            else:
                self.clear()
Esempio n. 6
0
    def setModelData(self, editor, kooModel, index):
        if str(editor.text()) == str(index.data(Qt.DisplayRole).toString()):
            return
        # We expecte a KooModel here
        model = kooModel.recordFromIndex(index)

        #model.setData( index, QVariant( editor.currentText() ), Qt.EditRole )
        domain = model.domain(self.name)
        context = model.fieldContext(self.name)

        ids = Rpc.session.execute('/object', 'execute', self.attributes['relation'], 'name_search', str(
            editor.text()), domain, 'ilike', context, False)
        ids = [x[0] for x in ids]
        if len(ids) != 1:
            dialog = SearchDialog(
                self.attributes['relation'], sel_multi=True, ids=ids, domain=domain, context=context)
            if dialog.exec_() == QDialog.Rejected:
                return
            ids = dialog.result

        ids = [QVariant(x) for x in ids]
        kooModel.setData(index, QVariant(ids), Qt.EditRole)
Esempio n. 7
0
    def setModelData(self, editor, kooModel, index):
        # We expect a KooModel here
        model = kooModel.recordFromIndex(index)

        if not str(editor.text()):
            model.setValue(self.name, False)
            return

        if str(kooModel.data(index,
                             Qt.DisplayRole).value()) == str(editor.text()):
            return

        domain = model.domain(self.name)
        context = model.context()
        ids = Rpc.session.execute('/object', 'execute',
                                  self.attributes['relation'], 'name_search',
                                  str(editor.text()), domain, 'ilike', context,
                                  False)
        if ids and len(ids) == 1:
            model.setValue(self.name, ids[0])
        else:
            dialog = SearchDialog(self.attributes['relation'],
                                  sel_multi=False,
                                  ids=[x[0] for x in ids],
                                  context=context,
                                  domain=domain)
            if dialog.exec_() == QDialog.Accepted and dialog.result:
                id = dialog.result[0]
                name = Rpc.session.execute('/object', 'execute',
                                           self.attributes['relation'],
                                           'name_get', [id],
                                           Rpc.session.context)[0]

                # Directly set the value to the model. There's no need to
                # use setData() but we mainly want to workaround a bug in
                # PyQt 4.4.3 and 4.4.4.
                #value = [ QVariant( name[0] ), QVariant( name[1] ) ]
                #kooModel.setData( index, QVariant( value ), Qt.EditRole )
                model.setValue(self.name, name)