1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE. |
4
|
|
|
# |
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
7
|
|
|
# Foundation, version 2. |
8
|
|
|
# |
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
12
|
|
|
# details. |
13
|
|
|
# |
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17
|
|
|
# |
18
|
|
|
# Copyright 2018-2022 by it's authors. |
19
|
|
|
# Some rights reserved, see README and LICENSE. |
20
|
|
|
|
21
|
|
|
from bika.lims import api |
22
|
|
|
from bika.lims import senaiteMessageFactory as _ |
23
|
|
|
from senaite.core.browser.form.adapters import EditFormAdapterBase |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class EditForm(EditFormAdapterBase): |
27
|
|
|
"""Edit form adapter for Worksheet Template |
28
|
|
|
""" |
29
|
|
|
|
30
|
|
|
def initialized(self, data): |
31
|
|
|
return self.data |
32
|
|
|
|
33
|
|
|
def modified(self, data): |
34
|
|
|
name = data.get("name") |
35
|
|
|
value = data.get("value") |
36
|
|
|
|
37
|
|
|
# Handle Methods Change |
38
|
|
|
if name == "RestrictToMethod" and value: |
39
|
|
|
method_uid = value[0] |
40
|
|
|
options = self.get_instruments_options(method_uid) |
41
|
|
|
self.add_update_field("Instrument", {"options": options}) |
42
|
|
|
|
43
|
|
|
return self.data |
44
|
|
|
|
45
|
|
|
def get_instruments_options(self, method): |
46
|
|
|
"""Returns a list of dicts that represent instrument options suitable |
47
|
|
|
for a selection list, with an empty option as first item |
48
|
|
|
""" |
49
|
|
|
options = [{"title": _("No Instrument"), "value": [""]}] |
50
|
|
|
method = api.get_object(method, default=None) |
51
|
|
|
instruments = method and method.getInstruments() or [] |
52
|
|
|
for instrument in instruments: |
53
|
|
|
option = { |
54
|
|
|
"title": api.get_title(instrument), |
55
|
|
|
"value": api.get_uid(instrument) |
56
|
|
|
} |
57
|
|
|
options.append(option) |
58
|
|
|
|
59
|
|
|
return options |
60
|
|
|
|