Example #1
0
    def get_namespace(self, resource, context):
        proxy = super(CRM_SearchContacts, self)
        namespace = proxy.get_namespace(resource, context)
        # Add infos about assured and probable amount
        # TODO Filter by year or semester
        total = self.assured + self.probable

        namespace['assured'] = format_amount(self.assured, context)
        namespace['probable'] = format_amount(self.probable, context)
        namespace['total'] = format_amount(total, context)
        namespace['crm-infos'] = True

        return namespace
Example #2
0
 def get_item_value(self, resource, context, item, column, cache={}):
     item_brain, item_resource = item
     if column == 'title':
         value = get_name(item_brain)
         href = '%s/' % context.get_link(item_resource)
         return value, href
     elif column == 'company':
         p_company = item_brain.crm_p_company
         if not p_company:
             return u''
         crm = get_crm(resource)
         company = crm.get_resource('companies/' + p_company)
         href = context.get_link(company)
         title = company.get_title()
         return title, href
     elif column == 'email':
         value = item_brain.crm_p_email
         href = 'mailto:%s' % value
         return value, href
     elif column == 'phones':
         return Phones(item_brain, 'crm_p_phone', 'crm_p_mobile')
     elif column == 'crm_p_assured':
         value = item_brain.crm_p_assured
         return format_amount(value, context)
     elif column == 'crm_p_probable':
         value = item_brain.crm_p_probable
         return format_amount(value, context)
     elif column.startswith('crm_m_'):
         # CSV export
         contact_name = item_brain.name
         mission_brain = cache.get(contact_name)
         if mission_brain is None:
             crm = get_crm(resource)
             query = AndQuery(
                     get_crm_path_query(crm),
                     PhraseQuery('format', 'mission'),
                     PhraseQuery('crm_m_contact', item_brain.name))
             results = context.root.search(query)
             last_missions = results.get_documents(sort_by='mtime',
                     reverse=True, size=1)
             if not last_missions:
                 return None
             mission_brain = cache[contact_name] = last_missions[0]
         if column == 'crm_m_title':
             column = 'title'
         return getattr(mission_brain, column)
     proxy = super(CRM_SearchContacts, self)
     return proxy.get_item_value(resource, context, item, column,
             cache=cache)