Opportunity sales status value not changing correctly

Hello.

I'm using SugarCRM Enterprise 7.5.2.4.

I have a RevenueLineItems module, that is related to the Opportunities modules.

What I need is when changing the RevenueLineItem 'sales_stage' field value, the related Opportunity 'sales_status' field value changes to the same value as the 'sales_stage' field.

I already done a logic hook to do this, but when in the RevenueLineItem I select the value 'Closed Cancel', the Opportunity sales_status changes to 'Prospecting'.

I already added a 'Closed Cancel' field/value to the Opportunity sales_stage dropdown.

Why this is happening? All the other RevenueLineItens values change the Opportunity value correctly.

Does the Opportunity 'sales_status' field have some sort of calculated field value that changes the field value automatically?

Thanks.

  • Hi Ramon,

    My guess is dropdown keys and values are not matching.

    I would double check after logic hook runs, i would go to DB and check the sales_stage for that record.

    This should help you to identify, what is being pass and written to DB.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik.

    I created a label with key 'Fechado Cancelado', and value 'Closed Cancel' for both 'sales_status' and 'sales_stages' dropdowns, as I indicate on this picture:

    sales_status-stage_dom.png

    When saving the RevenueLineItem, the log I put in the logic hook shows in the system the changed value. It's calling the save() function for both beans:

    $bean->name = $parentbean->name;
    $parentbean->sales_status = $bean->sales_stage;
    if ($bean->save()) {
        $GLOBALS['log']->fatal("Nome receita ".$bean->id." atualizado: ".$bean->name);
        if ($parentbean->save()) {
            $GLOBALS['log']->fatal("Status oportunidade ".$parentbean->id." atualizado: ".$parentbean->sales_status);
        } else {
            $GLOBALS['log']->fatal("Nao foi possivel editar status de oportunidade");
        }
    } else {
        $GLOBALS['log']->fatal("Nao foi possivel editar receita");
    }
    

    But when checking the Opportunity sales status value, it's still with 'Prospecting' value.

    Does this condition only applies to 'Prospecting', 'Closed Won', and 'Closed Lost'?
    That's because they are already default values in these dropdowns?

    Seeing by the response on a  similar case I opened with another account in the Sugar Enterprise Support, the logic only applies to the default values?

    https://web.sugarcrm.com/support/cases/5279bb73-ae00-6310-fe7e-573dbeb5ca91 

    Best Regards,

    Ramon

  • Hi Ramon,

    I miss the part that you are working with Enterprise.

    In enterprise we have a stock logic hook that changes sales status of the opportunities. Please have a look at `modules/Opportunities/OpportunityHooks.php` file `setSalesStatus` method.

    Hope this helps you.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik.

    I have a old backup that contains this file (OpportunityHooks.php).

    Should I override or extend this logic hook? How?

    Regards,

    Ramon

  • Hi Ramon,

    This is so depend on what you are trying to do. If you wanna reflect directly RLI Status to Opportunities Status, for sure you can do it by overriding.

    I was wondering, if there is a RLI closed before and later on there is an another RLI added  to same opportunities. That opportunity will be automatically new RLI status.

    So, Opportunities status wouldn't be redundant but I don't know what is your approach. Just for you to know

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik.

    Sorry for the delay on replying.

    I just need to update Opportunity sales stage status from the related RLI status, regardless of situation (any new status I place on RLI will be added to the Opportunity too). The status will always be updated from the Revenue Line Item sooner or later, as long the Opportunity has an RLI.

    It may sound strange, but that is what my client needs.

    There is a way to call a custom a logic hook with order after the opportunity stock hook?

    I need some way to do this, that is possible?

    If it is, how can I do it? If not, what I could do?

    You tell to override, but how the override is done? I haven't found nothing explaining how to do it in any documentation.

    Thanks for the patience.

    Best Regards,

    Ramon

  • Hi Ramon,

    In Sugar Enterprise, you can find a logic hook pre-defined like;

    /**
     * Define the before_save hook that will set the Opportunity Sales Status in Ent Only
     */
    $hook_array['before_save'][] = array(
        1,
        'setSalesStatus',
        'modules/Opportunities/OpportunityHooks.php',
        'OpportunityHooks',
        'setSalesStatus',
    );
    

    The number 1 is sequence number of before_save logic hooks for Opportunities. What that means, Sugar will look at these numbers. Before running the logic hooks first it will order them then run all the logic hooks by the sequence numbers ascending.

    If you wanna modify sales status behaviour, you can create an another logic hook with higher sequence number. (Such as 99 -considering you have less then 100 logic hook in your definitions-) Then after all before_save logic hooks run, yours will come after them and make the final change.

    Please have a look at this documentation for more informations: before_save - Developer Guide.

    Feel free to ask, if you have a questions/concerns.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik.

    But the logic hook I'm applying to change the field value is of "after_save" type, with order 99, so, why the pre-defined hook is always overriding the final value?

    My hook is set with the following values on manifest.php:

                array(
                    'module' => 'RevenueLineItems',
                    'hook' => 'after_save',
                    'order' => 99,
                    'description' => 'test',
                    'file' => 'custom/modules/RevenueLineItems/receita_code_hook.php',
                    'class' => 'receita_code',
                    'function' => 'receita_code_after_save',
                ),
    

    Best Regards,

    Ramon