Skip to content

Installation Instructions

The installation of Basic Lead consists of:

  • Adding the limepkg as a dependency in your solution
  • Creating one custom limeobject for the Lead limetype to your solution
  • Adding the correct fields and tables through lip and manually
  • Importing the view configuration for the webclient

Follow the instructions below to get started

Warning

Check that the requirements are met.

  1. Add the package to your solution. You can use poetry add limepkg-basic-lead in your terminal.

  2. Create a custom limeobject for lead How to create a Limeobject (Platform documentation).

  3. Import the following to your custom limeobject for lead, or copy the complete custom limeobject down below:

    import limepkg_basic_lead.decorators as lead_decorators
    import limepkg_base_solution_helpers.common as base_common
    
  4. Add lead decorator to your custom limeobject for lead:

    @lead_decorators.lead()
    class Lead(LimeObject):
        """Summarize the function of a Lead object here"""
    
        def before_update(self, uow, **kwargs):
    
  5. Add this code at the end of before_update() in your custom limeobject for lead:

    def before_update(self, uow, **kwargs):
        super().before_update(uow, **kwargs)
    
        ## TODO: Add from here
        base_common.add_history_if_option_change(
            limeobject=self,
            option_prop="leadstatus",
            uow=uow,
        )
    
  6. Install the LIP-Package to get the required structure.

    1. Manual step: Add a option field on Deal called source. Share options between lead.source and deal.source.
    2. Manual step: On History - Add option key autolog to history.type. English Localization: "Automatic note" - add corresponding in your local language. Should be deactivated by default.
  7. Go to Lime Admin and import the file webclient_views.json from the LIP-package to get the required Lead views.

  8. Don't forget to add the Lead on the views for related relations company (tab), person (tab), deal (tab), todo (field), history (field) and document (field).

  9. Go to Configuration to continue your setup.

Info

If you just want activate the default configuration you will need to press Save in Lime Admin->Settings->Basic Lead

Complete custom limeobject Lead

Warning

This is a complete limeobject WITHOUT Automated flow support

import logging

import limepkg_base_solution_helpers.common as base_common
import limepkg_basic_lead.decorators as lead_decorators
from lime_type import LimeObject

logger = logging.getLogger(__name__)


@lead_decorators.lead()
class Lead(LimeObject):
    """Summarize the function of a Lead object here"""

    def before_update(self, uow, **kwargs):
        """
        This is called on all new and updated objects. All changes
        made to the object here will be persisted.
        All other objects that are changed or created here must be
        added to the unit of work.
        """
        super().before_update(uow, **kwargs)

        base_common.add_history_if_option_change(
            limeobject=self,
            option_prop="leadstatus",
            uow=uow,
        )

    def before_delete(self, uow, **kwargs):
        """
        This is called on objects that are about to be deleted,
        before relations are detached. All changes made to
        the object here will be persisted.
        All other objects that are changed or created here must be
        added to the unit of work.

        """
        super().before_delete(uow, **kwargs)

    def after_update(self, unsaved_self, **kwargs):
        """
        This is called after the object has been saved, but before the
        transaction has been committed. IDs on new records will be set,
        and values that has changed are available on the unsaved_self
        object.
        Changes made to the object here will NOT be persisted.
        This is the place to publish custom events.
        """
        super().after_update(unsaved_self, **kwargs)


def register_limeobject_classes(register_class):
    register_class("lead", Lead)

If you'll use automated flow

You need to complement the installation of Basic Lead with:

  • Creating a common.py file in your limeobject_classes folder
  • Update the custom limeobject for the Lead limetype to your solution
  • Creating one custom limeobject for the Deal limetype to your solution
  • Adding the correct fields and tables through lip
  • Importing the view configuration for the webclient

Create file limeobject_classes/common.py

Create a new file in the limeobject_classes folder called common.py contating the following:

import limepkg_base_solution_helpers.common as base_common
from lime_application import LimeApplication
from lime_type import LimeObject
from lime_type.unit_of_work import UnitOfWork

import limepkg_basic_lead.translations as translations


def create_af_participant_history(
    participant: LimeObject,
    parent_object: LimeObject,
    uow: UnitOfWork,
) -> LimeObject:
    app: LimeApplication = participant.application

    automatedflow: LimeObject = participant.properties.automatedflow.fetch()
    person: LimeObject = participant.properties.person.fetch()

    return base_common.add_history_from_object(
        limeobject=parent_object,
        history_type_key="autolog",
        note=translations.get_translation(
            app,
            "automatedflowparticipant.created.history.note",
            flow_name=automatedflow.properties.name.value,
            person_name=person.properties.name.value,
        ),
        uow=uow,
        attach_active_coworker=True,
        auto_relate=False,
    )

Lead Custom limeobject

Warning

