Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated instrument locations to Dexterity #1705

Merged
merged 20 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.0.0rc3 (unreleased)
---------------------

- #1705 Migrated instrument locations to Dexterity
- #1706 Add "User name" and "User groups" columns in Lab Contacts listing
- #1702 Remove Analysis Specifications from AR Add Form
- #1700 Better styling of header and description in content views
Expand Down
29 changes: 11 additions & 18 deletions src/bika/lims/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from datetime import datetime
from datetime import timedelta

import Missing
import six

import Missing
from AccessControl.PermissionRole import rolesForPermissionOn
from Acquisition import aq_base
from bika.lims import logger
Expand Down Expand Up @@ -60,7 +60,6 @@
from zope.component.interfaces import IFactory
from zope.event import notify
from zope.lifecycleevent import ObjectCreatedEvent
from zope.lifecycleevent import modified
from zope.schema import getFieldsInOrder
from zope.security.interfaces import Unauthorized

Expand Down Expand Up @@ -132,41 +131,35 @@ def create(container, portal_type, *args, **kwargs):
:returns: The new created object
"""
from bika.lims.utils import tmpID
if kwargs.get("title") is None:
kwargs["title"] = "New {}".format(portal_type)

# generate a temporary ID
tmp_id = tmpID()
id = kwargs.pop("id", tmpID())
title = kwargs.pop("title", "New {}".format(portal_type))

# get the fti
types_tool = get_tool("portal_types")
fti = types_tool.getTypeInfo(portal_type)

if fti.product:
obj = _createObjectByType(portal_type, container, tmp_id)
obj = _createObjectByType(portal_type, container, id)
obj.processForm()
obj.edit(title=title, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be necessary to notify the modification explicitly?

notify(ObjectModifiedEvent(obj))

I recall there are some subscribers for ObjectModifiedEvent (for Contact, Batch, ...)
Probably for both ATs and DX.

Also, what if we do a noLongerProvides(IAuditLog, obj) before the edit and an alsoProvides(IAuditLog, obj) afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this modification event was always wrong in that function, because we are creating an object and not modifying it. Therefore, I think it is better to handle that internally as just one transaction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand, however, we'll need to keep this in mind. I think Batch type is the only one that might be affected by this change in core, but not sure atm about the scope of this change in other add-ons (e.g. jsonapi)

else:
# newstyle factory
factory = getUtility(IFactory, fti.factory)
obj = factory(tmp_id, *args, **kwargs)
obj = factory(id, *args, **kwargs)
if hasattr(obj, '_setPortalTypeName'):
obj._setPortalTypeName(fti.getId())
# set the title
obj.title = safe_unicode(title)
# notify that the object was created
notify(ObjectCreatedEvent(obj))
# notifies ObjectWillBeAddedEvent, ObjectAddedEvent and
# ContainerModifiedEvent
container._setObject(tmp_id, obj)
container._setObject(id, obj)
# we get the object here with the current object id, as it might be
# renamed already by an event handler
obj = container._getOb(obj.getId())

# handle AT Content
if is_at_content(obj):
obj.processForm()

# Edit after processForm; processForm does AT unmarkCreationFlag.
obj.edit(**kwargs)

# explicit notification
modified(obj)
return obj


Expand Down
76 changes: 3 additions & 73 deletions src/bika/lims/controlpanel/bika_instrumentlocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,85 +18,15 @@
# Copyright 2018-2020 by it's authors.
# Some rights reserved, see README and LICENSE.

from Products.ATContentTypes.content import schemata
from Products.Archetypes import atapi
from bika.lims import api
from bika.lims import bikaMessageFactory as _
from bika.lims.browser.bika_listing import BikaListingView
from bika.lims.config import PROJECTNAME
from bika.lims.interfaces import IInstrumentLocations
from bika.lims.permissions import AddInstrumentLocation
from bika.lims.utils import get_link
from plone.app.folder.folder import ATFolder
from plone.app.folder.folder import ATFolderSchema
from senaite.core.interfaces import IHideActionsMenu
from zope.interface import implements



class InstrumentLocationsView(BikaListingView):
"""Displays all available instrument locations in a table
"""

def __init__(self, context, request):
super(InstrumentLocationsView, self).__init__(context, request)

self.contentFilter = {'portal_type': 'InstrumentLocation',
'sort_on': 'sortable_title'}

self.context_actions = {_('Add'):
{'url': 'createObject?type_name=InstrumentLocation',
'permission': AddInstrumentLocation,
'icon': '++resource++bika.lims.images/add.png'}}

self.title = self.context.translate(_("Instrument Locations"))
self.icon = "++resource++bika.lims.images/instrumenttype_big.png"
self.description = ""

self.show_select_row = False
self.show_select_column = True
self.pagesize = 25

self.columns = {
'Title': {'title': _('Title'),
'index': 'sortable_title'},
'Description': {'title': _('Description'),
'index': 'description',
'toggle': True},
}

self.review_states = [
{'id': 'default',
'title': _('Active'),
'contentFilter': {'is_active': True},
'transitions': [{'id': 'deactivate'}, ],
'columns': ['Title', 'Description']},
{'id': 'inactive',
'title': _('Inactive'),
'contentFilter': {'is_active': False},
'transitions': [{'id': 'activate'}, ],
'columns': ['Title', 'Description']},
{'id': 'all',
'title': _('All'),
'contentFilter': {},
'columns': ['Title', 'Description']},
]

def folderitem(self, obj, item, index):
obj = api.get_object(obj)
item["Description"] = obj.Description()
item["replace"]["title"] = get_link(item["url"], item["Title"])
return item


schema = ATFolderSchema.copy()


# BBB: Only kept for backwards compatibility
class InstrumentLocations(ATFolder):
implements(IInstrumentLocations, IHideActionsMenu)
displayContentsTab = False
schema = schema
"""Moved to senaite.core.content.instrumentlocations
"""


schemata.finalizeATCTSchema(schema, folderish=True, moveDiscussion=False)
atapi.registerType(InstrumentLocations, PROJECTNAME)
8 changes: 0 additions & 8 deletions src/bika/lims/controlpanel/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@
layer="bika.lims.interfaces.IBikaLIMS"
/>

<browser:page
for="bika.lims.interfaces.IInstrumentLocations"
name="folder_view"
class=".bika_instrumentlocations.InstrumentLocationsView"
permission="senaite.core.permissions.ManageBika"
layer="bika.lims.interfaces.IBikaLIMS"
/>

<browser:page
for="bika.lims.interfaces.ICalculations"
name="folder_view"
Expand Down
2 changes: 0 additions & 2 deletions src/bika/lims/profiles/default/factorytool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<type portal_type="InstrumentMaintenanceTask"/>
<type portal_type="InstrumentScheduledTask"/>
<type portal_type="InstrumentType"/>
<type portal_type="InstrumentLocation"/>
<type portal_type="InstrumentLocations"/>
<type portal_type="InstrumentValidation"/>
<type portal_type="LabContact"/>
<type portal_type="LabProduct"/>
Expand Down
14 changes: 7 additions & 7 deletions src/bika/lims/profiles/default/structure/bika_setup/.objects
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
auditlog,AuditLog
bika_analysiscategories,AnalysisCategories
bika_analysisprofiles,AnalysisProfiles
bika_artemplates,ARTemplates
bika_analysisservices,AnalysisServices
bika_analysisspecs,AnalysisSpecs
bika_artemplates,ARTemplates
bika_attachmenttypes,AttachmentTypes
bika_batchlabels,BatchLabels
bika_calculations,Calculations
bika_instruments,Instruments
bika_instrumenttypes,InstrumentTypes
bika_instrumentlocations,InstrumentLocations
bika_labcontacts,LabContacts
bika_containers,Containers
bika_containertypes,ContainerTypes
bika_departments,Departments
laboratory,Laboratory
bika_instruments,Instruments
bika_instrumenttypes,InstrumentTypes
bika_labcontacts,LabContacts
bika_labproducts,LabProducts
bika_manufacturers,Manufacturers
bika_preservations,Preservations
Expand All @@ -24,8 +22,10 @@ bika_sampleconditions,SampleConditions
bika_samplematrices,SampleMatrices
bika_samplepoints,SamplePoints
bika_sampletypes,SampleTypes
bika_storagelocations,StorageLocations
bika_samplingdeviations,SamplingDeviations
bika_storagelocations,StorageLocations
bika_subgroups,SubGroups
bika_suppliers,Suppliers
bika_worksheettemplates,WorksheetTemplates
instrumentlocations,InstrumentLocations
laboratory,Laboratory
14 changes: 7 additions & 7 deletions src/bika/lims/profiles/default/structure/bika_setup/.preserve
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
auditlog
bika_analysiscategories
bika_analysisprofiles
bika_artemplates
bika_analysisservices
bika_analysisspecs
bika_artemplates
bika_attachmenttypes
bika_batchlabels
bika_calculations
bika_instruments
bika_instrumenttypes
bika_instrumentlocations
bika_labcontacts
bika_containers
bika_containertypes
bika_departments
laboratory
bika_instruments
bika_instrumenttypes
bika_labcontacts
bika_labproducts
bika_manufacturers
bika_preservations
Expand All @@ -26,6 +24,8 @@ bika_samplepoints
bika_sampletypes
bika_samplingdeviations
bika_storagelocations
bika_suppliers
bika_subgroups
bika_suppliers
bika_worksheettemplates
instrumentlocations
laboratory
2 changes: 0 additions & 2 deletions src/bika/lims/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
<object name="InstrumentScheduledTask" meta_type="Factory-based Type Information with dynamic views"/>
<object name="InstrumentType" meta_type="Factory-based Type Information with dynamic views"/>
<object name="InstrumentTypes" meta_type="Factory-based Type Information with dynamic views"/>
<object name="InstrumentLocation" meta_type="Factory-based Type Information with dynamic views"/>
<object name="InstrumentLocations" meta_type="Factory-based Type Information with dynamic views"/>
<object name="InstrumentValidation" meta_type="Factory-based Type Information with dynamic views"/>
<object name="Invoice" meta_type="Factory-based Type Information with dynamic views"/>
<object name="LabContact" meta_type="Factory-based Type Information with dynamic views"/>
Expand Down
57 changes: 0 additions & 57 deletions src/bika/lims/profiles/default/types/InstrumentLocation.xml

This file was deleted.

29 changes: 0 additions & 29 deletions src/bika/lims/profiles/default/types/InstrumentLocations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions src/bika/lims/profiles/default/workflows.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@
<type type_id="Departments">
<bound-workflow workflow_id="senaite_one_state_workflow"/>
</type>
<type type_id="InstrumentLocations">
<bound-workflow workflow_id="senaite_one_state_workflow"/>
</type>
<type type_id="InstrumentTypes">
<bound-workflow workflow_id="senaite_one_state_workflow"/>
</type>
Expand Down Expand Up @@ -331,9 +328,6 @@
<type type_id="Instrument">
<bound-workflow workflow_id="senaite_deactivable_type_workflow"/>
</type>
<type type_id="InstrumentLocation">
<bound-workflow workflow_id="senaite_deactivable_type_workflow"/>
</type>
<type type_id="InstrumentType">
<bound-workflow workflow_id="senaite_deactivable_type_workflow"/>
</type>
Expand Down
Loading