
    mRi`                     H    d dl mZmZmZmZ d dlmZ d dlmZ  G d d      Z	y)    )OuterRefFValueFunc)Coalesce)Customerc                       e Zd Zed        Zy)CustomerRepositoryc            	          t         j                  j                  t        d      t        d            j	                  t        t        t        d      dd      t        d            	      j                  d
      dd } | S )z
        Returns a Subquery that fetches the customer's name by phone and company,
        falling back to 'Unknown' if name is empty or null.
        
company_idfrom_number)r   phonenameNULLIFz!%(function)s(%(expressions)s, ''))functiontemplateUnknown)name_or_unknownr   N   )
r   objectsfilterr   annotater   r   r   r   values)subquerys    B/var/www/html/dp2/backend_v2.1/server/apps/customers/repository.pyget_name_subqueryz$CustomerRepository.get_name_subquery   s     ##**-=) + 
 ($fI%@
 i   	
 &"
#BQ(     N)__name__
__module____qualname__staticmethodr    r   r   r
   r
      s     r   r
   N)
django.db.modelsr   r   r   r   django.db.models.functionsr   apps.customers.modelsr   r
   r"   r   r   <module>r&      s    5 5 / * r   