diff --git a/bika/lims/__init__.py b/bika/lims/__init__.py index 17de1d0f9d..74ba288369 100644 --- a/bika/lims/__init__.py +++ b/bika/lims/__init__.py @@ -31,11 +31,16 @@ allow_module('bika.lims.permissions') allow_module('bika.lims.utils') allow_module('json') -allow_module('pdb') allow_module('zope.i18n.locales') allow_module('zope.component') allow_module('plone.registry.interfaces') +import App +debug_mode = App.config.getConfiguration().debug_mode +if debug_mode: + allow_module('pdb') + allow_module('pudb') + def initialize(context): from content.analysis import Analysis diff --git a/bika/lims/browser/analysisrequest/add.py b/bika/lims/browser/analysisrequest/add.py index c7e8be919a..8925b6910e 100644 --- a/bika/lims/browser/analysisrequest/add.py +++ b/bika/lims/browser/analysisrequest/add.py @@ -1,6 +1,5 @@ import json from bika.lims.utils.sample import create_sample -from bika.lims.utils.samplepartition import create_samplepartition from bika.lims.workflow import doActionFor import plone @@ -16,7 +15,7 @@ from bika.lims.utils import getHiddenAttributesForClass, dicts_to_dict from bika.lims.utils import t from bika.lims.utils import tmpID -from bika.lims.utils.analysisrequest import create_analysisrequest +from bika.lims.utils.analysisrequest import create_analysisrequest as crar from magnitude import mg from plone.app.layout.globals.interfaces import IViewView from Products.Archetypes import PloneMessageFactory as PMF @@ -443,7 +442,7 @@ def __call__(self): ARs = [] for arnum, state in valid_states.items(): # Create the Analysis Request - ar = create_analysisrequest( + ar = crar( portal_catalog(UID=state['Client'])[0].getObject(), self.request, state @@ -471,170 +470,9 @@ def __call__(self): return json.dumps({'success': message}) - +from bika.lims import deprecated +@deprecated(comment="bika.lims.browser.analysisrequest.add." + "create_analysisrequest is deprecated and will be removed " + "in Bika LIMS 3.3", replacement=crar) def create_analysisrequest(context, request, values): - """Create an AR. - - :param context the container in which the AR will be created (Client) - :param request the request object - :param values a dictionary containing fieldname/value pairs, which - will be applied. Some fields will have specific code to handle them, - and others will be directly written to the schema. - :return the new AR instance - - Special keys present (or required) in the values dict, which are not present - in the schema: - - - Partitions: data about partitions to be created, and the - analyses that are to be assigned to each. - - - Prices: custom prices set in the HTML form. - - - ResultsRange: Specification values entered in the HTML form. - - """ - # Gather neccesary tools - workflow = getToolByName(context, 'portal_workflow') - bc = getToolByName(context, 'bika_catalog') - - # Create new sample or locate the existing for secondary AR - sample = False - if values['Sample']: - if ISample.providedBy(values['Sample']): - secondary = True - sample = values['Sample'] - samplingworkflow_enabled = sample.getSamplingWorkflowEnabled() - else: - brains = bc(UID=values['Sample']) - if brains: - secondary = True - sample = brains[0].getObject() - samplingworkflow_enabled = sample.getSamplingWorkflowEnabled() - if not sample: - secondary = False - sample = create_sample(context, request, values) - samplingworkflow_enabled = context.bika_setup.getSamplingWorkflowEnabled() - - # Create the Analysis Request - ar = _createObjectByType('AnalysisRequest', context, tmpID()) - ar.setSample(sample) - - # processform renames the sample, this requires values to contain the Sample. - values['Sample'] = sample - ar.processForm(REQUEST=request, values=values) - - # Object has been renamed - ar.edit(RequestID=ar.getId()) - - # Set initial AR state - workflow_action = 'sampling_workflow' if samplingworkflow_enabled \ - else 'no_sampling_workflow' - workflow.doActionFor(ar, workflow_action) - - - # We need to send a list of service UIDS to setAnalyses function. - # But we may have received a list of titles, list of UIDS, - # list of keywords or list of service objects! - service_uids = [] - for obj in values['Analyses']: - uid = False - # service objects - if hasattr(obj, 'portal_type') and obj.portal_type == 'AnalysisService': - uid = obj.UID() - # Analysis objects (shortcut for eg copying analyses from other AR) - elif hasattr(obj, 'portal_type') and obj.portal_type == 'Analysis': - uid = obj.getService() - # Maybe already UIDs. - if not uid: - bsc = getToolByName(context, 'bika_setup_catalog') - brains = bsc(portal_type='AnalysisService', UID=obj) - if brains: - uid = brains[0].UID - # Maybe already UIDs. - if not uid: - bsc = getToolByName(context, 'bika_setup_catalog') - brains = bsc(portal_type='AnalysisService', title=obj) - if brains: - uid = brains[0].UID - if uid: - service_uids.append(uid) - else: - logger.info("In analysisrequest.add.create_analysisrequest: cannot " - "find uid of this service: %s" % obj) - - # Set analysis request analyses - ar.setAnalyses(service_uids, - prices=values.get("Prices", []), - specs=values.get('ResultsRange', [])) - analyses = ar.getAnalyses(full_objects=True) - - skip_receive = ['to_be_sampled', 'sample_due', 'sampled', 'to_be_preserved'] - if secondary: - # Only 'sample_due' and 'sample_recieved' samples can be selected - # for secondary analyses - doActionFor(ar, 'sampled') - doActionFor(ar, 'sample_due') - sample_state = workflow.getInfoFor(sample, 'review_state') - if sample_state not in skip_receive: - doActionFor(ar, 'receive') - - for analysis in analyses: - doActionFor(analysis, 'sample_due') - analysis_state = workflow.getInfoFor(analysis, 'review_state') - if analysis_state not in skip_receive: - doActionFor(analysis, 'receive') - - if not secondary: - # Create sample partitions - partitions = [] - for n, partition in enumerate(values['Partitions']): - # Calculate partition id - partition_prefix = sample.getId() + "-P" - partition_id = '%s%s' % (partition_prefix, n + 1) - partition['part_id'] = partition_id - # Point to or create sample partition - if partition_id in sample.objectIds(): - partition['object'] = sample[partition_id] - else: - partition['object'] = create_samplepartition( - sample, - partition - ) - # now assign analyses to this partition. - obj = partition['object'] - for analysis in analyses: - if analysis.getService().UID() in partition['services']: - analysis.setSamplePartition(obj) - - partitions.append(partition) - - # If Preservation is required for some partitions, - # and the SamplingWorkflow is disabled, we need - # to transition to to_be_preserved manually. - if not samplingworkflow_enabled: - to_be_preserved = [] - sample_due = [] - lowest_state = 'sample_due' - for p in sample.objectValues('SamplePartition'): - if p.getPreservation(): - lowest_state = 'to_be_preserved' - to_be_preserved.append(p) - else: - sample_due.append(p) - for p in to_be_preserved: - doActionFor(p, 'to_be_preserved') - for p in sample_due: - doActionFor(p, 'sample_due') - doActionFor(sample, lowest_state) - doActionFor(ar, lowest_state) - - # Transition pre-preserved partitions - for p in partitions: - if 'prepreserved' in p and p['prepreserved']: - part = p['object'] - state = workflow.getInfoFor(part, 'review_state') - if state == 'to_be_preserved': - workflow.doActionFor(part, 'preserve') - - # Return the newly created Analysis Request - return ar + return crar(context, request, values) diff --git a/bika/lims/browser/analysisrequest/templates/ar_add_by_col.pt b/bika/lims/browser/analysisrequest/templates/ar_add_by_col.pt index 78b1a9c472..d4dcf1a6db 100644 --- a/bika/lims/browser/analysisrequest/templates/ar_add_by_col.pt +++ b/bika/lims/browser/analysisrequest/templates/ar_add_by_col.pt @@ -140,22 +140,6 @@ - diff --git a/bika/lims/browser/js/bika.lims.loader.js b/bika/lims/browser/js/bika.lims.loader.js index 71b0be88f6..d26d108283 100644 --- a/bika/lims/browser/js/bika.lims.loader.js +++ b/bika/lims/browser/js/bika.lims.loader.js @@ -79,8 +79,8 @@ window.bika.lims.controllers = { ['ClientSamplingRoundAddEditView'], // Sampling Rounds PrintView - ".samplinground-print-form": - ['SamplingRoundtPrintView'], + "#sr_publish_container": + ['SamplingRoundPrintView'], // Reference Samples ".portaltype-referencesample.template-analyses": @@ -211,18 +211,11 @@ window.bika.lims.loadControllers = function(all, controllerKeys) { controllers[key].forEach(function(js) { if (all == true || $.inArray(key, controllerKeys) >= 0 || $.inArray(js, _bika_lims_loaded_js) < 0) { console.debug('[bika.lims.loader] Loading '+js); - try { - obj = new window[js](); - obj.load(); - // Register the object for further access - window.bika.lims[js]=obj; - _bika_lims_loaded_js.push(js); - } catch (e) { - // statements to handle any exceptions - var msg = '[bika.lims.loader] Unable to load '+js+": "+ e.message +"\n"+e.stack; - console.warn(msg); - window.bika.lims.error(msg); - } + obj = new window[js](); + obj.load(); + // Register the object for further access + window.bika.lims[js]=obj; + _bika_lims_loaded_js.push(js); } }); } diff --git a/bika/lims/browser/js/bika.lims.samplinground.print.js b/bika/lims/browser/js/bika.lims.samplinground.print.js index b0777b0fbe..87b26a635a 100644 --- a/bika/lims/browser/js/bika.lims.samplinground.print.js +++ b/bika/lims/browser/js/bika.lims.samplinground.print.js @@ -1,57 +1,81 @@ /** * Controller class for SamplingRound Print View */ -function SamplingRoundtPrintView() { +function SamplingRoundPrintView() { var that = this; - var referrer_cookie_name = '_rspv'; + var referrer_cookie_name = '_srpv'; + // Allowed Paper sizes and default margins, in mm + var papersize_default = "A4"; + var default_margins = [20, 20, 20, 20]; + var papersize = { + 'A4': { + dimensions: [210, 297], + margins: [20, 20, 20, 20] }, + + 'letter': { + dimensions: [215.9, 279.4], + margins: [20, 20, 20, 20] }, + }; + + /** + * Entry-point method for AnalysisRequestPublishView + */ that.load = function() { + // The report will be loaded dynamically by reloadReport() + $('#report').html('').hide(); + + // Load the report + reloadReport(); + // Store referrer in cookie in case it is lost due to a page reload + var cookiename = "sr.publish.view.referrer"; var backurl = document.referrer; if (backurl) { - createCookie("sr.print.urlback", backurl); + createCookie(cookiename, backurl); } else { - backurl = readCookie("sr.print.urlback"); + backurl = readCookie(cookiename); + // Fallback to portal_url instead of staying inside publish. if (!backurl) { backurl = portal_url; } } - load_barcodes(); + $('#sel_format').change(function(e) { + reloadReport(); + }); - $('#print_button').click(function(e) { - e.preventDefault(); - window.print(); + $('#sel_layout').change(function(e) { + $('body').removeClass($('body').attr('data-layout')); + $('body').attr('data-layout', $(this).val()); + $('body').addClass($(this).val()); + reloadReport(); }); $('#cancel_button').click(function(e) { - e.preventDefault(); - location.href = backurl; + location.href=backurl; }); - - $('#template').change(function(e) { + $('#print_button').click(function(e) { + e.preventDefault(); var url = window.location.href; - var seltpl = $(this).val(); - var selcols = $("#numcols").val(); - $('#samplinground-printview').animate({opacity:0.2}, 'slow'); - $.ajax({ - url: url, - type: 'POST', - data: { "template":seltpl, - "numcols":selcols} - }) - .always(function(data) { - var htmldata = data; - var cssdata = $(htmldata).find('#report-style').html(); - $('#report-style').html(cssdata); - htmldata = $(htmldata).find('#samplinground-printview').html(); - $('#samplinground-printview').html(htmldata); - $('#samplinground-printview').animate({opacity:1}, 'slow'); - load_barcodes(); + $('#sr_publish_container').animate({opacity:0.4}, 'slow'); + var count = $('#sr_publish_container #report .report_body').length; + $('#sr_publish_container #report .report_body').each(function(){ + var rephtml = $(this).clone().wrap('