rattail.clientele
¶
Clientele Handler
- class rattail.clientele.ClienteleHandler(*args, **kwargs)[source]¶
Base class and default implementation for clientele handlers.
- choice_uses_dropdown()[source]¶
Returns boolean indicating whether a customer choice should be presented to the user via a dropdown (select) element, vs. an autocomplete field. The latter is the default because potentially the customer list can be quite large, so we avoid loading them all in the dropdown unless so configured.
- Returns:
Boolean; if true then a dropdown should be used; otherwise (false) autocomplete is used.
- deactivate_shopper(shopper, **kwargs)[source]¶
Deactivate the given shopper, i.e. make it no longer active for the customer account to which it belongs.
- ensure_customer(person)[source]¶
Returns the customer record associated with the given person, creating it first if necessary.
- get_active_shopper(customer, **kwargs)[source]¶
Return the “active” shopper record for the given customer.
This should never return multiple shoppers, either one or none.
- get_all_customers(session, include_inactive=False, **kwargs)[source]¶
Get the full list of customers, e.g. for dropdown choice.
- get_customer_info_markdown(customer, **kwargs)[source]¶
Returns a Markdown string containing pertinent info about a given customer account.
- get_customers_for_account_holder(person, **kwargs)[source]¶
Return all Customer records for which the given Person is the account holder.
- get_email_address(customer, **kwargs)[source]¶
Return the first email address found for the given customer.
- Returns:
The email address as string, or
None
.
- get_first_email(customer, invalid=False, **kwargs)[source]¶
Return the first available email record found, either for the customer, or its first person.
- get_first_email_address(customer, invalid=False, **kwargs)[source]¶
Return the first available email address found, either for the customer, or its first person.
- get_first_phone(customer, **kwargs)[source]¶
Return the first available phone record found, either for the customer, or its first person.
- get_first_phone_number(customer, **kwargs)[source]¶
Return the first available phone number found, either for the customer, or its first person.
- get_person(customer)[source]¶
Returns the person associated with the given customer, if there is one.
- locate_customer_for_entry(session, entry, **kwargs)[source]¶
This method aims to provide sane default logic for locating a
Customer
record for the given “entry” value.The default logic here will try to honor the “configured” customer field, and prefer that when attempting the lookup.
- Parameters:
session¶ – Reference to current DB session.
entry¶ – Value to use for lookup. This is most often a simple string, but the method can handle a few others. For instance it is common to read values from a spreadsheet, and sometimes those come through as integers etc.
lookup_fields¶ –
Optional list of fields to use for lookup. The default value is
['uuid', '_customer_key_']
which means to lookup by UUID as well as “customer key” field, which is configurable. You can include any of the following inlookup_fields
:uuid
_customer_key_
-locate_customer_for_key()
- Returns:
First
Customer
instance found if there was a match; otherwiseNone
.
- locate_customer_for_id(session, entry, **kwargs)[source]¶
Locate the customer which matches the given ID.
This will do a lookup on the
rattail.db.model.customers.Customer.id
field only.Note that instead of calling this method directly, you might consider calling
locate_customer_for_key()
instead.
- locate_customer_for_key(session, entry, customer_key=None, **kwargs)[source]¶
Locate the customer which matches the given key value.
This is an abstraction layer so calling logic need not care which customer key field is configured. Under the hood this will invoke one of:
This will do a lookup on the customer key field only. It normally checks config to determine which field to use for customer key (via
get_customer_key_field()
), but you can override by specifying, e.g.customer_key='number'
.
- locate_customer_for_number(session, entry, **kwargs)[source]¶
Locate the customer which matches the given number.
This will do a lookup on the
rattail.db.model.customers.Customer.number
field only.Note that instead of calling this method directly, you might consider calling
locate_customer_for_key()
instead.
- normalize_customer(customer, fields=None, **kwargs)[source]¶
Normalize the given customer to a JSON-serializable dict.
- search_customers(session, entry, **kwargs)[source]¶
Perform a customer search across multiple fields, and return results as JSON data rows.
- rattail.clientele.get_clientele_handler(config, **kwargs)[source]¶
Create and return the configured
ClienteleHandler
instance.