How to define an initial filter lookup searches with a conditionnal logic ?

Hello,

I am looking about your help about a way to define an initial lookup search filter BUT with a bit of conditionnal logic.

Here is my scenario :

  • It's a B2B/C business so we need to support Account or Contact
  • I have a CASE record with 2 relationship
    • ACCOUNT
    • CONTACT
  • one is mandatory BUT both can be entered 
  • I have another relationship to select an invoice to complete my case; an invoice is linked to either an account OR a contact (but NOT both)
  • I would like to prefilter the invoice list to filter only the relevant invoices, ie 
    • if a contact is defined at the case level but no account, all the invoices linked to a contact = case contact
    • if an account is defined at the case level (whether a contact is linked to the case OR not), all the invoices linked to an account = case account
  • when using https://support.sugarcrm.com/documentation/sugar_developer/sugar_developer_guide_25.1/architecture/filters/#Adding_Initial_Filters_to_Lookup_Searches it works from the full list selection BUT not from the basic search selector
    • furthermore, we can define a condition about weither or not the account is filled etc.

So I was wondering if one of you already face a similar advanced initial filter definition and how you managed it ? 

Thanks for your help