Lock down all the fields in Quote line time conditionally

Hi,

I am trying to make all the fields in Quote Line Item read only when the Quote stage is "Invoiced/Credited"

Quote Line Item is nothing but a Product, so I  have created a file src/custom/modules/Products/metadata/dependencydefs.php

Here my code

<?php

$dependencies['Products']['read_only_fields'] = array();
 $fields = array(
       'product_template_name',
       'show_description',
       'display_line_item',
       'discount_price',
       'discount_per_unit_c',
       'quantity',
);

$dependencies['Products']['read_only_fields'] = array(
         'hooks' => array("all"),
         'trigger' => 'or(equal(related($quotes,"quote_stage"),"Invoiced"),                                  equal(related($quotes,"quote_stage"),"Credited")

                                )',
         'onload' => true,
         'actions' => array(),

);

foreach ($fields as $field) {
         $dependencies['Products']['read_only_fields']['actions'][] = array(
                  'name' => 'ReadOnly', 
                  'params' => array(
                        'target' => $field,
                         'value' => 'or(equal(related($quotes,"quote_stage"),"Invoiced"),                                                                                                       equal(related($quotes,"quote_stage"),"Credited")

                                               )', 
                  ),
         );
}

While edit the Quote Line Item it will make all the fields as read only except the "quantity" field

See the above image. while edit the QLI I am unable to make the "quantity" field as read only

Thanks

  • You need to copy the field "quote_stage" to QLI and update the dependency accordingly.

    This can be done by extending 2 js controllers of ProductBundles:

    • modules/ProductBundles/clients/base/views/quote-data-group-list/quote-data-group-list.js, method onAddNewItemToGroup. This will inject Quote's fields into QLI on adding a record.
    • modules/ProductBundles/clients/base/layouts/quote-data-group/quote-data-group.js, method bindDataChange. This will refresh QLI fields on updating respective fields in the Quote.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada