Пример #1
0
 def create(self, record):
     from Koo.Model.Group import RecordGroup
     group = RecordGroup(resource=self.attrs['relation'],
                         fields={},
                         parent=record,
                         context=self.context(record, eval=False))
     group.setDomainForEmptyGroup()
     group.tomanyfield = self
     self.connect(group, SIGNAL('modified'), self.groupModified)
     return group
Пример #2
0
 def initGui(self):
     if self.record:
         group = self.record.value(self.name)
     else:
         group = None
     if not group:
         group = RecordGroup(self.attrs['relation'])
         group.setDomainForEmptyGroup()
     self.screen.setRecordGroup(group)
     self.screen.setViewTypes(['tree'])
     self.screen.setEmbedded(True)
Пример #3
0
	def initGui(self):
		if self.record:
			group = self.record.value(self.name)
		else:
			group = None
		if not group:
			group = RecordGroup( self.attrs['relation'] )
			group.setDomainForEmptyGroup()

		self.screen.setRecordGroup( group )
		self.screen.setPreloadedViews( self.attrs.get('views', {}) )
		self.screen.setEmbedded( True )
		self.screen.setViewTypes( self.attrs.get('mode', 'tree,form').split(',') )
		self.uiTitle.setText( self.screen.currentView().title )
Пример #4
0
    def batchButton(self):
        viewTypes = self.viewTypes
        viewIds = self.viewIds

        group = RecordGroup(self.model, context=self.context)
        group.setDomainForEmptyGroup()
        group.load(self.screen.selectedIds())

        screen = Screen(self)
        screen.setRecordGroup(self.group)
        screen.setEmbedded(True)
        if 'form' in viewTypes:
            queue = ViewQueue()
            queue.setup(viewTypes, viewIds)
            type = ''
            while type != 'form':
                ident, type = next(queue)
            screen.setupViews(['form'], [ident])
        else:
            screen.setupViews(['form'], [False])

        from Koo.Fields.Button import ButtonFieldWidget
        from Koo.Common import Common

        buttons = {}
        for key, widget in screen.currentView().widgets.items():
            if isinstance(widget, ButtonFieldWidget):
                buttons[str(widget.button.text())] = widget.name

        selectionDialog = Common.SelectionDialog(
            _('Choose action to apply to selected records'), buttons, self)
        if selectionDialog.exec_() == QDialog.Rejected:
            return

        buttonString = selectionDialog.result[0]
        buttonName = selectionDialog.result[1]

        if QMessageBox.question(
                self, _("Batch Update"),
                _("Do you really want to push button '%s' of all selected records?") % buttonString,
                QMessageBox.Yes|QMessageBox.No
        ) == 1:
            return

        for ident in self.screen.selectedIds():
            screen.display(ident)
            screen.currentView().widgets[buttonName].executeButton(screen, ident)

        self.reload()
Пример #5
0
    def initGui(self):
        group = RecordGroup(self.attrs['relation'])
        group.setDomainForEmptyGroup()

        self.screen.setRecordGroup(group)
        self.screen.setEmbedded(True)
        #self.screen.setViewTypes( ['tree'] )
        # Set the view first otherwise, default values created by self.screen.new()
        # would only be set for those values handled by the current view.
        if 'views' in self.attrs and 'tree' in self.attrs['views']:
            arch = self.attrs['views']['tree']['arch']
            fields = self.attrs['views']['tree']['fields']
            self.screen.addView(arch, fields, display=True)
        else:
            self.screen.addViewByType('tree', display=True)
        treeView = self.screen.currentView().widget
        treeView.setHeaderHidden(True)
Пример #6
0
class BatchInsertDialog(QDialog, BatchInsertDialogUi):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        BatchInsertDialogUi.__init__(self)
        self.setupUi(self)

        self.connect(self.pushAccept, SIGNAL('clicked()'), self.save)

        self.ids = []
        self.model = None
        self.context = None
        self.updateOnServer = True
        self.newValues = {}
        self.availableFields = []

    def setModel(self, model):
        self.model = model

    def setContext(self, context):
        self.context = context

    def setAvailableFields(self, fields):
        self.availableFields = fields

    def setUpdateOnServer(self, update):
        self.updateOnServer = update

    def setViewTypes(self, viewTypes):
        self.viewTypes = viewTypes

    def setViewIds(self, viewIds):
        self.viewIds = viewIds

    def setup(self):
        fields = Rpc.session.execute('/object', 'execute', self.model,
                                     'fields_view_get', False, 'form',
                                     Rpc.session.context)
        fields = fields['fields']
        if self.availableFields:
            for field in list(fields.keys()):
                if not field in self.availableFields:
                    del fields[field]

        oneToManyFields = [(fields[field]['string'], field) for field in fields
                           if fields[field]['type'] == 'many2one']
        oneToManyFields = dict(oneToManyFields)
        selectionDialog = Common.SelectionDialog(
            _('Choose field to insert in batch action'), oneToManyFields, self)
        if selectionDialog.exec_() == QDialog.Rejected:
            return False
        fieldString = selectionDialog.result[0]
        fieldName = selectionDialog.result[1]
        self.newField = fieldName
        fieldModel = fields[fieldName]['relation']
        fields = {
            'many2many': {
                'string': fieldString,
                'name': 'many2many',
                'type': 'many2many',
                'relation': fieldModel,
            }
        }
        arch = ''
        arch += '<?xml version="1.0"?>'
        arch += '<form string="%s">\n' % _('Batch Insert')
        arch += '<label string="%s" colspan="4"/>' % fieldString
        arch += '<field name="many2many" colspan="4" nolabel="1"/>'
        arch += '</form>'
        group = RecordGroup(fieldModel, fields)
        self.screen.setRecordGroup(group)
        self.screen.new(default=False)
        self.screen.addView(arch, fields, display=True)
        return True

    def createScreen(self):
        self.group = RecordGroup(self.model, context=self.context)
        self.group.setDomainForEmptyGroup()

        screen = Screen()
        screen.setRecordGroup(self.group)
        screen.setEmbedded(True)
        if 'form' in self.viewTypes:
            queue = ViewQueue()
            queue.setup(self.viewTypes, self.viewIds)
            type = ''
            while type != 'form':
                id, type = next(queue)
            screen.setupViews(['form'], [id])
        else:
            screen.setupViews(['form'], [False])

    def save(self):
        self.screen.currentView().store()
        record = self.screen.currentRecord()
        self.newValues = [x.id for x in record.value('many2many')]
        if record.isModified() and self.newValues:
            if QMessageBox.question(
                    self, _('Batch Insert'),
                    _('Are you sure you want to insert %d records?') %
                    len(self.newValues), _("Yes"), _("No")) == 1:
                return
            if self.updateOnServer:
                screen = self.createScreen()
                for value in self.newValues:
                    record = self.group.create()
                    record.setValue(self.newField, value)
                self.group.save()
        self.accept()
Пример #7
0
class WizardPage(QDialog):
    def __init__(self, arch, fields, state, name, datas, parent=None):
        QDialog.__init__(self, parent)
        self.setModal(True)
        buttons = []
        self.datas = datas
        self.buttonsLayout = QHBoxLayout()
        self.buttonsLayout.addStretch()
        for x in state:
            but = QPushButton(Common.normalizeLabel(x[1]))
            # We store the value to return into objectName property
            but.setObjectName(x[0])
            # The third element is the gtk-icon
            if len(x) >= 3:
                but.setIcon(Icons.kdeIcon(x[2]))
            # The forth element is True if the button is the default one
            if len(x) >= 4 and x[3]:
                but.setDefault(True)
            self.buttonsLayout.addWidget(but)
            self.connect(but, SIGNAL('clicked()'), self.slotPush)

        val = {}
        for f in fields:
            if 'value' in fields[f]:
                val[f] = fields[f]['value']

        self.group = RecordGroup('wizard.' + name)
        # Do not allow record loading as most probably 'wizard.'+name model
        # won't exist in the server
        self.group.setDomainForEmptyGroup()
        self.screen = Screen(self)
        self.screen.setRecordGroup(self.group)
        self.screen.new(default=False)
        self.screen.addView(arch, fields, display=True)
        # Set default values
        self.screen.currentRecord().set(val)
        # Set already stored values
        self.screen.currentRecord().set(self.datas)
        self.screen.display()

        # Set minimum and maximum dialog size
        size = self.screen.sizeHint()
        self.setMinimumSize(size.width() + 100, min(600, size.height() + 25))
        size = QApplication.desktop().availableGeometry(self).size()
        size -= QSize(50, 50)
        self.setMaximumSize(size)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.screen)
        self.layout.addLayout(self.buttonsLayout)
        self.setWindowTitle(self.screen.currentView().title)

    def slotPush(self):
        o = self.sender()
        self.screen.currentView().store()
        # Get the value we want to return
        button = str(o.objectName())
        if button != 'end' and not self.screen.currentRecord().validate():
            self.screen.display()
            return
        self.datas.update(self.screen.get())
        self.result = (button, self.datas)
        self.accept()
