How to reference the Discount field when creating a BPM?

Hi!

The discount field seems not to carry over to a renewable RLI/Opportunity. I tried to create a BPM but I cant reference the Discount field. is there a way that we can carry over the values in the original RLI to the renewables for the discount field?

Parents
  • Hello  , 

    Thanks for this question. 

    I looked into the code, and it turns out that discount_amount is not included when Sugar automatically creates the new renewal Revenue Line Item (RLI) after the existing one is moved to Closed Won.

    Here’s the full list of fields that Sugar copies to the new RLI when the Original renewable RLI is closed-won:

    $copyRliFields = [
    'name',
    'account_id',
    'product_template_id',
    'category_id',
    'tax_class',
    'likely_case',
    'currency_id',
    'base_rate',
    'quantity',
    'list_price',
    'cost_price',
    'discount_price',
    'renewable',
    'service',
    'service_duration_value',
    'service_duration_unit',
    'catalog_service_duration_value',
    'catalog_service_duration_unit',
    'assigned_user_id',
    'team_id',
    'team_set_id',
    'acl_team_set_id',
    ];



    Unfortunately, from what I can see there isn’t a way to include discount_amount using BPM alone on the new RLI generation process.

    Based on my review, the only way to achieve this is through a customization: extending the Opportunities SugarBean and creating your own version of the createNewRenewalRLI() function that replicates the original function and includes the additional field.

    It’s a fairly straightforward customization, but of course, it does require development resources, and I understand that may not always be available.

    Still, I wanted to share the approach for reference in case it’s helpful.

    If you do go down the customization route, you would need to create two files:

    1. custom/modules/Opportunities/Opportunity.php

    <?php
    
    require_once 'modules/Opportunities/Opportunity.php';
    
    class CustomOpportunity extends Opportunity
    {
    
        //this is acopy of the original createNewRenewalRLI() adding the field discount_amount to  $copyRliFields
    
        public function createNewRenewalRLI(RevenueLineItem $rli): RevenueLineItem
        {
            $copyRliFields = [
                'name',
                'account_id',
                'product_template_id',
                'category_id',
                'tax_class',
                'likely_case',
                'currency_id',
                'base_rate',
                'quantity',
                'list_price',
                'cost_price',
                'discount_price',
                'discount_amount',
                'renewable',
                'service',
                'service_duration_value',
                'service_duration_unit',
                'catalog_service_duration_value',
                'catalog_service_duration_unit',
                'assigned_user_id',
                'team_id',
                'team_set_id',
                'acl_team_set_id',
            ];
    
            $newRliBean = BeanFactory::newBean($rli->getModuleName());
            $timeDate = TimeDate::getInstance();
            $newStartDate = $timeDate->fromDbDate($rli->service_end_date)->modify('+1 day')->asDbDate();
            $newRliBean->service_start_date = $newStartDate;
            $newRliBean->date_closed = $newStartDate;
            $newRliBean->product_type = 'Existing Business';
            $newRliBean->opportunity_id = $this->id;
            $newRliBean->renewal = true;
    
            foreach ($copyRliFields as $field) {
                if (isset($rli->$field)) {
                    $newRliBean->$field = $rli->$field;
                }
            }
    
            $newRliBean->save();
    
            if ($this->load_relationship('revenuelineitems')) {
                $this->revenuelineitems->add($newRliBean);
            }
    
            return $newRliBean;
        }
    }

    2. custom/Extension/application/Ext/Include/customOpportunity.php

    <?php
    /**
     * Map Opportunities to use the CustomOpportunity class
     */
    
    // Only needed if not already defined, but safe to include:
    $objectList['Opportunities'] = 'Opportunity';
    
    // Tell Sugar to use CustomOpportunity as the bean class
    $beanList['Opportunities'] = 'CustomOpportunity';
    
    // Point to the file you just created
    $beanFiles['CustomOpportunity'] = 'custom/modules/Opportunities/CustomOpportunity.php';

    Let us know if this helps.

    Cheers, 

    André 



