lims: entry: pre-assign sample numbers

This commit is contained in:
Adrián Bernardi 2022-02-01 13:29:50 -03:00
parent 8c387670d6
commit cec51c8343
7 changed files with 168 additions and 2 deletions

View File

@ -70,6 +70,8 @@ def register():
sample.PackagingIntegrity,
entry.EntrySuspensionReason,
entry.Entry,
entry.EntryPreAssignedSample,
entry.PreAssignSampleStart,
sample.Zone,
sample.Variety,
sample.SampleProducer,
@ -273,6 +275,7 @@ def register():
planification.PrintPendingServicesUnplannedReportStart,
module='lims', type_='model')
Pool.register(
entry.PreAssignSample,
entry.PrintAcknowledgmentOfReceipt,
control_tendency.PrintControlChart,
sample.CountersampleStoragePrint,

View File

@ -146,6 +146,10 @@ class Entry(Workflow, ModelSQL, ModelView):
('ongoing', 'closed'),
))
cls._buttons.update({
'pre_assign_sample': {
'invisible': ~Eval('state').in_(['draft']),
'depends': ['state'],
},
'create_sample': {
'invisible': ~Eval('state').in_(['draft']),
'depends': ['state'],
@ -513,6 +517,11 @@ class Entry(Workflow, ModelSQL, ModelView):
new_entries.append(new_entry)
return new_entries
@classmethod
@ModelView.button_action('lims.wiz_lims_pre_assign_sample')
def pre_assign_sample(cls, entries):
pass
@classmethod
@ModelView.button_action('lims.wiz_lims_create_sample')
def create_sample(cls, entries):
@ -802,6 +811,86 @@ class EntryAcknowledgmentContact(ModelSQL, ModelView):
])
class EntryPreAssignedSample(ModelSQL):
'Entry Pre-Assigned Sample'
__name__ = 'lims.entry.pre_assigned_sample'
entry = fields.Many2One('lims.entry', 'Entry',
ondelete='CASCADE', select=True, required=True)
number = fields.Char('Number')
used = fields.Boolean('Used')
@staticmethod
def default_used():
return False
@classmethod
def get_next_number(cls, entry_id):
next_number = cls.search([
('entry', '=', entry_id),
('used', '=', False),
], order=[('number', 'ASC')], limit=1)
if next_number:
cls.write(next_number, {'used': True})
return next_number[0].number
return None
class PreAssignSampleStart(ModelView):
'Pre-Assign Sample'
__name__ = 'lims.entry.pre_assign_sample.start'
quantity = fields.Integer('Samples quantity', required=True)
class PreAssignSample(Wizard):
'Pre-Assign Sample'
__name__ = 'lims.entry.pre_assign_sample'
start_state = 'check'
check = StateTransition()
start = StateView('lims.entry.pre_assign_sample.start',
'lims.lims_pre_assign_sample_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Pre-Assign', 'confirm', 'tryton-ok', default=True),
])
confirm = StateTransition()
def transition_check(self):
EntryPreAssignedSample = Pool().get('lims.entry.pre_assigned_sample')
entry_id = Transaction().context['active_id']
if EntryPreAssignedSample.search_count([
('entry', '=', entry_id)
]) > 0:
return 'end'
return 'start'
def transition_confirm(self):
pool = Pool()
LabWorkYear = pool.get('lims.lab.workyear')
EntryPreAssignedSample = pool.get('lims.entry.pre_assigned_sample')
workyear_id = LabWorkYear.find()
workyear = LabWorkYear(workyear_id)
sequence = workyear.get_sequence('sample')
if not sequence:
raise UserError(gettext('lims.msg_no_sample_sequence',
work_year=workyear.rec_name))
entry_id = Transaction().context['active_id']
records = []
for i in range(self.start.quantity):
records.append({
'entry': entry_id,
'number': sequence.get(),
'used': False,
})
EntryPreAssignedSample.create(records)
return 'end'
class EntrySuspensionReason(ModelSQL, ModelView):
'Entry Suspension Reason'
__name__ = 'lims.entry.suspension.reason'

View File

@ -94,6 +94,17 @@
<field name="group" ref="group_lims_entry"/>
</record>
<record model="ir.model.button" id="entry_pre_assign_sample_button">
<field name="name">pre_assign_sample</field>
<field name="string">Pre-assign sample numbers</field>
<field name="model" search="[('model', '=', 'lims.entry')]"/>
</record>
<record model="ir.model.button-res.group"
id="entry_pre_assign_sample_button_group_lims_entry">
<field name="button" ref="entry_pre_assign_sample_button"/>
<field name="group" ref="group_lims_entry"/>
</record>
<record model="ir.model.button" id="entry_create_sample_button">
<field name="name">create_sample</field>
<field name="model" search="[('model', '=', 'lims.entry')]"/>
@ -277,6 +288,19 @@
<field name="name">entry_acknowledgment_contacts_list</field>
</record>
<!-- Wizard Pre-Assign Samples -->
<record model="ir.ui.view" id="lims_pre_assign_sample_start_view_form">
<field name="model">lims.entry.pre_assign_sample.start</field>
<field name="type">form</field>
<field name="name">pre_assign_sample_start_form</field>
</record>
<record model="ir.action.wizard" id="wiz_lims_pre_assign_sample">
<field name="name">Pre-Assign Samples</field>
<field name="wiz_name">lims.entry.pre_assign_sample</field>
</record>
<!-- Entry Suspension Reason -->
<record model="ir.ui.view" id="lims_entry_suspension_reason_view_form">

