def fields_get(cls, fields_names=None, group=0, level=0): Model = Pool().get('ir.model') Data = Pool().get('lims.interface.data') res = super().fields_get(fields_names) table = cls.get_table() readonly = Transaction().context.get('lims_interface_readonly', False) encoder = PYSONEncoder() for field in table.grouped_fields_: if field.group != group: continue res[field.name] = { 'name': field.name, 'string': field.string, 'type': FIELD_TYPE_TRYTON[field.type], 'readonly': bool(readonly or field.formula or field.readonly), 'help': field.help, 'domain': field.domain, 'states': '{}', } if field.type == 'many2one': res[field.name]['relation'] = (field.related_model.model if field.related_model else None) if field.type == 'selection': selection = [tuple(v.split(':', 1)) for v in field.selection.splitlines() if v] res[field.name]['selection'] = selection res[field.name]['selection_change_with'] = [] res[field.name]['sort'] = False if field.type == 'reference': selection = [] for model in Model.search([]): selection.append((model.model, model.name)) res[field.name]['selection'] = selection if field.type in ['date', 'time', 'datetime', 'timestamp']: res[field.name]['format'] = PYSONEncoder().encode( '%H:%M:%S.%f') if field.type in ['float', 'numeric']: res[field.name]['digits'] = encoder.encode((16, field.digits)) if field.inputs: res[field.name]['on_change_with'] = field.inputs.split() + [ 'data'] cls.add_on_change_with_method(field) func_name = '%s_%s' % ('on_change_with', field.name) cls.__rpc__.setdefault(func_name, RPC(instantiate=0)) res['data'] = { 'name': 'data', 'string': 'Data', 'type': 'many2one', 'readonly': True, 'help': '', 'states': '{}', 'relation': 'lims.interface.data', 'relation_field': 'group_%s' % group, 'relation_fields': (Data.fields_get(level=level - 1) if level > 0 else []), } return res
def do_inpatient_evaluation(self, action): inpatient_registration = Transaction().context.get('active_id') try: reg_id = \ Pool().get('gnuhealth.inpatient.registration').browse([inpatient_registration])[0] except: self.raise_user_error('no_record_selected') patient = reg_id.patient.id action['pyson_domain'] = PYSONEncoder().encode([ ('patient', '=', patient), ('inpatient_registration_code', '=', reg_id.id), ('evaluation_type', '=', 'inpatient'), ]) action['pyson_context'] = PYSONEncoder().encode({ 'patient': patient, 'inpatient_registration_code': reg_id.id, 'evaluation_type': 'inpatient', }) return action, {}
def do_goto_notification(self, action): enctr_id, encounter = self._get_active_encounter() # Does the notification entry already exist? notification = Pool().get('gnuhealth.disease_notification').search([ ('encounter', '=', enctr_id) ]) if notification: rd = {'active_id': notification[0].id} action['res_id'] = rd['active_id'] else: now = datetime.now() patient = encounter.patient facility = encounter.institution rd = {} action['pyson_domain'] = PYSONEncoder().encode([ ('encounter', '=', enctr_id), ('patient', '=', patient.id), ('reporting_facility', '=', facility.id), ('date_notified', '=', localtime(now).strftime('%F %T')) ]) action['pyson_context'] = PYSONEncoder().encode({ 'encounter': enctr_id, 'patient': patient.id, 'reporting_facility': facility.id, 'date_notified': now }) return action, rd
def do_open_(self, action): entries_ids = self._get_entries_ready_for_invoicing() action['pyson_context'] = PYSONEncoder().encode({ 'ready_for_invoicing': True, }) action['pyson_domain'] = PYSONEncoder().encode([ ('id', 'in', entries_ids), ]) return action, {}
def do_open_(self, action): Date = Pool().get('ir.date') action['pyson_context'] = PYSONEncoder().encode({ 'product': Transaction().context['active_id'], 'warehouse': self.start.warehouse.id, }) action['pyson_search_value'] = PYSONEncoder().encode([ ('date', '>=', Date.today()), ]) return action, {}
def do_enter(self, action): date = self.start.date date = Date(date.year, date.month, date.day) action['pyson_domain'] = PYSONEncoder().encode([ ('employee', '=', self.start.employee.id), ('date', '=', date), ]) action['pyson_context'] = PYSONEncoder().encode({ 'employee': self.start.employee.id, 'date': date, }) action['name'] += " - " + self.start.employee.rec_name return action, {}
def do_open(self, action): pool = Pool() Product = pool.get('product.product') active_id = Transaction().context.get('active_id') if not active_id or active_id < 0: action['pyson_domain'] = PYSONEncoder().encode([ ('template', '=', None), ]) else: product = Product(active_id) action['pyson_domain'] = PYSONEncoder().encode([ ('template', '=', product.template.id), ]) return action, {}
def definition(self, model, language): pool = Pool() Translation = pool.get('ir.translation') encoder = PYSONEncoder() definition = { 'context': encoder.encode(self.context), 'loading': self.loading, 'name': self.name, 'on_change': list(self.on_change), 'on_change_with': list(self.on_change_with), 'readonly': self.readonly, 'required': self.required, 'states': encoder.encode(self.states), 'type': self._type, 'domain': encoder.encode(self.domain), 'searchable': hasattr(model, 'search'), 'sortable': hasattr(model, 'search'), } # Add id to on_change's if they are not cached # Not having the id increase the efficiency of the cache for method in ['on_change', 'on_change_with']: changes = definition[method] if changes: method_name = method + '_' + self.name if not model.__rpc__[method_name].cache: changes.append('id') name = '%s,%s' % (model.__name__, self.name) for attr, ttype in [('string', 'field'), ('help', 'help')]: definition[attr] = '' for source in getattr(self, attr): definition[attr] += (Translation.get_source( name, ttype, language, source) or source) return definition
def fields_get(cls, fields_names=None): Model = Pool().get('ir.model') res = super(Data, cls).fields_get(fields_names) table = cls.get_table() for field in table.fields: res[field.name] = { 'name': field.name, 'string': field.string, 'type': FIELD_TYPE_TRYTON[field.type], 'relation': (field.related_model.model if field.related_model else None), 'readonly': bool(field.formula), 'help': field.help, } if field.inputs: res[field.name]['on_change_with'] = field.inputs.split() if field.type == 'reference': selection = [] for model in Model.search([]): selection.append((model.model, model.name)) res[field.name]['selection'] = selection if field.type == 'timestamp': res[field.name]['format'] = PYSONEncoder().encode( '%H:%M:%S.%f') return res
def do_report(self, action): dict = {} try: self.start.location.id dict['location'] = self.start.location.id except: pass try: self.start.start_time dict['start_time'] = self.start.start_time except: pass try: self.start.end_time dict['end_time'] = self.start.end_time except: pass try: self.start.drug_type dict['drug_type'] = self.start.drug_type except: pass action['pyson_context'] = PYSONEncoder().encode(dict) action['name'] += ' - (%s) @ %s' % (u'调价盈亏报表', self.start.start_time) return action, {}
def get_buttons(self, wizard, state_name): ''' Returns button definitions translated ''' Translation = Pool().get('ir.translation') def translation_key(button): return (','.join( (wizard.__name__, state_name, button.state)), 'wizard_button', Transaction().language, button.string) translation_keys = [translation_key(button) for button in self.buttons] translations = Translation.get_sources(translation_keys) encoder = PYSONEncoder() result = [] for button in self.buttons: validate = (button.validate if button.validate is not None else button.state != wizard.end_state) result.append({ 'state': button.state, 'icon': button.icon, 'default': button.default, 'validate': validate, 'string': (translations.get(translation_key(button)) or button.string), 'states': encoder.encode(button.states), }) return result
def do_open(self, action): pool = Pool() Location = pool.get('stock.location') Lang = pool.get('ir.lang') context = {} context['locations'] = Transaction().context.get('active_ids') date = self.start.forecast_date or datetime.date.max context['stock_date_end'] = Date(date.year, date.month, date.day) action['pyson_context'] = PYSONEncoder().encode(context) locations = Location.browse(context['locations']) for code in [Transaction().language, 'en_US']: langs = Lang.search([ ('code', '=', code), ]) if langs: break lang = langs[0] date = Lang.strftime(date, lang.code, lang.date) action['name'] += ' - (%s) @ %s' % (','.join(l.name for l in locations), date) return action, {}
def definition(self, model, language): encoder = PYSONEncoder() definition = super().definition(model, language) definition['datetime_field'] = self.datetime_field definition['search_context'] = encoder.encode(self.search_context) definition['search_order'] = encoder.encode(self.search_order) return definition
def update_actions(cls, views): ActWindow = Pool().get('ir.action.act_window') to_write = [] for view in views: action = view.action if not action: action = ActWindow() action.name = '%s (%s)' % (view.name, view.sheet.name) action.res_model = 'shine.data' action.usage = 'dashboard' action.context = PYSONEncoder().encode({ 'shine_view': view.id, 'shine_sheet': view.sheet.id, 'shine_table': view.current_table.id, #'shine_table_view': view.current_table_view.id, }) action.save() if not view.action: to_write.append([view]) to_write.append({ 'action': action.id, }) if to_write: with Transaction().set_context({ 'shine_prevent_view_updates': True, }): cls.write(*to_write)
def do_report_customer(self, action): dict = {} try: self.start.location.id dict['location'] = self.start.location.id except: pass try: self.start.drug_type dict['drug_type'] = self.start.drug_type except: pass try: self.start.start_time dict['start_time'] = self.start.start_time except: pass try: self.start.end_time dict['end_time'] = self.start.end_time except: pass try: self.start.customer.id dict['customer'] = self.start.customer.id except: pass try: action['pyson_context'] = PYSONEncoder().encode(dict) except: pass action['name'] += ' - (%s) @ %s' % (u'药库出库报表', str(self.start.start_time) + '——' + str(self.start.end_time)) return action, {}
def do_open_(self, action): pool = Pool() Request = pool.get('gnuhealth.imaging.test.request') Result = pool.get('gnuhealth.imaging.test.result') request_data = [] requests = Request.browse(Transaction().context.get('active_ids')) for request in requests: request_data.append({ 'patient': request.patient.id, 'date': datetime.now(), 'request_date': request.date, 'requested_test': request.requested_test, 'request': request.id, 'doctor': request.doctor }) results = Result.create(request_data) action['pyson_domain'] = PYSONEncoder().encode([ ('id', 'in', [r.id for r in results]) ]) Request.requested(requests) Request.done(requests) return action, {}
def do_create_order(self, action): pool = Pool() Sale = pool.get('sale.sale') address = self._get_address() visit = self._get_visit() sale = Sale() sale.party = address.party sale.invoice_address = address sale.shipment_address = address if visit: sale.sale_date = visit.time.date() sale.origin = visit sale.save() encoder = PYSONEncoder() action['views'].reverse() action['domains'] = [] action['pyson_domain'] = encoder.encode([ ('id', '=', sale.id), ]) return action, { 'res_id': [sale.id], }
def do_open(self, action): pool = Pool() Product = pool.get('product.product') Lang = pool.get('ir.lang') context = {} product_id = Transaction().context['active_id'] context['product'] = product_id if self.start.forecast_date: context['stock_date_end'] = self.start.forecast_date else: context['stock_date_end'] = datetime.date.max action['pyson_context'] = PYSONEncoder().encode(context) product = Product(product_id) for code in [Transaction().language, 'en_US']: langs = Lang.search([ ('code', '=', code), ]) if langs: break lang, = langs date = Lang.strftime(context['stock_date_end'], lang.code, lang.date) action['name'] += ' - %s (%s) @ %s' % (product.rec_name, product.default_uom.rec_name, date) return action, {}
def do_start(self, action): pool = Pool() ResultsReport = pool.get('lims.results_report') ResultsDetail = pool.get('lims.results_report.version.detail') ResultsSample = pool.get('lims.results_report.version.detail.sample') Notebook = pool.get('lims.notebook') active_ids = Transaction().context['active_ids'] details = ResultsDetail.browse(active_ids) component_ids = [] samples = ResultsSample.search([ ('version_detail', 'in', active_ids), ]) for s in samples: if s.component: component_ids.append(s.component.id) notebooks = Notebook.search([ ('component', 'in', component_ids), ]) notebook_ids = [n.id for n in notebooks] reports = ResultsReport.search([ ('versions.details.samples.notebook', 'in', notebook_ids), ('versions.details.id', 'not in', active_ids), ]) results_report_ids = [r.id for r in reports] action['pyson_domain'] = PYSONEncoder().encode([ ('id', 'in', results_report_ids), ]) action['name'] = '%s (%s)' % (gettext('lims_industry.lbl_precedents'), ', '.join(d.rec_name for d in details)) return action, {}
def do_print_(self, action): #start_date = self.start.date end_date = self.start.to_date #fiscalyear = self.start.fiscalyear.id #start_date = Date(start_date.year, start_date.month, start_date.day) end_date = Date(end_date.year, end_date.month, end_date.day) data = { 'company': self.start.company.id, 'account': self.start.account.id, #'fiscalyear': self.start.fiscalyear.name, #'fiscalyear_id': self.start.fiscalyear.id, #'start_date': self.start.fiscalyear.start_date, 'end_date': self.start.to_date, 'omit_zero': self.start.omit_zero, } action['pyson_context'] = PYSONEncoder().encode({ 'company': self.start.company.id, #'fiscalyear': self.start.fiscalyear.id, #'start_date': start_date, 'end_date': end_date, }) #if self.start.fiscalyear: # action['name'] += ' - %s' % self.start.fiscalyear.rec_name return action, data
def do_open_(self, action): encoder = PYSONEncoder() action['pyson_context'] = encoder.encode(self.get_context()) action['pyson_search_value'] = encoder.encode(self.get_search_value()) action['pyson_domain'] = encoder.encode(self.get_domain()) action['name'] += '(' + self.record.rec_name + ')' return action, {}
def definition(self, model, language): pool = Pool() Translation = pool.get('ir.translation') encoder = PYSONEncoder() definition = { 'context': encoder.encode(self.context), 'loading': self.loading, 'name': self.name, 'depends': self.depends, 'on_change': list(self.on_change), 'on_change_with': list(self.on_change_with), 'readonly': self.readonly, 'required': self.required, 'states': encoder.encode(self.states), 'type': self._type, 'domain': encoder.encode(self.domain), 'searchable': hasattr(model, 'search'), 'sortable': hasattr(model, 'search'), } # Add id to on_change's if they are not cached # Not having the id increase the efficiency of the cache for method in ['on_change', 'on_change_with']: changes = definition[method] if changes: method_name = method + '_' + self.name if not model.__rpc__[method_name].cache: changes.append('id') for name in changes: target = model if '.' in name: prefix, _ = name.rsplit('.', 1) prefix += '.' else: prefix = '' while name.startswith('_parent_'): field, name = name.split('.', 1) target = target._fields[field[8:]].get_target() field = target._fields[name] if field and field.context: eval_fields = get_eval_fields(field.context) for context_field_name in eval_fields: prefix_ctx_field_name = ( prefix + context_field_name) if (context_field_name in field.depends and prefix_ctx_field_name not in changes): changes.append(prefix_ctx_field_name) name = '%s,%s' % (model.__name__, self.name) for attr, ttype in [('string', 'field'), ('help', 'help')]: definition[attr] = '' for source in getattr(self, attr): if not isinstance(source, LazyString): source = ( Translation.get_source(name, ttype, language, source) or source) definition[attr] += source return definition
def do_renumber(self, action): pool = Pool() Move = pool.get('account.move') Sequence = pool.get('ir.sequence') Warning = pool.get('res.user.warning') draft_moves = Move.search([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('state', '=', 'draft'), ]) if draft_moves: key = 'move_renumber_draft_moves%s' % self.start.fiscalyear.id if Warning.check(key): raise UserWarning( key, gettext('account_move_renumber.draft_moves_in_fiscalyear', fiscalyear=self.start.fiscalyear.rec_name)) sequences = set([self.start.fiscalyear.post_move_sequence]) for period in self.start.fiscalyear.periods: if period.post_move_sequence: sequences.add(period.post_move_sequence) Sequence.write(list(sequences), { 'number_next': self.start.first_number, }) moves_to_renumber = Move.search([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('post_number', '!=', None), ], order=[ ('date', 'ASC'), ('id', 'ASC'), ]) move_vals = [] for move in moves_to_renumber: if move == self.start.first_move: number_next_old = move.period.post_move_sequence_used.number_next Sequence.write(list(sequences), { 'number_next': 1, }) move_vals.extend(([move], { 'post_number': Sequence.get_id(move.period.post_move_sequence_used.id), })) Sequence.write(list(sequences), { 'number_next': number_next_old, }) continue move_vals.extend(([move], { 'post_number': (move.period.post_move_sequence_used.get()), })) Move.write(*move_vals) action['pyson_domain'] = PYSONEncoder().encode([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('post_number', '!=', None), ]) return action, {}
def do_open_(self, action): action['pyson_context'] = PYSONEncoder().encode({ 'start_date': self.start.start_date, 'end_date': self.start.end_date, }) return action, {}
def do_open_(self, action): action['pyson_context'] = PYSONEncoder().encode({ 'from_date': self.start.from_date, 'to_date': self.start.to_date, }) return action, {}
def digits(self): digits = 4 if self.field.ttype in ('float', 'numeric'): Model = Pool().get(self.field.model.model) digits = Model._fields.get(self.field.name).digits[1] if isinstance(digits, PYSON): digits = PYSONDecoder().decode(PYSONEncoder().encode(digits)) return digits
def do_open_(self, action): action['pyson_context'] = PYSONEncoder().encode({ 'start_date': self.start.start_date, 'end_date': self.start.end_date, 'group': self.start.group.id if self.start.group else None, 'number_records': self.start.number_records, }) return action, {}
def do_open_(self, action): action['pyson_domain'] = PYSONEncoder().encode([ ('id', 'in', [sample.id for sample in self.ask.countersamples]), ]) action['views'].reverse() return action, { 'res_id': [self.ask.countersamples[0].id], }
def do_open_(self, action): encoder = PYSONEncoder() action['pyson_context'] = '{}' action['pyson_search_value'] = encoder.encode([('date', '>=', self.record.date)]) action['pyson_domain'] = encoder.encode([('product', '=', str(self.record.product))]) action['name'] += ' (' + self.record.rec_name + ')' return action, {}
def _ModelView__view_look_dom( cls, element, type, fields_width=None, _fields_attrs=None): result = super()._ModelView__view_look_dom( element, type, fields_width, _fields_attrs) if element.get('name') == 'update_totp_secret': encoder = PYSONEncoder() states = cls._buttons['update_totp_secret'] element.set('states', encoder.encode(states)) return result