|
1 | 1 | import logging |
2 | 2 |
|
3 | 3 | from django.apps import AppConfig |
| 4 | +from core.utils import ConfigUtilMixin |
4 | 5 |
|
5 | 6 | MODULE_NAME = 'invoice' |
6 | 7 |
|
|
10 | 11 | "gql_invoice_create_perms": ["155102"], |
11 | 12 | "gql_invoice_update_perms": ["155103"], |
12 | 13 | "gql_invoice_delete_perms": ["155104"], |
13 | | - "gql_invoice_amend_perms": ["155109"], |
| 14 | + "gql_invoice_amend_perms": ["155109"], |
14 | 15 |
|
15 | 16 | "gql_invoice_payment_search_perms": ["155201"], |
16 | 17 | "gql_invoice_payment_create_perms": ["155202"], |
17 | 18 | "gql_invoice_payment_update_perms": ["155203"], |
18 | 19 | "gql_invoice_payment_delete_perms": ["155204"], |
19 | 20 | "gql_invoice_payment_refund_perms": ["155206"], |
20 | 21 |
|
21 | | - "gql_invoice_event_search_perms": ["155301"], |
22 | | - "gql_invoice_event_create_perms": ["155302"], |
23 | | - "gql_invoice_event_update_perms": ["155303"], |
24 | | - "gql_invoice_event_delete_perms": ["155304"], |
25 | | - "gql_invoice_event_create_message_perms": ["155306"], |
26 | | - "gql_invoice_event_delete_my_message_perms": ["155307"], |
| 22 | + "gql_invoice_event_search_perms": ["155301"], |
| 23 | + "gql_invoice_event_create_perms": ["155302"], |
| 24 | + "gql_invoice_event_update_perms": ["155303"], |
| 25 | + "gql_invoice_event_delete_perms": ["155304"], |
| 26 | + "gql_invoice_event_create_message_perms": ["155306"], |
| 27 | + "gql_invoice_event_delete_my_message_perms": ["155307"], |
27 | 28 | "gql_invoice_event_delete_all_message_perms": ["155308"], |
28 | 29 |
|
29 | 30 | "gql_bill_search_perms": ["156101"], |
30 | 31 | "gql_bill_create_perms": ["156102"], |
31 | 32 | "gql_bill_update_perms": ["156103"], |
32 | 33 | "gql_bill_delete_perms": ["156104"], |
33 | | - "gql_bill_amend_perms": ["156109"], |
| 34 | + "gql_bill_amend_perms": ["156109"], |
34 | 35 |
|
35 | 36 | "gql_bill_payment_search_perms": ["156201"], |
36 | 37 | "gql_bill_payment_create_perms": ["156202"], |
37 | 38 | "gql_bill_payment_update_perms": ["156203"], |
38 | 39 | "gql_bill_payment_delete_perms": ["156204"], |
39 | 40 | "gql_bill_payment_refund_perms": ["156206"], |
40 | 41 |
|
41 | | - "gql_bill_event_search_perms": ["156301"], |
42 | | - "gql_bill_event_create_perms": ["156302"], |
43 | | - "gql_bill_event_update_perms": ["156303"], |
44 | | - "gql_bill_event_delete_perms": ["156304"], |
45 | | - "gql_bill_event_create_message_perms": ["156306"], |
46 | | - "gql_bill_event_delete_my_message_perms": ["156307"], |
| 42 | + "gql_bill_event_search_perms": ["156301"], |
| 43 | + "gql_bill_event_create_perms": ["156302"], |
| 44 | + "gql_bill_event_update_perms": ["156303"], |
| 45 | + "gql_bill_event_delete_perms": ["156304"], |
| 46 | + "gql_bill_event_create_message_perms": ["156306"], |
| 47 | + "gql_bill_event_delete_my_message_perms": ["156307"], |
47 | 48 | "gql_bill_event_delete_all_message_perms": ["156308"], |
| 49 | + |
| 50 | + # Functions of type Callable[[QuerySet, User], QuerySet], to be used as custom user filters for bills and invoices |
| 51 | + # To be specified as "module_name.submodule.function_name" |
| 52 | + "bill_user_filter_function": None, |
| 53 | + "invoice_user_filter_function": None, |
48 | 54 | } |
49 | 55 |
|
50 | 56 | logger = logging.getLogger(__name__) |
51 | 57 |
|
52 | 58 |
|
53 | | -class InvoiceConfig(AppConfig): |
| 59 | +class InvoiceConfig(AppConfig, ConfigUtilMixin): |
54 | 60 | name = MODULE_NAME |
55 | 61 |
|
56 | 62 | default_currency_code = None |
@@ -89,12 +95,14 @@ class InvoiceConfig(AppConfig): |
89 | 95 | gql_bill_event_delete_my_message_perms = None |
90 | 96 | gql_bill_event_delete_all_message_perms = None |
91 | 97 |
|
92 | | - def __load_config(self, cfg): |
93 | | - for field in cfg: |
94 | | - if hasattr(InvoiceConfig, field): |
95 | | - setattr(InvoiceConfig, field, cfg[field]) |
| 98 | + bill_user_filter = None |
| 99 | + invoice_user_filter = None |
96 | 100 |
|
97 | 101 | def ready(self): |
98 | 102 | from core.models import ModuleConfiguration |
99 | 103 | cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CONFIG) |
100 | | - self.__load_config(cfg) |
| 104 | + self._load_config_fields(cfg) |
| 105 | + if cfg['bill_user_filter_function']: |
| 106 | + self._load_config_function('bill_user_filter', cfg['bill_user_filter_function']) |
| 107 | + if cfg['invoice_user_filter_function']: |
| 108 | + self._load_config_function('invoice_user_filter', cfg['invoice_user_filter_function']) |
0 commit comments