Skip to content

Commit

Permalink
Sampler field
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunga001 committed Dec 19, 2023
1 parent 335d85f commit 8226af5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/bika/aquaculture/extenders/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from bika.aquaculture.config import _
from bika.aquaculture.config import is_installed
from bika.aquaculture.vocabularies import BATCH_PRIORITY
from bika.aquaculture.vocabularies import getUsers
from bika.aquaculture.vocabularies import get_countries
from bika.aquaculture.interfaces import IBikaAquacultureLayer
from bika.extras.extenders.fields import ExtStringField
Expand Down Expand Up @@ -147,6 +148,18 @@
)
)

sampler_field = ExtStringField(
"Sampler",
required=False,
mode="rw",
write_permission=FieldEditContact,
vocabulary=getUsers(None, ["Sampler"]),
widget=SelectionWidget(
label=_("Sampler"),
format='select',
)
)


@implementer(ISchemaExtender, IBrowserLayerAwareExtender)
class BatchSchemaExtender(object):
Expand All @@ -160,6 +173,7 @@ class BatchSchemaExtender(object):
country_of_origin_field,
pooling_info_field,
destination_country_field,
sampler_field,
payment_method_field,
batch_priority_field,
]
Expand All @@ -185,6 +199,7 @@ def fiddle(self, schema):
"""
"""
if is_installed():
schema['Sampler'].vocabulary = getUsers(self.context, ["Sampler"])
schema['ClientBatchID'].widget.label = "Case Number"
schema['BatchLabels'].widget.label = "Case Labels"
schema['title'].widget.description = "If no Title value is entered, the Case ID will be used."
Expand Down
27 changes: 27 additions & 0 deletions src/bika/aquaculture/vocabularies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
# -*- coding: utf-8 -*-

from Products.Archetypes.public import DisplayList
from zope.interface import provider
from zope.schema.interfaces import IVocabularyFactory

from bika.aquaculture.config import _
from bika.lims import api
from senaite.core.api import geo


@provider(IVocabularyFactory)
def getUsers(context, roles, allow_empty=True):
""" Present a DisplayList containing users in the specified
list of roles
"""
pairs = allow_empty and [['', '']] or []
if not context:
return DisplayList(pairs)

mtool = api.get_tool('portal_membership')
users = mtool.searchForMembers(roles=roles)
for user in users:
uid = user.getId()
fullname = user.getProperty('fullname')
if not fullname:
fullname = uid
pairs.append((uid, fullname))
pairs.sort(lambda x, y: cmp(x[1], y[1]))
return DisplayList(pairs)


BATCH_PRIORITY = [
(_("routine"), _("Routine")),
(_("rush"), _("Rush")),
Expand Down

0 comments on commit 8226af5

Please sign in to comment.