Don't forget to go through each TODO and make an action in the code below

  1. Import the following to your custom limeobject for lead:

    from typing import Optional
    
    import addon_lime_automation.sdk.decorators as automation_decorators
    import addon_lime_automation.sdk as automation_sdk
    from lime_type.unit_of_work import UnitOfWork
    
    # TODO: Change to your solution name
    import solution_smh_package.limeobject_classes.common as common
    
  2. Add lead decorator to your custom limeobject for lead:

    ## TODO: Add the row below
    @automation_decorators.automated_flow_decider()
    @lead_decorators.lead()
    class Lead(LimeObject):
        """Summarize the function of a Lead object here"""
    
        def before_update(self, uow, **kwargs):
    
  3. Add this code at the end of before_update() in your custom limeobject for lead:

    def before_update(self, uow, **kwargs):
        super().before_update(uow, **kwargs)
    
        ## TODO: Add from here
        created_participant = _create_af_participant(self, uow)
        if created_participant:
            common.create_af_participant_history(
                created_participant, self, uow
            )
    
  4. Add this code at the bottom of your custom limeobject file for lead:

    def _create_af_participant(
        lead: LimeObject, uow: UnitOfWork
    ) -> Optional[LimeObject]:
        """Create automated flow participant
        if leadstatus have changed to qualify or convert and
        the lead is related to a person and automatedflow
    
        Args:
            lead (LimeObject): Lead object
            uow (UnitOfWork): Unit of work to add objects to
    
        Returns:
            Optional[LimeObject]:
            The potentially created automatedflowparticipant object
        """
        prop_status = lead.properties.leadstatus
        if not prop_status.is_dirty() or prop_status.value.key not in [
            "convert",
            "qualify",
        ]:
            return
        if not lead.get_property("automatedflow"):
            return
    
        factory = automation_sdk.AutomatedFlowParticipantFactory(lead.application)
        flow = lead.properties.automatedflow.fetch()
        person = lead.properties.person.fetch()
        if not flow or not person:
            return
    
        participant, *affected_objects = factory.init_automatedflow_participant(
            automatedflow=flow, related_object=person
        )
        will_be_duplicate = base_common.check_duplicate(
            object_to_create=participant,
            properties_to_check=[
                participant.properties.automatedflow,
                participant.properties.person,
            ],
            static_criterias=[
                {
                    "key": "bw_status",
                    "op": "IN",
                    "exp": ["initialize", "inprogress"],
                }
            ],
        )
        if will_be_duplicate:
            return
    
        participant.properties.lead.attach(lead)
    
        uow.add(participant)
        for affected_object in affected_objects:
            uow.add(affected_object)
    
        return participant
    

Deal Custom Limeobject

  1. Import the following to your custom limeobject for deal:

    from typing import Optional
    
    import limepkg_base_solution_helpers.common as base_common
    from lime_type.unit_of_work import UnitOfWork
    
    # TODO: Change to your solution name
    import solution_smh_package.limeobject_classes.common as common
    
  2. Add this code at the end of before_update() in your custom limeobject for deal:

    def before_update(self, uow, **kwargs):
        super().before_update(uow, **kwargs)
    
        ## TODO: Add from here
        created_from_lead = _get_created_from_lead(self, uow)
        if self.is_new and created_from_lead:
            _create_af_participant_history(self, created_from_lead, uow)
    
  3. Add this code at the bottom of your custom limeobject for deal:

    def _create_af_participant_history(
        deal: LimeObject, lead: LimeObject, uow: UnitOfWork
    ):
        """Fetch all flow participants related to the lead
        and create a history on each dated to the particpant created time
    
        Args:
            deal (LimeObject): Deal to attach history to
            lead (LimeObject): Lead to fetch participants from
            uow (UnitOfWork): Unit of work to add all relations to
        """
        if not lead.get_property("automatedflowparticipant"):
            return
    
        af_participants = lead.properties.automatedflowparticipant.fetch()
    
        for participant in af_participants:
            history = common.create_af_participant_history(participant, deal, uow)
            history.properties.date.value = participant.createdtime
    
    
    def _get_created_from_lead(
        deal: LimeObject, uow: UnitOfWork
    ) -> Optional[LimeObject]:
        """Fetch a lead from the uow that is related to the current deal.
    
        Args:
            deal (LimeObject): Deal object that should be related to the lead
            uow (UnitOfWork): Unit of work to fetch the lead from
    
        Returns:
            Optional[LimeObject]: The lead, if found, else None
        """
    
        def _get_idx(obj: LimeObject):
            if hasattr(obj, "idx"):
                return obj.idx
    
        deal_idx = _get_idx(deal)
    
        if deal_idx is None:
            return
    
        return next(
            (
                ci.unsaved
                for ci in uow.context.get_all()
                if ci.unsaved.limetype.name == "lead"
                and _get_idx(ci.unsaved.properties.deal.fetch()) == deal_idx
            ),
            None,
        )
    

Data structure

Automated flow

On the lead limetype add a single relation to the automatedflow limetype Like so: lead_af_relation

Flow participant

On the automatedflowparticipant limetype add the following single relations:

  • person
  • lead
  • deal

Like so: lead_flowparticipant