View File

@ -1567,6 +1567,22 @@ msgctxt "field:lims.entry.invoice_contacts,entry:"
msgid "Entry"
msgstr "Ingreso"
msgctxt "field:lims.entry.pre_assign_sample.start,quantity:"
msgid "Samples quantity"
msgstr "Cantidad de muestras"
msgctxt "field:lims.entry.pre_assigned_sample,entry:"
msgid "Entry"
msgstr "Ingreso"
msgctxt "field:lims.entry.pre_assigned_sample,number:"
msgid "Number"
msgstr "Número"
msgctxt "field:lims.entry.pre_assigned_sample,used:"
msgid "Used"
msgstr "Utilizado"
msgctxt "field:lims.entry.report_contacts,contact:"
msgid "Contact"
msgstr "Contacto"
@ -7271,6 +7287,10 @@ msgctxt "model:ir.action,name:wiz_lims_notebook_uncertainty_calc"
msgid "Uncertainty Calculation"
msgstr "08) Cálculo de incertidumbre"
msgctxt "model:ir.action,name:wiz_lims_pre_assign_sample"
msgid "Pre-Assign Samples"
msgstr "Preasignar muestras"
msgctxt "model:ir.action,name:wiz_lims_relate_analysis"
msgid "Relate Analysis"
msgstr "Relacionar análisis"
@ -8365,6 +8385,10 @@ msgctxt "model:ir.message,text:msg_zone_code_unique_id"
msgid "Zone code must be unique"
msgstr "El código de la zona debe ser único"
msgctxt "model:ir.model.button,string:entry_pre_assign_sample_button"
msgid "Pre-assign sample numbers"
msgstr "Preasignar números de muestras"
msgctxt "model:ir.rule.group,name:rule_group_analysis_device"
msgid "User in laboratory"
msgstr ""
@ -8985,6 +9009,14 @@ msgctxt "model:lims.entry.invoice_contacts,name:"
msgid "Entry Invoice Contact"
msgstr "Contacto facturación de Ingreso"
msgctxt "model:lims.entry.pre_assign_sample.start,name:"
msgid "Pre-Assign Sample"
msgstr "Preasignar muestra"
msgctxt "model:lims.entry.pre_assigned_sample,name:"
msgid "Entry Pre-Assigned Sample"
msgstr "Muestra preasignada"
msgctxt "model:lims.entry.report_contacts,name:"
msgid "Entry Report Contact"
msgstr "Contacto informe de Ingreso"
@ -14703,6 +14735,14 @@ msgctxt "wizard_button:lims.entry.duplicate_sample,start,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt "wizard_button:lims.entry.pre_assign_sample,start,confirm:"
msgid "Pre-Assign"
msgstr "Preasignar"
msgctxt "wizard_button:lims.entry.pre_assign_sample,start,end:"
msgid "Cancel"
msgstr "Cancelar"
msgctxt "wizard_button:lims.fraction.discharge,empty,end:"
msgid "Cancel"
msgstr "Cancelar"

View File

@ -2714,6 +2714,7 @@ class Sample(ModelSQL, ModelView):
def create(cls, vlist):
pool = Pool()
LabWorkYear = pool.get('lims.lab.workyear')
EntryPreAssignedSample = pool.get('lims.entry.pre_assigned_sample')
workyear_id = LabWorkYear.find()
workyear = LabWorkYear(workyear_id)
@ -2724,7 +2725,10 @@ class Sample(ModelSQL, ModelView):
vlist = [x.copy() for x in vlist]
for values in vlist:
values['number'] = sequence.get()
number = EntryPreAssignedSample.get_next_number(values['entry'])
if not number:
number = sequence.get()
values['number'] = number
samples = super().create(vlist)
for sample in samples:
sample.warn_duplicated_label()

View File

@ -20,10 +20,11 @@
<label name="no_acknowledgment_of_receipt"/>
<field name="no_acknowledgment_of_receipt" xexpand="0" width="25"/>
</group>
<group id="create_sample_spacer" colspan="3">
<group id="create_sample_spacer" colspan="2">
</group>
<button name="create_sample" string="CREATE SAMPLES"
colspan="1" icon="tryton-add"/>
<button name="pre_assign_sample"/>
<field name="samples" colspan="4"/>
</page>
<page string="Additional Information" id="additional_information">

View File

@ -0,0 +1,5 @@
<?xml version="1.0"?>
<form>
<label name="quantity"/>
<field name="quantity"/>
</form>