Completed
Branch master (9edffc)
by Jordi
04:36
created

bika.lims.exportimport.instruments.foss.winescan.auto   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 59
dl 0
loc 88
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C Import() 0 57 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A WinescanAutoCSVParser.getAttachmentFileType() 0 2 1
A WinescanAutoImporter.getKeywordsToBeExcluded() 0 2 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
""" FOSS 'Winescan Auto'
9
"""
10
from bika.lims import bikaMessageFactory as _
11
from bika.lims.utils import t
12
from . import WinescanImporter, WinescanCSVParser
13
import json
14
import traceback
15
16
title = "FOSS - Winescan Auto"
17
18
19
def Import(context, request):
20
    """ Read FOSS's Winescan Auto analysis results
21
    """
22
    infile = request.form['wsa_file']
23
    fileformat = request.form['wsa_format']
24
    artoapply = request.form['wsa_artoapply']
25
    override = request.form['wsa_override']
26
    instrument = request.form.get('instrument', None)
27
    errors = []
28
    logs = []
29
30
    # Load the most suitable parser according to file extension/options/etc...
31
    parser = None
32
    if not hasattr(infile, 'filename'):
33
        errors.append(_("No file selected"))
34
    elif fileformat == 'csv':
35
        parser = WinescanAutoCSVParser(infile)
36
    else:
37
        errors.append(t(_("Unrecognized file format ${fileformat}",
38
                          mapping={"fileformat": fileformat})))
39
40
    if parser:
41
        # Load the importer
42
        status = ['sample_received', 'attachment_due', 'to_be_verified']
43
        if artoapply == 'received':
44
            status = ['sample_received']
45
        elif artoapply == 'received_tobeverified':
46
            status = ['sample_received', 'attachment_due', 'to_be_verified']
47
48
        over = [False, False]
49
        if override == 'nooverride':
50
            over = [False, False]
51
        elif override == 'override':
52
            over = [True, False]
53
        elif override == 'overrideempty':
54
            over = [True, True]
55
56
        importer = WinescanAutoImporter(parser=parser,
57
                                        context=context,
58
                                        allowed_ar_states=status,
59
                                        allowed_analysis_states=None,
60
                                        override=over,
61
                                        instrument_uid=instrument)
62
        tbex = ''
63
        try:
64
            importer.process()
65
        except:
66
            tbex = traceback.format_exc()
67
        errors = importer.errors
68
        logs = importer.logs
69
        warns = importer.warns
70
        if tbex:
71
            errors.append(tbex)
72
73
    results = {'errors': errors, 'log': logs, 'warns': warns}
0 ignored issues
show
introduced by
The variable warns does not seem to be defined in case parser on line 40 is False. Are you sure this can never be the case?
Loading history...
74
75
    return json.dumps(results)
76
77
78
class WinescanAutoCSVParser(WinescanCSVParser):
79
80
    def getAttachmentFileType(self):
81
        return "FOSS Winescan Auto CSV"
82
83
84
class WinescanAutoImporter(WinescanImporter):
85
86
    def getKeywordsToBeExcluded(self):
87
        return ['Info', 'ResultType', 'BottleType', 'Remark']
88