lims_analysis_sheet: Interface: define file type for export
This commit is contained in:
parent
a72e40ed5d
commit
5437809785
|
@ -6,7 +6,7 @@ from datetime import datetime
|
|||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, Bool, Or
|
||||
from trytond.pyson import Eval, Bool, Or, And
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.lims_interface.data import Adapter
|
||||
|
||||
|
@ -73,13 +73,69 @@ class Compilation(metaclass=PoolMeta):
|
|||
class Column(metaclass=PoolMeta):
|
||||
__name__ = 'lims.interface.column'
|
||||
|
||||
destination_column = fields.Integer('Destination Column',
|
||||
destination_column = fields.Integer('Column',
|
||||
states={
|
||||
'invisible': Eval('_parent_interface', {}).get(
|
||||
'export_template_type') == 'txt',
|
||||
},
|
||||
help='Mapped column in batch file')
|
||||
destination_start = fields.Integer('Field start',
|
||||
states={
|
||||
'required': Eval('_parent_interface', {}).get(
|
||||
'export_template_type') == 'txt',
|
||||
'invisible': Eval('_parent_interface', {}).get(
|
||||
'export_template_type') != 'txt',
|
||||
})
|
||||
destination_end = fields.Integer('Field end',
|
||||
states={
|
||||
'required': Eval('_parent_interface', {}).get(
|
||||
'export_template_type') == 'txt',
|
||||
'invisible': Eval('_parent_interface', {}).get(
|
||||
'export_template_type') != 'txt',
|
||||
})
|
||||
|
||||
|
||||
class Interface(metaclass=PoolMeta):
|
||||
__name__ = 'lims.interface'
|
||||
|
||||
export_file_type = fields.Selection([
|
||||
(None, ''),
|
||||
('excel', 'Excel'),
|
||||
('csv', 'Comma Separated Values'),
|
||||
('txt', 'Text File'),
|
||||
], 'File Type', sort=False)
|
||||
export_field_separator = fields.Selection([
|
||||
('comma', 'Comma (,)'),
|
||||
('colon', 'Colon (:)'),
|
||||
('semicolon', 'Semicolon (;)'),
|
||||
('tab', 'Tab'),
|
||||
('space', 'Space'),
|
||||
('other', 'Other'),
|
||||
], 'Field separator', sort=False,
|
||||
states={
|
||||
'required': Eval('export_file_type') == 'csv',
|
||||
'invisible': Eval('export_file_type') != 'csv',
|
||||
},
|
||||
depends=['export_file_type'])
|
||||
export_field_separator_other = fields.Char('Other',
|
||||
states={
|
||||
'required': And(
|
||||
Eval('export_file_type') == 'csv',
|
||||
Eval('export_field_separator') == 'other'),
|
||||
'invisible': Or(
|
||||
Eval('export_file_type') != 'csv',
|
||||
Eval('export_field_separator') != 'other'),
|
||||
},
|
||||
depends=['export_file_type', 'export_field_separator'])
|
||||
|
||||
@staticmethod
|
||||
def default_export_template_type():
|
||||
return 'csv'
|
||||
|
||||
@staticmethod
|
||||
def default_export_field_separator():
|
||||
return 'semicolon'
|
||||
|
||||
def _get_fields_tree_view(self):
|
||||
fields = super(Interface, self)._get_fields_tree_view()
|
||||
fields.append('<field name="annulled"/>')
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
<tryton>
|
||||
<data>
|
||||
|
||||
<!-- Interface -->
|
||||
|
||||
<record model="ir.ui.view" id="interface_view_form">
|
||||
<field name="model">lims.interface</field>
|
||||
<field name="inherit" ref="lims_interface.lims_interface_view_form"/>
|
||||
<field name="name">interface_form</field>
|
||||
</record>
|
||||
|
||||
<!-- Interface Column -->
|
||||
|
||||
<record model="ir.ui.view" id="interface_column_view_form">
|
||||
|
|
|
@ -155,9 +155,29 @@ msgctxt "field:lims.configuration.sequence,analysis_sheet_sequence:"
|
|||
msgid "Analysis Sheet Sequence"
|
||||
msgstr "Secuencia de Hoja de análisis"
|
||||
|
||||
msgctxt "field:lims.interface,export_field_separator:"
|
||||
msgid "Field separator"
|
||||
msgstr "Separador de campos"
|
||||
|
||||
msgctxt "field:lims.interface,export_field_separator_other:"
|
||||
msgid "Other"
|
||||
msgstr "Otro"
|
||||
|
||||
msgctxt "field:lims.interface,export_file_type:"
|
||||
msgid "File Type"
|
||||
msgstr "Tipo de archivo"
|
||||
|
||||
msgctxt "field:lims.interface.column,destination_column:"
|
||||
msgid "Destination Column"
|
||||
msgstr "Columna destino"
|
||||
msgid "Column"
|
||||
msgstr "Columna"
|
||||
|
||||
msgctxt "field:lims.interface.column,destination_end:"
|
||||
msgid "Field end"
|
||||
msgstr "Campo fin"
|
||||
|
||||
msgctxt "field:lims.interface.column,destination_start:"
|
||||
msgid "Field start"
|
||||
msgstr "Campo inicio"
|
||||
|
||||
msgctxt "field:lims.interface.compilation,analysis_sheet:"
|
||||
msgid "Analysis Sheet"
|
||||
|
@ -696,6 +716,42 @@ msgctxt "selection:lims.analysis_sheet.add_control.start,type:"
|
|||
msgid "RM"
|
||||
msgstr "RM"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Colon (:)"
|
||||
msgstr "Dos puntos (:)"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Comma (,)"
|
||||
msgstr "Coma (,)"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Other"
|
||||
msgstr "Otro"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Semicolon (;)"
|
||||
msgstr "Punto y coma (;)"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Space"
|
||||
msgstr "Espacio"
|
||||
|
||||
msgctxt "selection:lims.interface,export_field_separator:"
|
||||
msgid "Tab"
|
||||
msgstr "Tabulador"
|
||||
|
||||
msgctxt "selection:lims.interface,export_file_type:"
|
||||
msgid "Comma Separated Values"
|
||||
msgstr "Valores separados por coma (.csv)"
|
||||
|
||||
msgctxt "selection:lims.interface,export_file_type:"
|
||||
msgid "Excel"
|
||||
msgstr "Excel"
|
||||
|
||||
msgctxt "selection:lims.interface,export_file_type:"
|
||||
msgid "Text File"
|
||||
msgstr "Archivo de texto"
|
||||
|
||||
msgctxt "selection:lims.planification.relate_technicians.result,grouping:"
|
||||
msgid "Analysis sheet"
|
||||
msgstr "Hoja de análisis"
|
||||
|
@ -776,6 +832,10 @@ msgctxt "view:lims.interface.column:"
|
|||
msgid "Export"
|
||||
msgstr "Exportación"
|
||||
|
||||
msgctxt "view:lims.interface:"
|
||||
msgid "Export"
|
||||
msgstr "Exportación"
|
||||
|
||||
msgctxt "view:lims.planification:"
|
||||
msgid "Search Analysis Sheets"
|
||||
msgstr "Buscar Hojas de ensayos"
|
||||
|
|
|
@ -683,17 +683,24 @@ class ExportAnalysisSheetFile(Wizard):
|
|||
'file': cast(file_) if file_ else None,
|
||||
}
|
||||
|
||||
def get_file(self, sheet_id, sep=';', newline='\n'):
|
||||
pool = Pool()
|
||||
Column = pool.get('lims.interface.column')
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
Data = pool.get('lims.interface.data')
|
||||
def get_file(self, sheet_id):
|
||||
AnalysisSheet = Pool().get('lims.analysis_sheet')
|
||||
|
||||
if not sheet_id:
|
||||
return
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
|
||||
# TODO: use lims.interface.table.field
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
file_type = sheet.template.interface.export_file_type
|
||||
if not file_type:
|
||||
return
|
||||
|
||||
return getattr(self, 'export_%s' % file_type)(sheet)
|
||||
|
||||
def export_csv(self, sheet, newline='\n'):
|
||||
pool = Pool()
|
||||
Column = pool.get('lims.interface.column')
|
||||
Data = pool.get('lims.interface.data')
|
||||
|
||||
columns = Column.search([
|
||||
('interface', '=', sheet.template.interface),
|
||||
('destination_column', '!=', None),
|
||||
|
@ -702,6 +709,16 @@ class ExportAnalysisSheetFile(Wizard):
|
|||
return
|
||||
cols = [c.alias for c in columns]
|
||||
|
||||
separator = {
|
||||
'comma': ',',
|
||||
'colon': ':',
|
||||
'semicolon': ';',
|
||||
'tab': '\t',
|
||||
'space': ' ',
|
||||
'other': sheet.template.interface.export_field_separator_other,
|
||||
}
|
||||
delimiter = separator[sheet.template.interface.export_field_separator]
|
||||
|
||||
file_ = StringIO(newline=newline)
|
||||
with Transaction().set_context(
|
||||
lims_interface_compilation=sheet.compilation.id,
|
||||
|
@ -713,13 +730,20 @@ class ExportAnalysisSheetFile(Wizard):
|
|||
entry = ''
|
||||
for field in cols:
|
||||
if entry:
|
||||
entry += sep
|
||||
entry += str(getattr(line, field))
|
||||
entry += delimiter
|
||||
entry += str(getattr(line, field) or '')
|
||||
entry += newline
|
||||
file_.write(entry)
|
||||
|
||||
if file_:
|
||||
return str(file_.getvalue()).encode('utf-8')
|
||||
if not file_:
|
||||
return
|
||||
|
||||
return str(file_.getvalue()).encode('utf-8')
|
||||
|
||||
def export_txt(self, sheet):
|
||||
return
|
||||
|
||||
def export_excel(self, sheet):
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
<xpath expr="/form/group[@id='storage_field']"
|
||||
position="after">
|
||||
<separator id="export" colspan="4" string="Export"/>
|
||||
<label name="destination_column"/>
|
||||
<field name="destination_column"/>
|
||||
<group id="export_spreadsheet" colspan="4" col="4">
|
||||
<label name="destination_column"/>
|
||||
<field name="destination_column"/>
|
||||
</group>
|
||||
<label name="destination_start"/>
|
||||
<field name="destination_start"/>
|
||||
<label name="destination_end"/>
|
||||
<field name="destination_end"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='controller']" position="after">
|
||||
<page id="export" string="Export">
|
||||
<label name="export_file_type"/>
|
||||
<field name="export_file_type"/>
|
||||
<group id="separators" colspan="4" col="6">
|
||||
<label name="export_field_separator"/>
|
||||
<field name="export_field_separator"/>
|
||||
<label name="export_field_separator_other"/>
|
||||
<field name="export_field_separator_other"/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
|
@ -20,7 +20,7 @@ msgstr "Controlador"
|
|||
|
||||
msgctxt "field:lims.interface,field_separator:"
|
||||
msgid "Field separator"
|
||||
msgstr "Campo separador"
|
||||
msgstr "Separador de campos"
|
||||
|
||||
msgctxt "field:lims.interface,field_separator_other:"
|
||||
msgid "Other"
|
||||
|
|
Loading…
Reference in New Issue