lims_analysis_sheet: add wizard to move data lines to different/new analysis sheet

This commit is contained in:
Adrián Bernardi 2021-11-30 18:22:02 -03:00
parent ecea524ba4
commit 00cb3f18ee
5 changed files with 163 additions and 0 deletions

View file

@ -47,6 +47,7 @@ def register():
notebook.EditGroupedDataStart,
notebook.EditMultiSampleDataStart,
notebook.MultiSampleData,
notebook.MoveDataStart,
laboratory.NotebookRule,
laboratory.NotebookRuleCondition,
module='lims_analysis_sheet', type_='model')
@ -68,6 +69,7 @@ def register():
notebook.EvaluateRules,
notebook.EditGroupedData,
notebook.EditMultiSampleData,
notebook.MoveData,
module='lims_analysis_sheet', type_='wizard')
Pool.register(
sheet.AnalysisSheetReport,

View file

@ -147,6 +147,18 @@ msgctxt "field:lims.analysis_sheet.import_file.start,origin_file:"
msgid "Origin File"
msgstr "Archivo origen"
msgctxt "field:lims.analysis_sheet.move_data.start,analysis_sheet:"
msgid "Analysis Sheet"
msgstr "Hoja de análisis"
msgctxt "field:lims.analysis_sheet.move_data.start,move_to:"
msgid "Move to"
msgstr "Mover a"
msgctxt "field:lims.analysis_sheet.move_data.start,table:"
msgid "Table"
msgstr "Tabla"
msgctxt "field:lims.analysis_sheet.print_report.ask,print_expression_column:"
msgid "Print formula column"
msgstr "Incluir columnas con fórmulas"
@ -568,6 +580,10 @@ msgctxt "model:ir.action,name:wiz_analysis_sheet_limits_validation"
msgid "Limits Validation"
msgstr "05) Validación de límites"
msgctxt "model:ir.action,name:wiz_analysis_sheet_move_data"
msgid "Move Data"
msgstr "Mover datos"
msgctxt "model:ir.action,name:wiz_analysis_sheet_open_data"
msgid "Open Analysis Sheet Data"
msgstr "Abrir datos de Hoja de análisis"
@ -714,6 +730,10 @@ msgctxt "model:lims.analysis_sheet.import_file.start,name:"
msgid "Import Analysis Sheet File"
msgstr "Importar archivo de datos"
msgctxt "model:lims.analysis_sheet.move_data.start,name:"
msgid "Move Data"
msgstr "Mover datos"
msgctxt "model:lims.analysis_sheet.print_report.ask,name:"
msgid "Analysis Sheet Report"
msgstr "Informe de Hoja de análisis"
@ -1058,6 +1078,14 @@ msgctxt "selection:lims.analysis_sheet.add_control.start,type:"
msgid "RM"
msgstr "RM"
msgctxt "selection:lims.analysis_sheet.move_data.start,move_to:"
msgid "Existing sheet"
msgstr "Hoja existente"
msgctxt "selection:lims.analysis_sheet.move_data.start,move_to:"
msgid "New sheet"
msgstr "Nueva hoja"
msgctxt "selection:lims.interface,export_field_separator:"
msgid "Colon (:)"
msgstr "Dos puntos (:)"
@ -1250,6 +1278,14 @@ msgctxt "wizard_button:lims.analysis_sheet.import_file,ask_file,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt "wizard_button:lims.analysis_sheet.move_data,start,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt "wizard_button:lims.analysis_sheet.move_data,start,move:"
msgid "Move"
msgstr "Mover"
msgctxt "wizard_button:lims.analysis_sheet.print_report,ask,end:"
msgid "Cancel"
msgstr "Cancelar"

View file

@ -1698,3 +1698,101 @@ class EditMultiSampleData(Wizard):
def _save(self):
pass
class MoveDataStart(ModelView):
'Move Data'
__name__ = 'lims.analysis_sheet.move_data.start'
move_to = fields.Selection([
('new', 'New sheet'),
('exist', 'Existing sheet'),
], 'Move to', required=True)
analysis_sheet = fields.Many2One('lims.analysis_sheet',
'Analysis Sheet', required=True,
domain=[
('compilation.table', '=', Eval('table')),
('state', 'in', ['draft', 'active']),
],
states={
'invisible': Eval('move_to') != 'exist',
'required': Eval('move_to') == 'exist',
},
depends=['move_to', 'table'])
table = fields.Many2One('lims.interface.table', 'Table')
class MoveData(Wizard):
'Move Data'
__name__ = 'lims.analysis_sheet.move_data'
start_state = 'check'
check = StateTransition()
start = StateView('lims.analysis_sheet.move_data.start',
'lims_analysis_sheet.analysis_sheet_move_data_start_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Move', 'move', 'tryton-ok', default=True),
])
move = StateTransition()
def _get_analysis_sheet_id(self):
return Transaction().context.get('lims_analysis_sheet', None)
def transition_check(self):
AnalysisSheet = Pool().get('lims.analysis_sheet')
line_ids = Transaction().context.get('active_ids', None)
sheet_id = self._get_analysis_sheet_id()
if line_ids and sheet_id:
sheet = AnalysisSheet(sheet_id)
if sheet.state == 'active':
return 'start'
return 'end'
def default_start(self, fields):
AnalysisSheet = Pool().get('lims.analysis_sheet')
sheet_id = self._get_analysis_sheet_id()
sheet = AnalysisSheet(sheet_id)
defaults = {
'move_to': 'new',
'table': sheet.compilation.table.id,
}
return defaults
def transition_move(self):
pool = Pool()
AnalysisSheet = pool.get('lims.analysis_sheet')
Data = pool.get('lims.interface.data')
line_ids = Transaction().context.get('active_ids', None)
sheet_id = self._get_analysis_sheet_id()
sheet = AnalysisSheet(sheet_id)
if self.start.move_to == 'new':
with Transaction().set_user(0):
target = AnalysisSheet()
target.template = sheet.template
target.compilation = sheet.get_new_compilation()
target.professional = sheet.professional
target.laboratory = sheet.laboratory
target.save()
else:
target = self.start.analysis_sheet
with Transaction().set_context(
lims_interface_table=sheet.compilation.table.id):
lines = Data.search([
('compilation', '=', sheet.compilation.id),
('id', 'in', line_ids),
])
Data.write(lines, {
'compilation': target.compilation.id,
})
return 'end'
def end(self):
return 'reload'

View file

@ -149,5 +149,25 @@
<field name="wiz_name">lims.analysis_sheet.edit_multi_sample_data</field>
</record>
<!-- Wizard Move Data -->
<record model="ir.ui.view" id="analysis_sheet_move_data_start_form">
<field name="model">lims.analysis_sheet.move_data.start</field>
<field name="type">form</field>
<field name="name">analysis_sheet_move_data_start_form</field>
</record>
<record model="ir.action.wizard" id="wiz_analysis_sheet_move_data">
<field name="name">Move Data</field>
<field name="wiz_name">lims.analysis_sheet.move_data</field>
<field name="model">lims.interface.data</field>
</record>
<record model="ir.action.keyword" id="wiz_analysis_sheet_move_data_keyword">
<field name="keyword">form_action</field>
<field name="model">lims.interface.data,-1</field>
<field name="action" ref="wiz_analysis_sheet_move_data"/>
</record>
</data>
</tryton>

View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<form>
<label name="move_to"/>
<field name="move_to"/>
<label name="analysis_sheet"/>
<field name="analysis_sheet"/>
</form>