Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AR Add: Set default contact on client change #707

Merged
merged 6 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog

**Fixed**

- #707 AR Add: Set default contact on client change
- #698 Fix Publish Actions for Batches
- #696 Filter worksheets by department. The worksheet count in the dashboard is now properly updated accordingly to the selected departments

Expand Down
25 changes: 17 additions & 8 deletions bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def get_copy_from(self):
logger.info("get_copy_from: uids={}".format(copy_from_uids))
return out

def get_default_value(self, field, context):
def get_default_value(self, field, context, arnum):
"""Get the default value of the field
"""
name = field.getName()
Expand All @@ -286,7 +286,8 @@ def get_default_value(self, field, context):
client = self.get_client()
if client is not None:
default = client
if name == "Contact":
# only set default contact for first column
if name == "Contact" and arnum == 0:
contact = self.get_default_contact()
if contact is not None:
default = contact
Expand All @@ -312,8 +313,8 @@ def get_default_value(self, field, context):
interface=IGetDefaultFieldValueARAddHook)
if adapter is not None:
default = adapter(self.context)
logger.info("get_default_value: context={} field={} value={}".format(
context, name, default))
logger.info("get_default_value: context={} field={} value={} arnum={}"
.format(context, name, default, arnum))
return default

def get_field_value(self, field, context):
Expand Down Expand Up @@ -406,14 +407,14 @@ def generate_fieldvalues(self, count=1):
value = self.get_field_value(field, context)
else:
# get the default value of this field
value = self.get_default_value(field, ar_context)
value = self.get_default_value(field, ar_context, arnum=arnum)
# store the value on the new fieldname
new_fieldname = self.get_fieldname(field, arnum)
out[new_fieldname] = value

return out

def get_default_contact(self):
def get_default_contact(self, client=None):
"""Logic refactored from JavaScript:

* If client only has one contact, and the analysis request comes from
Expand All @@ -425,7 +426,7 @@ def get_default_contact(self):
:rtype: Client object or None
"""
catalog = api.get_tool("portal_catalog")
client = self.get_client()
client = client or self.get_client()
path = api.get_path(self.context)
if client:
path = api.get_path(client)
Expand Down Expand Up @@ -937,7 +938,15 @@ def get_client_info(self, obj):
"""Returns the client info of an object
"""
info = self.get_base_info(obj)
info.update({})

default_contact_info = {}
default_contact = self.get_default_contact(client=obj)
if default_contact:
default_contact_info = self.get_contact_info(default_contact)

info.update({
"default_contact": default_contact_info
})

# UID of the client
uid = api.get_uid(obj)
Expand Down
Loading