Reply
  • Hello  , 

    Thanks for this question. 

    I looked into the code, and it turns out that discount_amount is not included when Sugar automatically creates the new renewal Revenue Line Item (RLI) after the existing one is moved to Closed Won.

    Here’s the full list of fields that Sugar copies to the new RLI when the Original renewable RLI is closed-won:

    $copyRliFields = [
    'name',
    'account_id',
    'product_template_id',
    'category_id',
    'tax_class',
    'likely_case',
    'currency_id',
    'base_rate',
    'quantity',
    'list_price',
    'cost_price',
    'discount_price',
    'renewable',
    'service',
    'service_duration_value',
    'service_duration_unit',
    'catalog_service_duration_value',
    'catalog_service_duration_unit',
    'assigned_user_id',
    'team_id',
    'team_set_id',
    'acl_team_set_id',
    ];



    Unfortunately, from what I can see there isn’t a way to include discount_amount using BPM alone on the new RLI generation process.

    Based on my review, the only way to achieve this is through a customization: extending the Opportunities SugarBean and creating your own version of the createNewRenewalRLI() function that replicates the original function and includes the additional field.

    It’s a fairly straightforward customization, but of course, it does require development resources, and I understand that may not always be available.

    Still, I wanted to share the approach for reference in case it’s helpful.

    If you do go down the customization route, you would need to create two files:

    1. custom/modules/Opportunities/Opportunity.php

    <?php
    
    require_once 'modules/Opportunities/Opportunity.php';
    
    class CustomOpportunity extends Opportunity
    {
    
        //this is acopy of the original createNewRenewalRLI() adding the field discount_amount to  $copyRliFields
    
        public function createNewRenewalRLI(RevenueLineItem $rli): RevenueLineItem
        {
            $copyRliFields = [
                'name',
                'account_id',
                'product_template_id',
                'category_id',
                'tax_class',
                'likely_case',
                'currency_id',
                'base_rate',
                'quantity',
                'list_price',
                'cost_price',
                'discount_price',
                'discount_amount',
                'renewable',
                'service',
                'service_duration_value',
                'service_duration_unit',
                'catalog_service_duration_value',
                'catalog_service_duration_unit',
                'assigned_user_id',
                'team_id',
                'team_set_id',
                'acl_team_set_id',
            ];
    
            $newRliBean = BeanFactory::newBean($rli->getModuleName());
            $timeDate = TimeDate::getInstance();
            $newStartDate = $timeDate->fromDbDate($rli->service_end_date)->modify('+1 day')->asDbDate();
            $newRliBean->service_start_date = $newStartDate;
            $newRliBean->date_closed = $newStartDate;
            $newRliBean->product_type = 'Existing Business';
            $newRliBean->opportunity_id = $this->id;
            $newRliBean->renewal = true;
    
            foreach ($copyRliFields as $field) {
                if (isset($rli->$field)) {
                    $newRliBean->$field = $rli->$field;
                }
            }
    
            $newRliBean->save();
    
            if ($this->load_relationship('revenuelineitems')) {
                $this->revenuelineitems->add($newRliBean);
            }
    
            return $newRliBean;
        }
    }

    2. custom/Extension/application/Ext/Include/customOpportunity.php

    <?php
    /**
     * Map Opportunities to use the CustomOpportunity class
     */
    
    // Only needed if not already defined, but safe to include:
    $objectList['Opportunities'] = 'Opportunity';
    
    // Tell Sugar to use CustomOpportunity as the bean class
    $beanList['Opportunities'] = 'CustomOpportunity';
    
    // Point to the file you just created
    $beanFiles['CustomOpportunity'] = 'custom/modules/Opportunities/CustomOpportunity.php';

    Let us know if this helps.

    Cheers, 

    André 



Children
No Data