lims_sale, lims_sale_industry: create samples wizard: automatically load quoted services
This commit is contained in:
parent
8d428780f5
commit
72e854464c
|
@ -81,6 +81,47 @@ class CreateSampleStart(metaclass=PoolMeta):
|
|||
|
||||
return [a for a in analysis_domain if a in quoted_analysis]
|
||||
|
||||
@fields.depends('sale_lines', 'product_type', 'matrix', 'services')
|
||||
def on_change_sale_lines(self, name=None):
|
||||
if not self.sale_lines:
|
||||
return
|
||||
self.load_sale_lines_analyzes()
|
||||
|
||||
def load_sale_lines_analyzes(self):
|
||||
pool = Pool()
|
||||
CreateSampleService = pool.get('lims.create_sample.service')
|
||||
|
||||
analysis_domain = super().on_change_with_analysis_domain()
|
||||
if not analysis_domain:
|
||||
return
|
||||
|
||||
quoted_analysis = []
|
||||
for sale_line in self.sale_lines:
|
||||
if sale_line.analysis:
|
||||
quoted_analysis.append(sale_line.analysis)
|
||||
quoted_analysis = [a for a in quoted_analysis
|
||||
if a.id in analysis_domain]
|
||||
if not quoted_analysis:
|
||||
return
|
||||
|
||||
quoted_services = []
|
||||
for a in quoted_analysis:
|
||||
with Transaction().set_context(
|
||||
product_type=self.product_type.id,
|
||||
matrix=self.matrix.id):
|
||||
s = CreateSampleService()
|
||||
s.analysis_locked = False
|
||||
s.urgent = s.default_urgent()
|
||||
s.priority = s.default_priority()
|
||||
s.analysis = a
|
||||
s.on_change_analysis()
|
||||
s.laboratory_date = s.on_change_with_laboratory_date()
|
||||
s.report_date = s.on_change_with_report_date()
|
||||
|
||||
quoted_services.append(s)
|
||||
|
||||
self.services = quoted_services
|
||||
|
||||
|
||||
class CreateSample(metaclass=PoolMeta):
|
||||
__name__ = 'lims.create_sample'
|
||||
|
|
|
@ -4,21 +4,38 @@
|
|||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class CreateSampleStart(metaclass=PoolMeta):
|
||||
__name__ = 'lims.create_sample.start'
|
||||
|
||||
@fields.depends('party', 'label', 'component', 'equipment',
|
||||
'product_type', 'matrix')
|
||||
@fields.depends('party', 'product_type', 'matrix',
|
||||
'sale_lines_filter_product_type_matrix',
|
||||
'label', 'component', 'equipment')
|
||||
def on_change_with_sale_lines_domain(self, name=None):
|
||||
cursor = Transaction().connection.cursor()
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
SaleLine = pool.get('sale.line')
|
||||
Analysis = pool.get('lims.analysis')
|
||||
|
||||
if not self.party:
|
||||
if not self.party or not self.product_type or not self.matrix:
|
||||
return []
|
||||
|
||||
analysis_domain = super().on_change_with_analysis_domain()
|
||||
if not analysis_domain:
|
||||
return []
|
||||
analysis_ids = ', '.join(str(a) for a in analysis_domain)
|
||||
|
||||
cursor.execute('SELECT DISTINCT(product) '
|
||||
'FROM "' + Analysis._table + '" '
|
||||
'WHERE id IN (' + analysis_ids + ')')
|
||||
res = cursor.fetchall()
|
||||
if not res:
|
||||
return []
|
||||
product_ids = [x[0] for x in res]
|
||||
|
||||
today = Date.today()
|
||||
clause = [
|
||||
('sale.party', '=', self.party.id),
|
||||
|
@ -26,6 +43,7 @@ class CreateSampleStart(metaclass=PoolMeta):
|
|||
('sale.state', 'in', [
|
||||
'quotation', 'confirmed', 'processing', 'done',
|
||||
]),
|
||||
('product.id', 'in', product_ids),
|
||||
]
|
||||
|
||||
if self.label:
|
||||
|
@ -35,8 +53,9 @@ class CreateSampleStart(metaclass=PoolMeta):
|
|||
('sale.label_from', '<=', label),
|
||||
('sale.label_to', '>=', label),
|
||||
])
|
||||
res = SaleLine.search(clause)
|
||||
return [x.id for x in res]
|
||||
sale_lines = SaleLine.search(clause)
|
||||
res = [sl.id for sl in sale_lines if not sl.services_completed]
|
||||
return res
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
@ -45,22 +64,25 @@ class CreateSampleStart(metaclass=PoolMeta):
|
|||
('components', '=', self.component.id),
|
||||
('sale.components', '=', self.component.id),
|
||||
])
|
||||
res = SaleLine.search(clause)
|
||||
if res:
|
||||
return [x.id for x in res]
|
||||
sale_lines = SaleLine.search(clause)
|
||||
if sale_lines:
|
||||
res = [sl.id for sl in sale_lines if not sl.services_completed]
|
||||
return res
|
||||
|
||||
if self.equipment:
|
||||
clause.append(['OR',
|
||||
('equipments', '=', self.equipment.id),
|
||||
('sale.equipments', '=', self.equipment.id),
|
||||
])
|
||||
res = SaleLine.search(clause)
|
||||
if res:
|
||||
return [x.id for x in res]
|
||||
sale_lines = SaleLine.search(clause)
|
||||
if sale_lines:
|
||||
res = [sl.id for sl in sale_lines if not sl.services_completed]
|
||||
return res
|
||||
|
||||
if self.product_type:
|
||||
if self.sale_lines_filter_product_type_matrix:
|
||||
clause.append(('product_type', '=', self.product_type.id))
|
||||
if self.matrix:
|
||||
clause.append(('matrix', '=', self.matrix.id))
|
||||
res = SaleLine.search(clause)
|
||||
return [x.id for x in res]
|
||||
|
||||
sale_lines = SaleLine.search(clause)
|
||||
res = [sl.id for sl in sale_lines if not sl.services_completed]
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue