mirror of
https://github.com/Kalenis/kalenislims.git
synced 2023-12-14 07:13:04 +01:00
lims/lims_analysis_sheet: Entry Detail: store plannable condition
This commit is contained in:
parent
1c17786f2c
commit
ab453cb7ca
|
@ -1403,7 +1403,6 @@ class Analysis(Workflow, ModelSQL, ModelView):
|
|||
Analysis = pool.get('lims.analysis')
|
||||
Service = pool.get('lims.service')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
|
||||
date_from = context.get('date_from')
|
||||
date_to = context.get('date_to')
|
||||
|
@ -1422,15 +1421,16 @@ class Analysis(Workflow, ModelSQL, ModelView):
|
|||
if preplanned_services:
|
||||
preplanned_services_ids = ', '.join(str(s) for s in
|
||||
preplanned_services)
|
||||
preplanned_clause = ('AND service.id NOT IN (' +
|
||||
preplanned_clause = ('AND srv.id NOT IN (' +
|
||||
preplanned_services_ids + ')')
|
||||
|
||||
not_planned_services_clause = ''
|
||||
not_planned_services_clause = 'AND id = 0'
|
||||
cursor.execute('SELECT DISTINCT(d.service) '
|
||||
'FROM "' + EntryDetailAnalysis._table + '" d '
|
||||
'INNER JOIN "' + Analysis._table + '" a '
|
||||
'ON a.id = d.analysis '
|
||||
'WHERE d.state IN (\'draft\', \'unplanned\') '
|
||||
'WHERE d.plannable = TRUE '
|
||||
'AND d.state IN (\'draft\', \'unplanned\') '
|
||||
'AND a.behavior != \'internal_relation\'')
|
||||
not_planned_services = [s[0] for s in cursor.fetchall()]
|
||||
if not_planned_services:
|
||||
|
@ -1448,17 +1448,14 @@ class Analysis(Workflow, ModelSQL, ModelView):
|
|||
res = {}
|
||||
for analysis_id in all_analysis_ids:
|
||||
count = 0
|
||||
cursor.execute('SELECT service.id '
|
||||
'FROM "' + Service._table + '" service '
|
||||
'INNER JOIN "' + Fraction._table + '" fraction '
|
||||
'ON fraction.id = service.fraction '
|
||||
'INNER JOIN "' + FractionType._table + '" f_type '
|
||||
'ON f_type.id = fraction.type '
|
||||
'WHERE service.analysis = %s '
|
||||
'AND service.confirmation_date::date >= %s::date '
|
||||
'AND service.confirmation_date::date <= %s::date '
|
||||
'AND fraction.confirmed = TRUE '
|
||||
'AND f_type.plannable = TRUE ' +
|
||||
cursor.execute('SELECT srv.id '
|
||||
'FROM "' + Service._table + '" srv '
|
||||
'INNER JOIN "' + Fraction._table + '" frc '
|
||||
'ON frc.id = srv.fraction '
|
||||
'WHERE srv.analysis = %s '
|
||||
'AND srv.confirmation_date::date >= %s::date '
|
||||
'AND srv.confirmation_date::date <= %s::date '
|
||||
'AND frc.confirmed = TRUE ' +
|
||||
preplanned_clause,
|
||||
(analysis_id, date_from, date_to))
|
||||
pending_services = [s[0] for s in cursor.fetchall()]
|
||||
|
@ -1470,7 +1467,6 @@ class Analysis(Workflow, ModelSQL, ModelView):
|
|||
'WHERE id IN (' + pending_services_ids + ') ' +
|
||||
not_planned_services_clause)
|
||||
count = cursor.fetchone()[0]
|
||||
|
||||
res[analysis_id] = count
|
||||
return res
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from datetime import datetime
|
|||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.application import MIMEApplication
|
||||
from trytond import backend
|
||||
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
|
||||
from trytond.wizard import Wizard, StateTransition, StateView, StateReport, \
|
||||
Button
|
||||
|
@ -786,12 +787,44 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
|
|||
cie_max_value = fields.Char('Maximum value')
|
||||
cie_fraction_type = fields.Function(fields.Boolean('Blind Sample'),
|
||||
'get_cie_fraction_type')
|
||||
plannable = fields.Boolean('Plannable', readonly=True, select=True)
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
tablehandler = TableHandler(cls, module_name)
|
||||
|
||||
plannable_exist = tablehandler.column_exist('plannable')
|
||||
|
||||
super(EntryDetailAnalysis, cls).__register__(module_name)
|
||||
|
||||
if not plannable_exist:
|
||||
cursor = Transaction().connection.cursor()
|
||||
pool = Pool()
|
||||
Service = pool.get('lims.service')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
cursor.execute('UPDATE "' + cls._table + '" d '
|
||||
'SET plannable = ft.plannable FROM '
|
||||
'"' + Service._table + '" srv, '
|
||||
'"' + Fraction._table + '" frc, '
|
||||
'"' + FractionType._table + '" ft '
|
||||
'WHERE srv.id = d.service '
|
||||
'AND frc.id = srv.fraction '
|
||||
'AND ft.id = frc.type')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(EntryDetailAnalysis, cls).__setup__()
|
||||
cls._order.insert(0, ('service', 'DESC'))
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for values in vlist:
|
||||
values['plannable'] = cls._get_plannable(values)
|
||||
return super(EntryDetailAnalysis, cls).create(vlist)
|
||||
|
||||
@classmethod
|
||||
def copy(cls, details, default=None):
|
||||
if default is None:
|
||||
|
@ -825,7 +858,6 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
|
|||
Company = pool.get('company.company')
|
||||
|
||||
lines_create = []
|
||||
|
||||
for detail in details:
|
||||
cursor.execute('SELECT default_repetitions, '
|
||||
'initial_concentration, final_concentration, start_uom, '
|
||||
|
@ -1097,6 +1129,14 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
|
|||
'max_value': self.cie_max_value,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def _get_plannable(cls, values):
|
||||
Service = Pool().get('lims.service')
|
||||
service_id = values.get('service', None)
|
||||
if not service_id:
|
||||
return False
|
||||
return Service(service_id).fraction.type.plannable
|
||||
|
||||
|
||||
class ForwardAcknowledgmentOfReceipt(Wizard):
|
||||
'Forward Acknowledgment of Samples Receipt'
|
||||
|
|
|
@ -2367,6 +2367,10 @@ msgctxt "field:lims.entry.detail.analysis,party:"
|
|||
msgid "Party"
|
||||
msgstr "Entidad"
|
||||
|
||||
msgctxt "field:lims.entry.detail.analysis,plannable:"
|
||||
msgid "Plannable"
|
||||
msgstr "Planificable"
|
||||
|
||||
msgctxt "field:lims.entry.detail.analysis,rec_name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
|
|
@ -3844,7 +3844,6 @@ class SearchFractions(Wizard):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
Notebook = pool.get('lims.notebook')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
Sample = pool.get('lims.sample')
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
Service = pool.get('lims.service')
|
||||
|
@ -3892,8 +3891,6 @@ class SearchFractions(Wizard):
|
|||
'ON nb.id = nl.notebook '
|
||||
'INNER JOIN "' + Fraction._table + '" frc '
|
||||
'ON frc.id = nb.fraction '
|
||||
'INNER JOIN "' + FractionType._table + '" ft '
|
||||
'ON ft.id = frc.type '
|
||||
'INNER JOIN "' + EntryDetailAnalysis._table + '" ad '
|
||||
'ON ad.id = nl.analysis_detail '
|
||||
'INNER JOIN "' + Service._table + '" srv '
|
||||
|
@ -3901,11 +3898,11 @@ class SearchFractions(Wizard):
|
|||
sample_from)
|
||||
|
||||
sql_where = (
|
||||
'WHERE nl.planification IS NULL '
|
||||
'WHERE ad.plannable = TRUE '
|
||||
'AND nl.start_date IS NULL '
|
||||
'AND nl.annulled = FALSE '
|
||||
'AND ft.plannable = TRUE '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nl.laboratory = %s '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nla.behavior != \'internal_relation\' '
|
||||
'AND ad.confirmation_date::date >= %s::date '
|
||||
'AND ad.confirmation_date::date <= %s::date ' +
|
||||
|
@ -4156,7 +4153,6 @@ class SearchPlannedFractions(Wizard):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
Notebook = pool.get('lims.notebook')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
Sample = pool.get('lims.sample')
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
Service = pool.get('lims.service')
|
||||
|
@ -4202,8 +4198,6 @@ class SearchPlannedFractions(Wizard):
|
|||
'ON nb.id = nl.notebook '
|
||||
'INNER JOIN "' + Fraction._table + '" frc '
|
||||
'ON frc.id = nb.fraction '
|
||||
'INNER JOIN "' + FractionType._table + '" ft '
|
||||
'ON ft.id = frc.type '
|
||||
'INNER JOIN "' + EntryDetailAnalysis._table + '" ad '
|
||||
'ON ad.id = nl.analysis_detail '
|
||||
'INNER JOIN "' + Service._table + '" srv '
|
||||
|
@ -4211,8 +4205,8 @@ class SearchPlannedFractions(Wizard):
|
|||
sample_from)
|
||||
|
||||
sql_where = (
|
||||
'WHERE nl.planification IS NOT NULL '
|
||||
'AND ft.plannable = TRUE '
|
||||
'WHERE ad.plannable = TRUE '
|
||||
'AND nl.start_date IS NOT NULL '
|
||||
'AND nl.end_date IS NULL '
|
||||
'AND nl.laboratory = %s '
|
||||
'AND nla.behavior != \'internal_relation\' '
|
||||
|
@ -4284,12 +4278,11 @@ class SearchPlannedFractions(Wizard):
|
|||
'ON frc.id = nb.fraction '
|
||||
'INNER JOIN "' + EntryDetailAnalysis._table + '" ad '
|
||||
'ON ad.id = nl.analysis_detail '
|
||||
'WHERE nl.planification IS NOT NULL '
|
||||
'WHERE frc.type IN (' + special_types_ids + ') '
|
||||
'AND nl.start_date IS NOT NULL '
|
||||
'AND nl.end_date IS NULL '
|
||||
'AND nl.laboratory = %s '
|
||||
'AND frc.type IN (' + special_types_ids + ') ' +
|
||||
search_clause,
|
||||
(laboratory,))
|
||||
'AND nl.laboratory = %s ' +
|
||||
search_clause, (laboratory,))
|
||||
notebook_lines = cursor.fetchall()
|
||||
if not notebook_lines:
|
||||
return []
|
||||
|
@ -6228,7 +6221,6 @@ class PendingServicesUnplannedReport(Report):
|
|||
if data['party']:
|
||||
clause.append(('party', '=', data['party']))
|
||||
clause.extend([
|
||||
('fraction.type.plannable', '=', True),
|
||||
('fraction.confirmed', '=', True),
|
||||
('analysis.behavior', '!=', 'internal_relation'),
|
||||
])
|
||||
|
@ -6377,7 +6369,8 @@ class PendingServicesUnplannedReport(Report):
|
|||
'FROM "' + EntryDetailAnalysis._table + '" d '
|
||||
'INNER JOIN "' + Analysis._table + '" a '
|
||||
'ON a.id = d.analysis '
|
||||
'WHERE d.state = \'unplanned\' '
|
||||
'WHERE d.plannable = TRUE '
|
||||
'AND d.state = \'unplanned\' '
|
||||
'AND a.behavior != \'internal_relation\'')
|
||||
not_planned_ids = [s[0] for s in cursor.fetchall()]
|
||||
return not_planned_ids
|
||||
|
@ -6473,7 +6466,6 @@ class PendingServicesUnplannedSpreadsheet(Report):
|
|||
if data['party']:
|
||||
clause.append(('party', '=', data['party']))
|
||||
clause.extend([
|
||||
('fraction.type.plannable', '=', True),
|
||||
('fraction.confirmed', '=', True),
|
||||
('analysis.behavior', '!=', 'internal_relation'),
|
||||
])
|
||||
|
@ -6617,7 +6609,8 @@ class PendingServicesUnplannedSpreadsheet(Report):
|
|||
'FROM "' + EntryDetailAnalysis._table + '" d '
|
||||
'INNER JOIN "' + Analysis._table + '" a '
|
||||
'ON a.id = d.analysis '
|
||||
'WHERE d.state = \'unplanned\' '
|
||||
'WHERE d.plannable = TRUE '
|
||||
'AND d.state = \'unplanned\' '
|
||||
'AND a.behavior != \'internal_relation\'')
|
||||
not_planned_ids = [s[0] for s in cursor.fetchall()]
|
||||
return not_planned_ids
|
||||
|
|
|
@ -130,7 +130,6 @@ class SearchAnalysisSheet(Wizard):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
Notebook = pool.get('lims.notebook')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
Analysis = pool.get('lims.analysis')
|
||||
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
|
||||
|
@ -153,17 +152,15 @@ class SearchAnalysisSheet(Wizard):
|
|||
'ON nb.id = nl.notebook '
|
||||
'INNER JOIN "' + Fraction._table + '" frc '
|
||||
'ON frc.id = nb.fraction '
|
||||
'INNER JOIN "' + FractionType._table + '" ft '
|
||||
'ON ft.id = frc.type '
|
||||
'INNER JOIN "' + EntryDetailAnalysis._table + '" ad '
|
||||
'ON ad.id = nl.analysis_detail ')
|
||||
|
||||
sql_where = (
|
||||
'WHERE nl.planification IS NULL '
|
||||
'WHERE ad.plannable = TRUE '
|
||||
'AND nl.start_date IS NULL '
|
||||
'AND nl.annulled = FALSE '
|
||||
'AND ft.plannable = TRUE '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nl.laboratory = %s '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nla.behavior != \'internal_relation\' '
|
||||
'AND ad.confirmation_date::date >= %s::date '
|
||||
'AND ad.confirmation_date::date <= %s::date')
|
||||
|
@ -281,7 +278,6 @@ class SearchAnalysisSheet(Wizard):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
Notebook = pool.get('lims.notebook')
|
||||
Fraction = pool.get('lims.fraction')
|
||||
FractionType = pool.get('lims.fraction.type')
|
||||
Sample = pool.get('lims.sample')
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
Service = pool.get('lims.service')
|
||||
|
@ -335,8 +331,6 @@ class SearchAnalysisSheet(Wizard):
|
|||
'ON nb.id = nl.notebook '
|
||||
'INNER JOIN "' + Fraction._table + '" frc '
|
||||
'ON frc.id = nb.fraction '
|
||||
'INNER JOIN "' + FractionType._table + '" ft '
|
||||
'ON ft.id = frc.type '
|
||||
'INNER JOIN "' + EntryDetailAnalysis._table + '" ad '
|
||||
'ON ad.id = nl.analysis_detail '
|
||||
'INNER JOIN "' + Service._table + '" srv '
|
||||
|
@ -344,11 +338,11 @@ class SearchAnalysisSheet(Wizard):
|
|||
sample_from)
|
||||
|
||||
sql_where = (
|
||||
'WHERE nl.planification IS NULL '
|
||||
'WHERE ad.plannable = TRUE '
|
||||
'AND nl.start_date IS NULL '
|
||||
'AND nl.annulled = FALSE '
|
||||
'AND ft.plannable = TRUE '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nl.laboratory = %s '
|
||||
'AND nl.id NOT IN (' + planned_lines_ids + ') '
|
||||
'AND nla.behavior != \'internal_relation\' '
|
||||
'AND ad.confirmation_date::date >= %s::date '
|
||||
'AND ad.confirmation_date::date <= %s::date ' +
|
||||
|
|
Loading…
Reference in a new issue