Announcement

Collapse
No announcement yet.

Sales Pack- How to automatic filter products with Account and the Sales Order related

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sales Pack- How to automatic filter products with Account and the Sales Order related

    I have the following problem:

    I want to pre-filter my list of products based on a Account selected on my Sales Order; I know I can do this manually once I click the add item "plus" icon and choose the Account field created; but I want to do this automatically; i also have the Advanced Pack, but I haven't found how to solve this.

    I want to know if this is possible since I know that when I click the Add Item button, there is no item created, and I don't know if there is a way to send this variable as a filter.

    I add a manual example of this. (Cliente = Account; I speak spanish.)


  • #2
    Yes, you just need to a custom account field view where you apply getSelectFilters to return the cliente field from current sales order.

    Create this file account.js under client\custom\src\views\sales-order\fields

    PHP Code:
    define('custom:views/sales-order/fields/account', ['views/fields/link'], function (Dep) {

        return 
    Dep.extend({

            
    getSelectFilters: function () {
                if (
    this.model.get('accountId')) {
                    return {
                        
    'account': {
                            
    type'equals',
                            
    attribute'accountId'// change this to the name of the account on product (cliente??)
                            
    valuethis.model.get('accountId'),
                            
    data: {
                                
    type'is',
                                
    nameValuethis.model.get('accountName'),
                            },
                        }
                    };
                }
            },
        });
    });
    ​ 

    Now once this is done, you just need to create a custom SalesOrder.json file under custom\Espo\Custom\Resources\metadata\entityDefs and assign the custom field view to the account field as below

    PHP Code:
    {
        
    "fields": {
            
    "account": {
                
    "view""custom:views/sales-order/fields/account"
            
    }
        }
    }
    ​ 

    Now save those files and clear cache and rebuild the crm and the filter will always applied when an account is selected on the sales order

    Comment

    Working...
    X