class BatchUpdateDialog(QDialog, BatchUpdateDialogUi):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        BatchUpdateDialogUi.__init__(self)
        self.setupUi(self)

        self.pushAccept.clicked.connect(self.save)
        self.pushCancel.clicked.connect(self.cancelled)

        self.ids = []
        self.model = None
        self.group = None
        self.isGroupNew = False
        self.context = None
        self.updateOnServer = True
        self.newValues = {}

    def setIds(self, ids):
        self.ids = ids

    def setModel(self, model):
        self.model = model

    def setGroup(self, group):
        self.group = group
        self.isGroupNew = False

    def setContext(self, context):
        self.context = context

    def setUpdateOnServer(self, update):
        self.updateOnServer = update

    def setup(self, viewTypes, viewIds):
        if not self.group:
            self.group = RecordGroup(self.model, context=self.context)
            self.group.setDomainForEmptyGroup()
            self.isGroupNew = True

        self.screen.setRecordGroup(self.group)
        self.screen.setEmbedded(True)
        if 'form' in viewTypes:
            queue = ViewQueue()
            queue.setup(viewTypes, viewIds)
            type = ''
            while type != 'form':
                id, type = next(queue)
            self.screen.setupViews(['form'], [id])
        else:
            self.screen.setupViews(['form'], [False])
        self.screen.new()

    def save(self):
        self.screen.currentView().store()
        record = self.screen.currentRecord()
        fields = []
        if record.isModified():
            values = record.get(get_readonly=False, get_modifiedonly=True)
            for field in values:
                attrs = record.fields()[field].attrs
                if 'string' in attrs:
                    name = attrs['string']
                else:
                    name = field
                fields.append((name, field))

            fields.sort(key=lambda x: x[0])

            if fields:
                messageBox = BatchUpdateMessageBoxDialog(self)
                messageBox.setFields(fields)
                messageBox.setMessage(
                    _('Select the fields you want to update in the <b>%d</b> selected records:'
                      ) % len(self.ids))
                if messageBox.exec_() == QDialog.Rejected:
                    return
                self.newValues = {}
                for field in messageBox.selectedFields():
                    if not self.updateOnServer and self.group.fieldType(
                            field) == 'many2many':
                        if len(values[field]):
                            self.newValues[field] = values[field][0][2]
                        else:
                            self.newValues[field] = []
                    else:
                        self.newValues[field] = values[field]

                if self.updateOnServer:
                    Rpc.session.execute('/object', 'execute', self.model,
                                        'write', self.ids, self.newValues,
                                        self.context)

        if not self.isGroupNew:
            self.group.removeRecord(self.screen.currentRecord())

        self.accept()

    def cancelled(self):
        if not self.isGroupNew:
            self.group.removeRecord(self.screen.currentRecord())
Пример #9
0
class TranslationDialog(QDialog, TranslationDialogUi):
    LineEdit = 0
    TextEdit = 1
    RichEdit = 2

    # @brief Constructs a new TranslationDialog object.
    def __init__(self, id, model, fieldName, value, type, parent=None):
        QDialog.__init__(self, parent)
        TranslationDialogUi.__init__(self)
        self.setupUi(self)

        self.connect(self.pushAccept, SIGNAL('clicked()'), self.slotAccept)
        self.id = id
        self.model = model
        self.fieldName = fieldName
        self.value = value
        self.type = type

        self.values = {}
        self.result = value
        # Using the timer should improve user feedback
        QTimer.singleShot(0, self.init)

    def adaptContext(self, value):
        if value == 'en_US':
            return False
        else:
            return value

    def init(self):
        self.currentCode = Rpc.session.context.get('lang', 'en_US')

        languageIds = Rpc.session.execute('/object', 'execute', 'res.lang',
                                          'search',
                                          [('translatable', '=', '1')])
        languages = Rpc.session.execute('/object', 'execute', 'res.lang',
                                        'read', languageIds, ['code', 'name'])

        arch = []
        fields = {}
        for lang in languages:
            if self.type == TranslationDialog.LineEdit:
                widget = 'char'
                fieldType = 'char'
            elif self.type == TranslationDialog.TextEdit:
                widget = 'text'
                fieldType = 'text'
            else:
                widget = 'text_tag'
                fieldType = 'text'

            arch.append(
                """<field name="%s" widget="%s" use="{'lang':'%s'}"/>""" %
                (lang['code'], widget, lang['code']))
            fields[lang['code']] = {
                'string': lang['name'],
                'type': fieldType,
            }
            if lang['code'] == self.currentCode:
                self.values[lang['code']] = self.value
                continue

            context = copy.copy(Rpc.session.context)
            context['lang'] = self.adaptContext(lang['code'])
            val = Rpc.session.execute('/object', 'execute', self.model, 'read',
                                      [self.id], [self.fieldName], context)
            val = val[0]

            self.values[lang['code']] = val[self.fieldName]

        arch = '<form string="%s" col="2">%s</form>' % (
            _('Translation Dialog'), ''.join(arch))

        self.group = RecordGroup('translator')
        # Do not allow record loading as most probably 'wizard.'+name model
        # won't exist in the server
        self.group.setDomainForEmptyGroup()
        self.uiScreen.setRecordGroup(self.group)
        self.uiScreen.new(default=False)
        self.uiScreen.addView(arch, fields, display=True)
        self.uiScreen.currentRecord().set(self.values)
        self.uiScreen.display()

    def slotAccept(self):
        self.uiScreen.currentView().store()
        for lang, oldValue in self.values.items():
            newValue = self.uiScreen.currentRecord().value(lang)
            # Don't update on the server the current text. This would cause information
            # on the server to be updated after the form has been read causing possible
            # conflits.
            if lang == self.currentCode:
                self.result = newValue
                continue
            # Only update on the server if the value has changed
            if newValue == oldValue:
                continue
            context = copy.copy(Rpc.session.context)
            context['lang'] = self.adaptContext(lang)
            Rpc.session.execute('/object', 'execute', self.model, 'write',
                                [self.id], {self.fieldName: newValue}, context)
        self.accept()