Skip to content

Commit

Permalink
company contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pau Soliva committed Jun 28, 2016
1 parent 21732f5 commit bab528e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
40 changes: 34 additions & 6 deletions bika/lims/browser/sample/printform.py
Expand Up @@ -101,6 +101,21 @@ def _rise_error(self):
self.destination_url = self.request.get_header(
"referer", self.context.absolute_url())

def _get_contacts_for_sample(self, sample, contacts_list):
"""
This function returns the contacts defined in each analysis request.
:sample: a sample object
:old_list: A list with the contact names
Returns a sorted list with the complete names.
"""
ars = sample.getAnalysisRequests()
for ar in ars:
contact = ar.getContactTitle()
if contact not in contacts_list:
contacts_list.append(contact)
contacts_list.sort()
return contacts_list

def getSortedFilteredSamples(self):
"""
This function returns all the samples sorted and filtered
Expand Down Expand Up @@ -163,11 +178,20 @@ def getSortedFilteredSamples(self):
# Filling the dictionary
if sampler_uid in result.keys():
client_d = result[sampler_uid].get(client_uid, {})
# Always write the info again.
# Is it faster than doing a check every time?
client_d['info'] = {
'name': sample.getClientTitle(),
'id': sample.getClientReference()}
if not client_d.keys():
client_d['info'] = {
'name': sample.getClientTitle(),
'reference': sample.getClientReference(),
# Contacts contains the client contacts selected in
# each ar to the same client
'contacts':
self._get_contacts_for_sample(sample, [])
}
else:
# Only update the contacts list
contacts = self._get_contacts_for_sample(
sample, client_d['info'].get('contacts', []))
client_d['info']['contacts'] = contacts
if date:
c_l = client_d.get(date, [])
c_l.append(
Expand All @@ -185,7 +209,11 @@ def getSortedFilteredSamples(self):
client_dict = {
'info': {
'name': sample.getClientTitle(),
'id': sample.getClientReference()
'reference': sample.getClientReference(),
# Contacts contains the client contacts selected in
# each ar to the same client
'contacts':
self._get_contacts_for_sample(sample, [])
},
}
# If the sample has a sampling date, build the dictionary
Expand Down
11 changes: 7 additions & 4 deletions bika/lims/browser/sample/templates/print/default_form.pt
Expand Up @@ -43,10 +43,10 @@
</th>
<th>
<table>
<td class="table-cell" tal:content="python:dictionaries[sampler_uid][client_uid]['info']['name']">Client</td>
<td tal:content="python:dictionaries[sampler_uid][client_uid]['info']['name']">Client</td>
<td
tal:condition="python:dictionaries[sampler_uid][client_uid]['info']['id']">-</td>
<td class="table-cell" tal:content="python:dictionaries[sampler_uid][client_uid]['info']['id']">Client</td>
tal:condition="python:dictionaries[sampler_uid][client_uid]['info']['reference']"> - </td>
<td tal:content="python:dictionaries[sampler_uid][client_uid]['info']['reference']">Client</td>
</table>
</th>
<th rowspan="2">
Expand All @@ -58,8 +58,11 @@
<label i18n:translate="">Signature</label>
<div class="data-input"></div>
</th>
<th>
<th tal:define="
contacts_list python:dictionaries[sampler_uid][client_uid]['info']['contacts'];
contacts python:', '.join(contacts_list)">
<label i18n:translate="">Company contact</label>
<div tal:content="contacts">Contacts</div>
<div class="data-input"></div>
</th>
</tr>
Expand Down

0 comments on commit bab528e

Please sign in to comment.