def load(self, model, fieldsInfo): if self.rowCount() > 0: self.removeRows(0, self.rowCount()) ir_export = Rpc.RpcProxy('ir.exports') ir_export_line = Rpc.RpcProxy('ir.exports.line') export_ids = ir_export.search([('resource', '=', model)]) for export in ir_export.read(export_ids): fields = ir_export_line.read(export['export_fields']) allFound = True for f in fields: if not f['name'] in fieldsInfo: allFound = False break if not allFound: continue items = [ QStandardItem(', '.join([f['name'] for f in fields])), QStandardItem(str(export['id'])), QStandardItem(export['name']), QStandardItem(', '.join( [fieldsInfo[f['name']]['string'] for f in fields])) ] self.rootItem.appendRow(items)
def search(self): if self.isCustomSearch(): # Do not emit the signal if the server raises an exception with the search # which unfortunately can happen in some cases such as some searches with properties. # (ie. [('property_product_pricelist.name','ilike','a')]) value = self.value() proxy = Rpc.RpcProxy(self.model, useExecute=False) try: proxy.search(value, 0, False, False, Rpc.session.context) except Rpc.RpcException as e: number = 0 for item in value: if not isinstance(item, tuple): continue valid = True try: self.uiCustomContainer.setItemValid proxy.search([item], 0, False, False, Rpc.session.context) except Rpc.RpcException as e: valid = False self.uiCustomContainer.setItemValid(number, valid) number += 1 QMessageBox.warning( self, _('Search Error'), _('Some items of custom search cannot be used. Please, change those in red and try again.' )) return self.uiCustomContainer.setAllItemsValid(True) self.emit(SIGNAL('search()'))
def removeExport(self): idx = self.uiPredefined.selectionModel().selectedRows(1) if len(idx) != 1: return idx = idx[0] id = int(str(self.storedModel.itemFromIndex(idx).text())) ir_export = Rpc.RpcProxy('ir.exports') ir_export.unlink([id]) self.storedModel.load(self.model, self.fieldsInfo)
def updateCompany(self, company=None): if not company: users = Rpc.RpcProxy('res.users') records = users.read([Rpc.session.uid], ['company_id'], Rpc.session.context) company = records[0]['company_id'] if company: company = company[1] else: company = '' self.pushCompany.setText(company)
def changeCompany(self): action = self.sender() company_id = action.data().toInt()[0] users = Rpc.RpcProxy('res.users') users.write([Rpc.session.uid], { 'company_id': company_id, }, Rpc.session.context) Rpc.session.reloadContext() self.updateCompany() self.closeAllTabs() self.openMenuTab()
def save(self): name, ok = QInputDialog.getText(self, '', _('What is the name of this export?')) if not ok: return ir_export = Rpc.RpcProxy('ir.exports') fields = [] for x in range(0, self.selectedModel.rowCount()): fields.append(str(self.selectedModel.item(x).data().toString())) ir_export.create({ 'name': str(name), 'resource': self.model, 'export_fields': [(0, 0, { 'name': f }) for f in fields] }) self.storedModel.load(self.model, self.fieldsInfo)
def save(self, reload=True): """ Save the record to the database. It doesn't matter if the record is new or already exists. :param reload: :return: """ from .Group import RecordGroup if self.before_save_fnc: self.before_save_fnc() self.ensureIsLoaded() if not self.id: value = self.get(get_readonly=False) self.id = self.rpc.create(value, self.context()) else: if not self.isModified(): return self.id value = self.get(get_readonly=False, get_modifiedonly=True) context = self.context() context = context.copy() context[ConcurrencyCheckField] = time.time() - self.read_time if not self.rpc.write([self.id], value, context): return False self._loaded = False # Delete elements for key_name, value in self.values.items(): if isinstance(value, RecordGroup): if value.removedRecords: model = value.resource ids = value.removedRecords Rpc.RpcProxy(model).unlink(ids) if reload: self.reload() if self.group: self.group.written(self.id) self.modified = False return self.id
def inheritView(self): view_id = self.attrs.get('x-view') if not view_id: return view_id = re.findall('\d+', view_id) if not view_id: return view_id = int(view_id[0]) view = Rpc.RpcProxy('ir.ui.view') records = view.read([view_id], ['name', 'model', 'xml_id']) record = records[0] id = record['xml_id'].split('.')[-1] arch = """ <openerp> <data> <record model="ir.ui.view" id="%(id)s"> <field name="name">%(name)s</field> <field name="model">%(model)s</field> <field name="type">form</field> <field name="inherit_id" ref="%(xml_id)s"/> <field name="arch" type="xml"> <field name="%(field)s" position="after"> <field name=""/> </field> </field> </record> </data> </openerp>""" % { 'id': id, 'name': record['name'], 'model': record['model'], 'xml_id': record['xml_id'], 'field': self.attrs.get('name', ''), } fd, fileName = tempfile.mkstemp(suffix='.txt') os.write(fd, arch) os.close(fd) Common.openFile(fileName)
def save(self, reload=True): """ Save the record to the database. It doesn't matter if the record is new or already exists. :param reload: :return: """ from .Group import RecordGroup self.ensureIsLoaded() dialog_container = False is_modal = False action = '' write_res = False create_res = False try: try: dialog_container = self.sender().parentWidget().parentWidget( ).parentWidget() is_modal = dialog_container.isModal() except Exception: pass if not self.id: values = self.get(get_readonly=False) action = 'create' context = self.context() fill_geom = ( 'geom' in context and ('geom' not in values or ('geom' in values and not values.get('geom', True))) and 'geom' in self.rpc.fields_get()) if fill_geom: values['geom'] = context['geom'] create_res = self.rpc.create_qread(values, self.group.allFieldNames(), context, '_classic_read') self.id = create_res['id'] else: context = self.context() if not self.isModified(): if is_modal: QTimer.singleShot(0, dialog_container.accept) if self.after_save_function and context.get( 'from_search', False): self.after_save_function(self.id, {}) return self.id values = self.get(get_readonly=False, get_modifiedonly=True) context = context.copy() context[ConcurrencyCheckField] = time.time() - self.read_time action = 'write' write_res = self.rpc.write_qread(self.id, values, self.group.allFieldNames(), context, '_classic_read') if not write_res: if is_modal: QTimer.singleShot(0, dialog_container.accept) return False self._loaded = False # Delete elements for key_name, value in self.values.items(): if isinstance(value, RecordGroup): if value.removedRecords: model = value.resource ids = value.removedRecords Rpc.RpcProxy(model).unlink(ids) if write_res: self.set(write_res, signal=False) Rpc.session.context['skip_reload'] = True elif create_res: self.set(create_res, signal=False) Rpc.session.context['skip_reload'] = True elif reload: self.reload() Rpc.session.context['skip_reload'] = True if self.group: self.group.written(self.id) self.modified = False if self.after_save_function: self.after_save_function(self.id, values) if is_modal: QTimer.singleShot(0, dialog_container.accept) return self.id except Exception as e: if action == 'create': # Si venim d'un CREATE s'ha de fer rollback i donar info de # l'error. if self.error_procedure: self.error_procedure(action, e) if is_modal: QTimer.singleShot(0, dialog_container.accept) elif action == 'write': # Si venim d'un WRITE s'ha de donar info de l'error i de que # l'accio s'ha invalidat i no ha tingut cap efecte if self.error_procedure: self.error_procedure(action, e) return False