def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) # Fix Analysis Services IMM incoherences for service in portal.bika_setup.bika_analysisservices.objectValues('AnalysisService'): if (service.getInstrumentEntryOfResults() == False): # Remove any assigned instrument service.setInstruments([]) service.setInstrument(None) if (service.getManualEntryOfResults() == False): # Remove any assigned manual method service.setMethods([]) service.set_Method(None) service.reindexObject() return True
def upgrade(tool): """ Sort by Type in instruments """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) bsc = getToolByName(portal, 'bika_setup_catalog', None) if 'getInstrumentType' not in bsc.indexes(): bsc.addIndex('getInstrumentType', 'FieldIndex') bsc.addColumn('getInstrumentType') bsc.addIndex('getInstrumentTypeName','FieldIndex') bsc.addColumn('getInstrumentTypeName') #Del old "getType" Index, it's not used now. if 'getType' in bsc.indexes(): bsc.delIndex('getType') if 'getType' in bsc.indexes(): bsc.delColumn('getType') setup = portal.portal_setup logger.info("Reindex added indexes in bika_setup_catalog") bsc.manage_reindexIndex( ids=['getInstrumentType', 'getInstrumentTypeName', ]) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') stub('bika.lims.content.invoicelineitem', 'InvoiceLineItem', BaseContent) for inv in portal['invoices'].objectValues(): inv.invoice_lineitems = [] for invl in inv.objectValues(): item = dict( ItemDate=invl.ItemDate, ItemDescription=invl.ItemDescription, ClientOrderNumber=invl.ClientOrderNumber, Subtotal=invl.Subtotal, VATAmount=invl.VATAmount, Total=invl.Total, ) inv.invoice_lineitems.append(item) return True
def upgrade(tool): """ Adding getRawSamplePoint/Type idx to obtain Sample's uid easly """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) bsc = getToolByName(portal, 'bika_setup_catalog', None) if 'getRawSamplePoints' not in bsc.indexes(): bsc.addIndex('getRawSamplePoints', 'KeywordIndex') if 'getRawSampleTypes' not in bsc.indexes(): bsc.addIndex('getRawSampleTypes', 'KeywordIndex') logger.info("Reindex added indexes in bika_setup_catalog") bsc.manage_reindexIndex(ids=[ 'getRawSamplePoints', ]) bsc.manage_reindexIndex(ids=[ 'getRawSampleTypes', ]) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup mp = portal.bika_setup.manage_permission mp('Access contents information', ['Authenticated', 'Analyst', 'LabClerk'], 1) mp(permissions.View, ['Authenticated', 'Analyst', 'LabClerk'], 1) portal.bika_setup.reindexObject() for obj in portal.bika_setup.bika_analysisservices.objectValues(): mp = obj.manage_permission mp(permissions.View, ['Manager', 'LabManager', 'Analyst', 'LabClerk'], 0) mp('Access contents information', [ 'Manager', 'LabManager', 'Member', 'LabClerk', 'Analyst', 'Sampler', 'Preserver', 'Owner' ], 0) obj.reindexObject()
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup mp = portal.bika_setup.manage_permission mp('Access contents information', ['Authenticated', 'Analyst'], 1) mp(permissions.View, ['Authenticated', 'Analyst'], 1) portal.bika_setup.reindexObject() for obj in portal.bika_setup.bika_analysisservices.objectValues(): mp = obj.manage_permission mp(permissions.View, ['Manager', 'LabManager', 'Analyst'], 0) mp('Access contents information', [ 'Manager', 'LabManager', 'Member', 'LabClerk', 'Analyst', 'Sampler', 'Preserver', 'Owner' ], 0) obj.reindexObject() wf = getToolByName(portal, 'portal_workflow') # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow-csv') wf.updateRoleMappings() return True
def upgrade(tool): """ Fix workflow variable review_history permission guard. """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True wf_ids = [ 'bika_analysis_workflow', 'bika_batch_workflow', 'bika_cancellation_workflow', 'bika_duplicateanalysis_workflow', 'bika_inactive_workflow', 'bika_publication_workflow', 'bika_referenceanalysis_workflow', 'bika_referencesample_workflow', 'bika_reject_analysis_workflow', 'bika_sample_workflow', 'bika_worksheet_workflow', 'bika_worksheetanalysis_workflow', ] portal = aq_parent(aq_inner(tool)) workflow = getToolByName(portal, 'portal_workflow') for wf_id in wf_ids: wf = workflow.getWorkflowById(wf_id) if wf: rhdef = wf.variables['review_history'] rhdef.info_guard = None return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup workflow = getToolByName(portal, "portal_workflow") # /arimports folder permissions mp = portal.arimports.manage_permission mp(ManageARImport, ['Manager', ], 1) mp(permissions.ListFolderContents, ['Manager','Member',], 1) mp(permissions.AddPortalContent, ['Manager', ], 0) mp(permissions.DeleteObjects, ['Manager'], 0) mp(permissions.View, ['Manager','Member'], 0) portal.arimports.reindexObject() try: workflow.doActionFor(portal.arimports, "hide") except: pass portal.arimports.setLayout('@@arimports') return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) at = getToolByName(portal, 'archetype_tool') at.setCatalogsByType('SubGroup', ['bika_setup_catalog', ]) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'controlpanel') try: _createObjectByType("SubGroups", portal.bika_setup, "bika_subgroups", title="Sub-groups") obj = portal.bika_setup.bika_subgroups obj.unmarkCreationFlag() obj.reindexObject() except BadRequest: # folder already exists pass return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) at = getToolByName(portal, 'archetype_tool') at.setCatalogsByType('SubGroup', [ 'bika_setup_catalog', ]) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'controlpanel') try: _createObjectByType("SubGroups", portal.bika_setup, "bika_subgroups", title="Sub-groups") obj = portal.bika_setup.bika_subgroups obj.unmarkCreationFlag() obj.reindexObject() except BadRequest: # folder already exists pass return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow-csv') # /supplyorders folder permissions mp = portal.supplyorders.manage_permission mp(CancelAndReinstate, ['Manager', 'LabManager', 'LabClerk'], 0) mp(ManagePricelists, ['Manager', 'LabManager', 'Owner'], 1) mp(permissions.ListFolderContents, ['Member'], 1) mp(permissions.AddPortalContent, ['Manager', 'LabManager', 'Owner'], 0) mp(permissions.DeleteObjects, ['Manager', 'LabManager', 'Owner'], 0) mp(permissions.View, ['Manager', 'LabManager'], 0) portal.supplyorders.reindexObject() wf = getToolByName(portal, 'portal_workflow') wf.updateRoleMappings() return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup typestool = getToolByName(portal, 'portal_types') # Add the object to bika_setup try: portal.bika_setup.manage_delObjects('bika_arpriorities') except BadRequest: logger.info("Folder doesn't exist") try: typestool.constructContent(type_name="ARPriorities", container=portal.bika_setup, id='bika_arpriorities', title='AR Priorities') obj = portal.bika_setup.bika_arpriorities obj.unmarkCreationFlag() obj.reindexObject() except BadRequest: # folder already exists pass return True
def upgrade(tool): """Added bika.lims.loader.js and bika.lims.artemplate.edit.js Also fix LIMS-1352 (would have been 3042, but metadata.xml is not up to date!). """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') # LIMS-1352 proxies = portal.bika_catalog(portal_type='Sample') for brain in proxies: sample = brain.getObject() sample.setSamplingWorkflowEnabled( sample.getSamplingWorkflowEnabledDefault()) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # re-import js registry setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') # Update permissions according to Bika Setup # By default, restrict user access and management to WS bs = portal.bika_setup bs.setRestrictWorksheetUsersAccess(True) bs.setRestrictWorksheetManagement(True) bs.reindexObject() # Only LabManagers are able to create worksheets. mp = portal.manage_permission mp(ManageWorksheets, ['Manager', 'LabManager'],1) return True
def upgrade(tool): """ Sort by Type in instruments """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) bsc = getToolByName(portal, 'bika_setup_catalog', None) if 'getInstrumentType' not in bsc.indexes(): bsc.addIndex('getInstrumentType', 'FieldIndex') bsc.addColumn('getInstrumentType') bsc.addIndex('getInstrumentTypeName', 'FieldIndex') bsc.addColumn('getInstrumentTypeName') #Del old "getType" Index, it's not used now. if 'getType' in bsc.indexes(): bsc.delIndex('getType') if 'getType' in bsc.indexes(): bsc.delColumn('getType') setup = portal.portal_setup logger.info("Reindex added indexes in bika_setup_catalog") bsc.manage_reindexIndex(ids=[ 'getInstrumentType', 'getInstrumentTypeName', ]) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') stub('bika.lims.content.pricelistlineitem', 'PricelistLineItem', BaseContent) for pl in portal['pricelists'].objectValues(): pl.pricelist_lineitems = [] for pli in pl.objectValues(): item = dict( title=pli.title, ItemDescription=pli.ItemDescription, Accredited=pli.Accredited, Subtotal="%d.%d" % (pli.Subtotal[0], pli.Subtotal[1]), VATAmount="%d.%d" % (pli.VATAmount[0], pli.VATAmount[1]), Total="%d.%d" % (pli.Total[0], pli.Total[1]), CategoryTitle=pli.CategoryTitle, ) pl.pricelist_lineitems.append(item) return True
def upgrade(tool): """ Refactor ARs listing to allow sorting by priority """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True def addIndex(cat, *args): try: cat.addIndex(*args) except: pass portal = aq_parent(aq_inner(tool)) # Create new indexes bc = getToolByName(portal, 'bika_catalog') addIndex(bc, 'Priority', 'FieldIndex') addIndex(bc, 'BatchUID', 'FieldIndex') bc.manage_reindexIndex(ids=[ 'Priority', 'BatchUID', ]) bac = getToolByName(portal, 'bika_analysis_catalog') addIndex(bac, 'Priority', 'FieldIndex') bac.manage_reindexIndex(ids=[ 'Priority', ]) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # re-import js registry setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') # Update permissions according to Bika Setup # By default, restrict user access and management to WS bs = portal.bika_setup bs.setRestrictWorksheetUsersAccess(True) bs.setRestrictWorksheetManagement(True) bs.reindexObject() # Only LabManagers are able to create worksheets. mp = portal.manage_permission mp(ManageWorksheets, ['Manager', 'LabManager'], 1) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup mp = portal.bika_setup.manage_permission mp('Access contents information', ['Authenticated', 'Analyst'], 1) mp(permissions.View, ['Authenticated', 'Analyst'], 1) portal.bika_setup.reindexObject() for obj in portal.bika_setup.bika_analysisservices.objectValues(): mp = obj.manage_permission mp(permissions.View, ['Manager', 'LabManager', 'Analyst'], 0) mp('Access contents information', ['Manager', 'LabManager', 'Member', 'LabClerk', 'Analyst', 'Sampler', 'Preserver', 'Owner'], 0) obj.reindexObject() wf = getToolByName(portal, 'portal_workflow') # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow-csv') wf.updateRoleMappings() return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup workflow = getToolByName(portal, "portal_workflow") # /arimports folder permissions mp = portal.arimports.manage_permission mp(ManageARImport, [ 'Manager', ], 1) mp(permissions.ListFolderContents, [ 'Manager', 'Member', ], 1) mp(permissions.AddPortalContent, [ 'Manager', ], 0) mp(permissions.DeleteObjects, ['Manager'], 0) mp(permissions.View, ['Manager', 'Member'], 0) portal.arimports.reindexObject() try: workflow.doActionFor(portal.arimports, "hide") except: pass portal.arimports.setLayout('@@arimports') return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # Add new Client role role = "Client" if role not in portal.acl_users.portal_role_manager.listRoleIds(): portal.acl_users.portal_role_manager.addRole(role) portal._addRole(role) # Add the role Client role to Clients group portal.portal_groups.editGroup('Clients', roles=['Member', 'Authenticated', 'Client']) # Add all Client contacts to Clients group for client in portal.clients.values(): for contact in client.getContacts(): user = portal.portal_membership.getMemberById(contact.getUsername()) if user is not None: portal.portal_groups.addPrincipalToGroup(user.getUserName(), "Clients") # Add AddAttachment permission to Clients mp = portal.manage_permission mp(AddAttachment, ['Manager', 'LabManager', 'Owner' 'Analyst', 'LabClerk', 'Client', 'Sampler'], 0) # Add Analysis Services View permission to Clients mp = portal.bika_setup.bika_analysisservices.manage_permission mp('Access contents information', ['Authenticated', 'Analyst', 'Client'], 1) mp(permissions.View, ['Authenticated', 'Analyst', 'Client'], 1) portal.bika_setup.bika_analysisservices.reindexObject() for obj in portal.bika_setup.bika_analysisservices.objectValues(): mp = obj.manage_permission mp(permissions.View, ['Manager', 'LabManager', 'Analyst', 'Client'], 0) mp('Access contents information', ['Manager', 'LabManager', 'Member', 'LabClerk', 'Analyst', 'Client', 'Sampler', 'Preserver', 'Owner'], 0) obj.reindexObject() # Grant AttachmentType view access to Clients mp = portal.bika_setup.bika_attachmenttypes.manage_permission mp('Access contents information', ['Authenticated', 'Analyst', 'Client'], 1) mp(permissions.View, ['Authenticated', 'Analyst', 'Client'], 1) portal.bika_setup.bika_attachmenttypes.reindexObject() wf = getToolByName(portal, 'portal_workflow') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow-csv') wf.updateRoleMappings() return True
def upgrade(tool): """Added bika.lims.analysisservice.edit.js """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') # apply new method/calculation data to old Analysis Services portal = aq_parent(aq_inner(tool)) pc = getToolByName(portal, 'portal_catalog') bsc = getToolByName(portal, 'bika_setup_catalog') rc = getToolByName(portal, REFERENCE_CATALOG) proxies = pc(portal_type="AnalysisService") for proxy in proxies: an = proxy.getObject() rels = an.at_references.objectValues() oldmethod = None oldinstrument = None oldcalc = None for rel in rels: if rel.relationship == 'AnalysisServiceCalculation': oldcalc = rc.lookupObject(rel.targetUID) elif rel.relationship == 'AnalysisServiceInstrument': oldinstrument = rc.lookupObject(rel.targetUID) elif rel.relationship == 'AnalysisServiceMethod': oldmethod = rc.lookupObject(rel.targetUID) if oldmethod and oldcalc and oldinstrument: break # Reset the method, instrument and calculations if oldmethod: an.Schema().getField('Methods').set(an, [ oldmethod.UID(), ]) an.Schema().getField('_Method').set(an, oldmethod.UID()) if oldinstrument: an.Schema().getField('Instruments').set(an, [ oldinstrument.UID(), ]) an.Schema().getField('Instrument').set(an, oldinstrument.UID()) if oldcalc: an.setUseDefaultCalculation(False) an.Schema().getField('DeferredCalculation').set(an, oldcalc.UID()) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup typestool = getToolByName(portal, 'portal_types') # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow') # Add the SupplyOrderFolder /supplyorders try: typestool.constructContent(type_name="SupplyOrderFolder", container=portal, id='supplyorders', title='Supply Orders') obj = portal['supplyorders'] obj.unmarkCreationFlag() obj.reindexObject() except BadRequest: # folder already exists pass # /supplyorders folder permissions mp = portal.supplyorders.manage_permission mp(permissions.ListFolderContents, [ 'Manager', 'LabManager', 'LabClerk', ], 0) mp(permissions.View, ['Manager', 'LabManager', 'LabClerk'], 0) mp('Access contents information', ['Manager', 'LabManager', 'LabClerk'], 0) mp(AddSupplyOrder, ['Manager', 'LabManager', 'Owner'], 0) portal.supplyorders.reindexObject() # /pricelists folder permissions mp = portal.pricelists.manage_permission mp(permissions.ListFolderContents, [ 'Manager', 'LabManager', 'LabClerk', ], 0) mp(permissions.View, ['Manager', 'LabManager', 'LabClerk'], 0) mp('Access contents information', ['Manager', 'LabManager', 'LabClerk'], 0) mp(AddPricelist, ['Manager', 'LabManager', 'LabClerk'], 0) portal.pricelists.reindexObject() return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) at = getToolByName(portal, 'archetype_tool') at.setCatalogsByType('ARPriority', ['bika_setup_catalog', ]) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) portal.portal_actions.portal_tabs.queries.visible = False return True
def upgrade(tool): """ Re-import types tool to add condition for sample/partitions view """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo')
def upgrade(tool): """Added bika.lims.analysisservice.edit.js """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') # apply new method/calculation data to old Analysis Services portal = aq_parent(aq_inner(tool)) pc = getToolByName(portal, 'portal_catalog') bsc = getToolByName(portal, 'bika_setup_catalog') rc=getToolByName(portal, REFERENCE_CATALOG) proxies = pc(portal_type="AnalysisService") for proxy in proxies: an = proxy.getObject() rels = an.at_references.objectValues() oldmethod = None oldinstrument = None oldcalc = None for rel in rels: if rel.relationship == 'AnalysisServiceCalculation': oldcalc=rc.lookupObject(rel.targetUID) elif rel.relationship == 'AnalysisServiceInstrument': oldinstrument=rc.lookupObject(rel.targetUID) elif rel.relationship == 'AnalysisServiceMethod': oldmethod=rc.lookupObject(rel.targetUID) if oldmethod and oldcalc and oldinstrument: break # Reset the method, instrument and calculations if oldmethod: an.Schema().getField('Methods').set(an, [oldmethod.UID(),]) an.Schema().getField('_Method').set(an, oldmethod.UID()) if oldinstrument: an.Schema().getField('Instruments').set(an, [oldinstrument.UID(),]) an.Schema().getField('Instrument').set(an, oldinstrument.UID()) if oldcalc: an.setUseDefaultCalculation(False); an.Schema().getField('DeferredCalculation').set(an, oldcalc.UID()) return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile( 'profile-bika.lims:default', 'propertiestool') return True
def upgrade(tool): """Upgrade step required for Bika LIMS 3.1.9 """ portal = aq_parent(aq_inner(tool)) # Adding new feature multiple profiles per Analysis Request multipleAnalysisProfiles(portal) setup = portal.portal_setup # Updated profile steps setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow-csv') # important info about upgrade steps in # http://stackoverflow.com/questions/7821498/is-there-a-good-reference-list-for-the-names-of-the-genericsetup-import-steps setup.runImportStepFromProfile('profile-bika.lims:default', 'skins') # Update workflow permissions wf = getToolByName(portal, 'portal_workflow') wf.updateRoleMappings() qi = portal.portal_quickinstaller ufrom = qi.upgradeInfo('bika.lims')['installedVersion'] logger.info("Upgrading Bika LIMS: %s -> %s" % (ufrom, '319')) # Migrations return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup typestool = getToolByName(portal, 'portal_types') # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow') return True
def upgrade(tool): """ JS structure refactoring """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup typestool = getToolByName(portal, 'portal_types') # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') setup.runImportStepFromProfile('profile-bika.lims:default', 'workflow') # Add the SupplyOrderFolder /supplyorders try: typestool.constructContent(type_name="SupplyOrderFolder", container=portal, id='supplyorders', title='Supply Orders') obj = portal['supplyorders'] obj.unmarkCreationFlag() obj.reindexObject() except BadRequest: # folder already exists pass # /supplyorders folder permissions mp = portal.supplyorders.manage_permission mp(permissions.ListFolderContents, ['Manager', 'LabManager', 'LabClerk', ], 0) mp(permissions.View, ['Manager', 'LabManager', 'LabClerk'], 0) mp('Access contents information', ['Manager', 'LabManager', 'LabClerk'], 0) mp(AddSupplyOrder, ['Manager', 'LabManager', 'Owner'], 0) portal.supplyorders.reindexObject() # /pricelists folder permissions mp = portal.pricelists.manage_permission mp(permissions.ListFolderContents, ['Manager', 'LabManager', 'LabClerk', ], 0) mp(permissions.View, ['Manager', 'LabManager', 'LabClerk'], 0) mp('Access contents information', ['Manager', 'LabManager', 'LabClerk'], 0) mp(AddPricelist, ['Manager', 'LabManager', 'LabClerk'], 0) portal.pricelists.reindexObject() return True
def upgrade(tool): """Added bika.lims.client.view.js """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # reread jsregistry with the new data setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') return True
def upgrade(tool): """ Remove Maintenance, Validations, Calibrations ans Schedule https://github.com/bikalabs/Bika-LIMS/issues/1134 """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') return True
def upgrade(tool): """Added bika.lims.loader.js and bika.lims.method.edit.js """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') return True
def upgrade(tool): """Added D3.js library and D3 Control-chart for Instrument QC """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup # update affected tools setup.runImportStepFromProfile('profile-bika.lims:default', 'jsregistry') return True
def upgrade(tool): """Add the bika-frontpage view to the selectable views. This will not set the default, but all new sites will have the 'properties.xml' loaded, which does set the default. """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup setup.runImportStepFromProfile('profile-bika.lims:default', 'typeinfo') return True
def upgrade(tool): """ Convert analysis specs to AR specs in AR.ResultsRange. """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) bc = getToolByName(portal, 'bika_catalog', None) bsc = getToolByName(portal, 'bika_setup_catalog', None) # for each AR proxies = bc(portal_type="AnalysisRequest") for proxy in proxies: ar = proxy.getObject() # get the AR.Specification arspec = ar.getSpecification() rr = arspec.getResultsRange() if arspec else [] # Get analysis specifications specs = [] for analysis in ar.getAnalyses(full_objects=True): spec = getattr(analysis, 'specification', False) if spec: spec['keyword'] = analysis.getService().getKeyword() spec['uid'] = analysis.UID() specs.append(spec) # mix in the analysis spec values for s in specs: s_in_rr = False for i, r in enumerate(rr): if s['keyword'] == r['keyword']: rr[i].update(s) s_in_rr = True if not s_in_rr: rr.append(s) # set AR.ResultsRange ar.setResultsRange(rr) return True
def upgrade(tool): """ """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) portal_catalog = getToolByName(portal, "portal_catalog") typestool = getToolByName(portal, "portal_types") workflowtool = getToolByName(portal, "portal_workflow") setup = portal.portal_setup # Changes to the catalogs at = getToolByName(portal, "archetype_tool") at.setCatalogsByType("Batch", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("AnalysisRequest", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("Sample", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("SamplePartition", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("ReferenceSample", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("Report", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("Worksheet", ["bika_catalog", "portal_catalog"]) at.setCatalogsByType("AnalysisService", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("SampleType", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("SamplePoint", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("Instrument", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("Method", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("Calculation", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("AnalysisProfile", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("ARTemplate", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("LabProduct", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("LabContact", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("ReferenceManufacturer", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("ReferenceSupplier", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("ReferenceDefinition", ["bika_setup_catalog", "portal_catalog"]) at.setCatalogsByType("WorksheetTemplate", ["bika_setup_catalog", "portal_catalog"]) portal_catalog.clearFindAndRebuild() return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) # missing /supplyorders folder permission clients = portal.clients.objectValues() for client in clients: mp = client.manage_permission mp(AddSupplyOrder, ['Manager', 'LabManager', 'Owner'], 0) client.reindexObject() return True
def upgrade(tool): """LIMS-1275 - Remove acquisition for "Modify portal content" permission """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) # /bika_setup - mp = portal.bika_setup.manage_permission mp(permissions.ModifyPortalContent, ['Manager', 'LabManager'], 0) portal.batches.reindexObject() return True
def upgrade(tool): # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) for pricelist in portal.pricelists.objectValues('Pricelist'): for broken in pricelist.objectValues('PriceListLineItem'): pricelist.manage_delObjects([broken.id]) pc = getToolByName(portal, 'portal_catalog') pc.refreshCatalog(clear=1) return True
def upgrade(tool): """ Add Storage locacations to ARs and Samples. """ # Hack prevent out-of-date upgrading # Related: PR #1484 # https://github.com/bikalabs/Bika-LIMS/pull/1484 from lims.upgrade import skip_pre315 if skip_pre315(aq_parent(aq_inner(tool))): return True portal = aq_parent(aq_inner(tool)) setup = portal.portal_setup bc = getToolByName(portal, 'bika_catalog') for brain in bc(portal_type='AnalysisRequest'): obj = brain.getObject() if not obj.getPriority(): obj.setDefaultPriority()