trex-model 1.6.2__tar.gz → 1.6.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of trex-model might be problematic. Click here for more details.

Files changed (65) hide show
  1. {trex_model-1.6.2 → trex_model-1.6.4}/PKG-INFO +1 -1
  2. {trex_model-1.6.2 → trex_model-1.6.4}/setup.py +1 -1
  3. {trex_model-1.6.2 → trex_model-1.6.4}/trex_model.egg-info/PKG-INFO +1 -1
  4. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/analytic_models.py +14 -2
  5. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/customer_models.py +1 -1
  6. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/helper/reward_transaction_helper.py +49 -14
  7. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/lucky_draw_models.py +16 -3
  8. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/merchant_models.py +27 -2
  9. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/ndb_models.py +10 -6
  10. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/partnership_models.py +85 -8
  11. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/redeem_models.py +50 -32
  12. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/reward_models.py +35 -2
  13. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/transaction_models.py +141 -93
  14. {trex_model-1.6.2 → trex_model-1.6.4}/LICENSE +0 -0
  15. {trex_model-1.6.2 → trex_model-1.6.4}/MANIFEST.in +0 -0
  16. {trex_model-1.6.2 → trex_model-1.6.4}/README.md +0 -0
  17. {trex_model-1.6.2 → trex_model-1.6.4}/setup.cfg +0 -0
  18. {trex_model-1.6.2 → trex_model-1.6.4}/trex_model.egg-info/SOURCES.txt +0 -0
  19. {trex_model-1.6.2 → trex_model-1.6.4}/trex_model.egg-info/dependency_links.txt +0 -0
  20. {trex_model-1.6.2 → trex_model-1.6.4}/trex_model.egg-info/requires.txt +0 -0
  21. {trex_model-1.6.2 → trex_model-1.6.4}/trex_model.egg-info/top_level.txt +0 -0
  22. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/__init__.py +0 -0
  23. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/conf.py +0 -0
  24. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/__init__.py +0 -0
  25. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/__init__.py +0 -0
  26. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/admin_models.py +0 -0
  27. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/app_models.py +0 -0
  28. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/coporate_models.py +0 -0
  29. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/customer_model_helpers.py +0 -0
  30. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/fb_subsriber_models.py +0 -0
  31. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/helper/__init__.py +0 -0
  32. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/helper/reward_model_helpers.py +0 -0
  33. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/import_models.py +0 -0
  34. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/inventory_model.py +0 -0
  35. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/loyalty_models.py +0 -0
  36. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/marketing_models.py +0 -0
  37. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/membership_models.py +0 -0
  38. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/merchant_promotion_models.py +0 -0
  39. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/message_model_helper.py +0 -0
  40. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/message_models.py +0 -0
  41. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/model_decorators.py +0 -0
  42. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/pos_models.py +0 -0
  43. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/prepaid_models.py +0 -0
  44. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/product_models.py +0 -0
  45. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/program_models.py +0 -0
  46. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/rating_models.py +0 -0
  47. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/recruit_models.py +0 -0
  48. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/redemption_catalogue_models.py +0 -0
  49. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/referral_program_model.py +0 -0
  50. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/spending_base_program_model.py +0 -0
  51. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/system_models.py +0 -0
  52. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/task_models.py +0 -0
  53. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/test_models.py +0 -0
  54. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/user_models.py +0 -0
  55. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/datastore/voucher_models.py +0 -0
  56. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/merchant_helpers.py +0 -0
  57. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/model_decorator.py +0 -0
  58. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/models/prepaid_helpers.py +0 -0
  59. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/pos_conf.py +0 -0
  60. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/program_conf.py +0 -0
  61. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/utils/__init__.py +0 -0
  62. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/utils/gcloud/__init__.py +0 -0
  63. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/utils/gcloud/datastore_util.py +0 -0
  64. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/utils/model/__init__.py +0 -0
  65. {trex_model-1.6.2 → trex_model-1.6.4}/trexmodel/utils/model/model_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trex_model
3
- Version: 1.6.2
3
+ Version: 1.6.4
4
4
  Summary: TRex database module package
5
5
  Home-page: https://bitbucket.org/lokjac/trex-model
6
6
  Author: Jack Lok
@@ -3,7 +3,7 @@ with open("README.md", "r") as fh:
3
3
  long_description = fh.read()
4
4
  setuptools.setup(
5
5
  name='trex_model',
6
- version='1.6.2',
6
+ version='1.6.4',
7
7
  author="Jack Lok",
8
8
  author_email="sglok77@gmail.com",
9
9
  description="TRex database module package",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trex-model
3
- Version: 1.6.2
3
+ Version: 1.6.4
4
4
  Summary: TRex database module package
5
5
  Home-page: https://bitbucket.org/lokjac/trex-model
6
6
  Author: Jack Lok
@@ -17,8 +17,9 @@ class UpstreamData(BaseNModel, DictModel):
17
17
  stream_content = ndb.JsonProperty(required=True)
18
18
  is_sent = ndb.BooleanProperty(required=True, default=False)
19
19
  created_datetime = ndb.DateTimeProperty(required=True, auto_now_add=True)
20
+ partition_datetime = ndb.DateTimeProperty(required=False)
20
21
 
21
- dict_properties = ['table_template_name', 'dataset_name', 'table_name', 'stream_content', 'is_sent']
22
+ dict_properties = ['table_template_name', 'dataset_name', 'table_name', 'stream_content', 'is_sent', 'partition_datetime']
22
23
 
23
24
  @staticmethod
24
25
  def list_not_send(offset=0, limit=model_conf.MAX_FETCH_RECORD, start_cursor=None,return_with_cursor=False, keys_only=False):
@@ -27,6 +28,12 @@ class UpstreamData(BaseNModel, DictModel):
27
28
  return UpstreamData.list_all_with_condition_query(query, offset=offset, start_cursor=start_cursor, return_with_cursor=return_with_cursor, keys_only=keys_only, limit=limit)
28
29
 
29
30
 
31
+ @staticmethod
32
+ def list_all(offset=0, limit=model_conf.MAX_FETCH_RECORD, start_cursor=None,return_with_cursor=False, keys_only=False):
33
+ query = UpstreamData.query()
34
+
35
+ return UpstreamData.list_all_with_condition_query(query, offset=offset, start_cursor=start_cursor, return_with_cursor=return_with_cursor, keys_only=keys_only, limit=limit)
36
+
30
37
  @staticmethod
31
38
  def list_by_date_range(datetime_start, datetime_end, offset=0, limit=model_conf.MAX_FETCH_RECORD, start_cursor=None,return_with_cursor=False, keys_only=False):
32
39
 
@@ -43,6 +50,10 @@ class UpstreamData(BaseNModel, DictModel):
43
50
  def count_not_sent(limit=model_conf.MAX_FETCH_RECORD):
44
51
  return UpstreamData.query(ndb.AND(UpstreamData.is_sent==False)).count(limit = limit)
45
52
 
53
+ @staticmethod
54
+ def count_all(limit=model_conf.MAX_FETCH_RECORD):
55
+ return UpstreamData.query().count(limit = limit)
56
+
46
57
  @staticmethod
47
58
  def count_by_date_range(datetime_start, datetime_end, limit=model_conf.MAX_FETCH_RECORD):
48
59
  datetime_end = datetime_end + timedelta(days=1)
@@ -53,13 +64,14 @@ class UpstreamData(BaseNModel, DictModel):
53
64
  )).count(limit = limit)
54
65
 
55
66
  @staticmethod
56
- def create(merchant_acct, dataset_name, table_name, table_template_name, stream_content):
67
+ def create(merchant_acct, dataset_name, table_name, table_template_name, stream_content, partition_datetime=None):
57
68
  UpstreamData(
58
69
  merchant_acct = merchant_acct.create_ndb_key(),
59
70
  table_template_name = table_template_name,
60
71
  dataset_name = dataset_name,
61
72
  table_name = table_name,
62
73
  stream_content = stream_content,
74
+ partition_datetime = partition_datetime,
63
75
  ).put()
64
76
 
65
77
 
@@ -757,7 +757,7 @@ class Customer(BaseNModel, DictModel, FullTextSearchable):
757
757
  def update_after_added_voucher(self, added_voucher):
758
758
  entitled_voucher_summary = self.entitled_voucher_summary
759
759
  update_customer_entiteld_voucher_summary_with_customer_new_voucher(entitled_voucher_summary, added_voucher)
760
- self.put()
760
+ self.put()
761
761
 
762
762
  class CustomerMembership(BaseNModel, DictModel):
763
763
  '''
@@ -25,8 +25,8 @@ from trexanalytics.bigquery_upstream_data_config import create_merchant_customer
25
25
  create_merchant_customer_prepaid_upstream_for_merchant,\
26
26
  create_merchant_customer_redemption_reverted_upstream_for_merchant,\
27
27
  create_revert_entitled_customer_voucher_upstream_for_merchant,\
28
- create_entitled_customer_voucher_upstream_for_merchant,\
29
- create_redeemed_customer_voucher_to_upstream_for_merchant
28
+ create_redeemed_customer_voucher_to_upstream_for_merchant,\
29
+ create_merchant_sales_transaction_upstream_for_merchant
30
30
  from trexmodel.models.datastore.membership_models import MerchantTierMembership
31
31
  from trexmodel.models.datastore.transaction_models import CustomerTransaction,\
32
32
  SalesTransaction
@@ -139,7 +139,7 @@ def create_sales_transaction(transact_outlet=None, sales_amount=.0, tax_amount=.
139
139
  logger.debug('invoice_details=%s', invoice_details)
140
140
 
141
141
  @model_transactional(desc='create_sales_transaction')
142
- def __start_transaction_for_customer_transaction():
142
+ def __start_transaction_for_sales_transaction():
143
143
  sales_transaction = SalesTransaction.create(
144
144
  transact_outlet = transact_outlet,
145
145
 
@@ -156,11 +156,11 @@ def create_sales_transaction(transact_outlet=None, sales_amount=.0, tax_amount=.
156
156
 
157
157
  )
158
158
 
159
- #create_merchant_sales_transaction_upstream_for_merchant(sales_transaction, streamed_datetime=transact_datetime)
159
+ create_merchant_sales_transaction_upstream_for_merchant(sales_transaction, streamed_datetime=transact_datetime)
160
160
 
161
161
  return sales_transaction
162
162
 
163
- return __start_transaction_for_customer_transaction()
163
+ return __start_transaction_for_sales_transaction()
164
164
 
165
165
  def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, tax_amount=.0, invoice_id=None, remarks=None,
166
166
  transact_by=None, transact_datetime=None, invoice_details=None, promotion_code=None):
@@ -171,6 +171,25 @@ def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, t
171
171
 
172
172
  @model_transactional(desc='create_reward_transaction')
173
173
  def __start_transaction_for_customer_transaction():
174
+
175
+ sales_transaction = SalesTransaction.create(
176
+ transact_outlet = transact_outlet,
177
+
178
+ transact_amount = sales_amount,
179
+ tax_amount = tax_amount,
180
+
181
+ invoice_id = invoice_id,
182
+ remarks = remarks,
183
+
184
+ transact_by = transact_by,
185
+
186
+ transact_datetime = transact_datetime,
187
+
188
+ )
189
+ create_merchant_sales_transaction_upstream_for_merchant(sales_transaction)
190
+
191
+ #customer_transaction = give_reward_from_sales_transaction(customer, sales_transaction)
192
+
174
193
  customer_transaction = CustomerTransaction.create_system_transaction(
175
194
  customer,
176
195
  transact_outlet = transact_outlet,
@@ -196,7 +215,8 @@ def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, t
196
215
 
197
216
  if trigger_check_reward_success:
198
217
  create_transaction_message(customer_transaction)
199
- create_merchant_customer_transaction_upstream_for_merchant(customer_transaction, streamed_datetime=transact_datetime)
218
+ create_merchant_customer_transaction_upstream_for_merchant(customer_transaction, )
219
+
200
220
 
201
221
  return customer_transaction
202
222
 
@@ -216,7 +236,7 @@ def give_reward_from_sales_transaction(customer, sales_transaction, for_testing=
216
236
 
217
237
  if trigger_check_reward_success:
218
238
  create_transaction_message(customer_transaction)
219
- create_merchant_customer_transaction_upstream_for_merchant(customer_transaction, streamed_datetime=sales_transaction.transact_datetime)
239
+ create_merchant_customer_transaction_upstream_for_merchant(customer_transaction,)
220
240
 
221
241
  return customer_transaction
222
242
 
@@ -389,12 +409,12 @@ def check_for_tier_membership_upgrade_downgrade(customer_acct, merchant_acct, tr
389
409
  existing_tier_membership = None
390
410
  membership_to_assign = None
391
411
 
392
- customer_kpi_summary = customer_acct.kpi_summary
412
+ customer_kpi_summary = customer_acct.kpi_summary or {}
393
413
 
394
- total_transact_amount = customer_kpi_summary['total_transact_amount']
395
- total_accumulated_point = customer_kpi_summary['total_accumulated_point']
396
- total_accumulated_stamp = customer_kpi_summary['total_accumulated_stamp']
397
- total_accumulated_prepaid = customer_kpi_summary['total_accumulated_prepaid']
414
+ total_transact_amount = customer_kpi_summary.get('total_transact_amount',0)
415
+ total_accumulated_point = customer_kpi_summary.get('total_accumulated_point',0)
416
+ total_accumulated_stamp = customer_kpi_summary.get('total_accumulated_stamp',0)
417
+ total_accumulated_prepaid = customer_kpi_summary.get('total_accumulated_prepaid',0)
398
418
 
399
419
  logger.debug('check_for_tier_membership_upgrade_downgrade: total_transact_amount=%s', total_transact_amount)
400
420
  logger.debug('check_for_tier_membership_upgrade_downgrade: total_accumulated_point=%s', total_accumulated_point)
@@ -712,7 +732,7 @@ def redeem_reward_transaction(customer, redeem_outlet=None, reward_format=None,
712
732
 
713
733
  if customer_redemption:
714
734
  create_redemption_message(customer_redemption)
715
- create_merchant_customer_redemption_upstream_for_merchant(customer_redemption, streamed_datetime=redeemed_datetime)
735
+ create_merchant_customer_redemption_upstream_for_merchant(customer_redemption, )
716
736
  if reward_format == program_conf.REWARD_FORMAT_VOUCHER:
717
737
  for voucher_key in redeemed_voucher_keys_list:
718
738
  customer_voucher = CustomerEntitledVoucher.fetch(voucher_key)
@@ -920,6 +940,21 @@ def revert_transaction(transaction_details, reverted_by, reverted_datetime=None,
920
940
  transaction_details.reverted_by_username = reverted_by.username
921
941
  transaction_details.put()
922
942
 
943
+ create_merchant_customer_transaction_upstream_for_merchant(transaction_details, Reverted=True)
944
+
945
+ if transaction_details.is_sales_transaction:
946
+ sales_transaction = SalesTransaction.get_by_transaction_id(transaction_id)
947
+
948
+ if sales_transaction:
949
+ sales_transaction.is_revert = True
950
+ sales_transaction.reverted_datetime = reverted_datetime
951
+ sales_transaction.reverted_by = reverted_by_key
952
+ sales_transaction.reverted_by_username = reverted_by.username
953
+ sales_transaction.put()
954
+
955
+ create_merchant_sales_transaction_upstream_for_merchant(sales_transaction, Reverted=True)
956
+
957
+
923
958
  if is_stamp_entitled_in_transaction or is_point_entitled_in_transaction or is_voucher_entitled_in_transaction or is_prepaid_entitled_in_transaction:
924
959
  for p in reverting_point_details_list:
925
960
  if p.is_valid:
@@ -1265,7 +1300,7 @@ def update_transaction_all_entitled_reward_summary(transaction_id):
1265
1300
 
1266
1301
  if vouchers_list:
1267
1302
  logger.debug('found entitled voucher list')
1268
- entiteld_voucher_brief = EntitledVoucherSummary()
1303
+ entiteld_voucher_brief = EntitledVoucherSummary(transaction_id=transaction_id)
1269
1304
 
1270
1305
  for customer_voucher in vouchers_list:
1271
1306
  merchant_voucher = customer_voucher.entitled_voucher_entity
@@ -16,6 +16,7 @@ import random
16
16
  from trexlib.utils.common.common_util import sort_dict_list
17
17
  from trexmodel.models.datastore.customer_models import Customer
18
18
  from collections import Counter
19
+ from trexmodel.models.datastore.voucher_models import MerchantVoucher
19
20
 
20
21
  logger = logging.getLogger('model')
21
22
  #logger = logging.getLogger('debug')
@@ -678,15 +679,27 @@ class LuckyDrawTicket(BaseNModel, DictModel):
678
679
  program = LuckyDrawTicket.__get_lucky_draw_program(merchant_acct.lucky_draw_configuration, customer_acct=customer_acct)
679
680
  if program:
680
681
  program_key = program.get('program_key')
681
- prize_details_list = program.get('program_settings').get('prize_settings').get('prizes')
682
- ticket_image_url = program.get('program_settings').get('ticket_image_url')
683
-
682
+ prize_details_list = program.get('program_settings').get('prize_settings').get('prizes')
683
+ ticket_image_url = program.get('program_settings').get('ticket_image_url')
684
+ archived_vouchers_list = MerchantVoucher.list_archived_by_merchant_account(merchant_acct)
684
685
  for prize in prize_details_list:
685
686
  if prize.get('prize_type') == program_conf.REWARD_FORMAT_VOUCHER:
687
+ found_voucher = False
686
688
  for voucher_details in merchant_acct.published_voucher_configuration.get('vouchers'):
687
689
  if voucher_details.get('voucher_key') == prize.get('voucher_key'):
688
690
  prize['image_url'] = voucher_details.get('image_url')
689
691
  prize['label'] = voucher_details.get('label')
692
+ found_voucher = True
693
+
694
+ if found_voucher==False:
695
+ logger.info('Some voucher may be archived')
696
+
697
+ if archived_vouchers_list:
698
+ for voucher_details in archived_vouchers_list:
699
+ if voucher_details.key_in_str == prize.get('voucher_key'):
700
+ prize['image_url'] = voucher_details.image_public_url
701
+ prize['label'] = voucher_details.label
702
+ found_voucher = True
690
703
 
691
704
 
692
705
  drawed_details = {
@@ -81,6 +81,7 @@ class MerchantAcct(MerchantMin):
81
81
  published_tier_program_configuration = ndb.JsonProperty()
82
82
 
83
83
  approved_partner_merchant_configuration = ndb.JsonProperty()
84
+ partner_merchant_history_configuration = ndb.JsonProperty()
84
85
 
85
86
  membership_configuration = ndb.JsonProperty()
86
87
  tier_membership_configuration = ndb.JsonProperty()
@@ -115,7 +116,7 @@ class MerchantAcct(MerchantMin):
115
116
  'dashboard_stat_figure', 'program_settings', 'is_tier_membership_configured', 'website',
116
117
  'product_package', 'loyalty_package','pos_package', 'account_plan','outlet_count', 'outlet_limit',
117
118
  'published_redemption_catalogue_configuration', 'partner_redemption_catalogue_configuration',
118
- 'approved_partner_merchant_configuration',
119
+ 'approved_partner_merchant_configuration', 'partner_merchant_history_configuration',
119
120
  'logo_public_url'
120
121
  ]
121
122
 
@@ -877,6 +878,12 @@ class MerchantAcct(MerchantMin):
877
878
  def update_partner_merchant_configuration(self, partner_merchant_configuration):
878
879
  merchant_acct_key = partner_merchant_configuration.get('merchant_acct_key')
879
880
 
881
+ if is_empty(self.partner_merchant_history_configuration):
882
+ self.partner_merchant_history_configuration = {
883
+ 'partners':{},
884
+ 'count':0
885
+ }
886
+
880
887
  if is_empty(self.approved_partner_merchant_configuration):
881
888
  self.approved_partner_merchant_configuration = {
882
889
  'partners' :{
@@ -884,15 +891,33 @@ class MerchantAcct(MerchantMin):
884
891
  },
885
892
  'count' : 1,
886
893
  }
894
+
895
+ self.partner_merchant_history_configuration = {
896
+ 'partners' :{
897
+ merchant_acct_key : partner_merchant_configuration,
898
+ },
899
+ 'count' : 1,
900
+ }
887
901
 
888
902
  else:
903
+
889
904
  existing_partner_merchant_dict = self.approved_partner_merchant_configuration.get('partners')
890
- partner_merchant_details = existing_partner_merchant_dict.get(merchant_acct_key)
905
+ partner_merchant_history_dict = self.partner_merchant_history_configuration.get('partners')
906
+ partner_merchant_details = existing_partner_merchant_dict.get(merchant_acct_key)
907
+
891
908
  if partner_merchant_details:
892
909
  existing_partner_merchant_dict[merchant_acct_key] = partner_merchant_configuration
893
910
  else:
894
911
  existing_partner_merchant_dict[merchant_acct_key] = partner_merchant_configuration
895
912
  self.approved_partner_merchant_configuration['count']+=self.approved_partner_merchant_configuration['count']
913
+
914
+ partner_merchant_details = partner_merchant_history_dict.get(merchant_acct_key)
915
+ if partner_merchant_details:
916
+ partner_merchant_history_dict[merchant_acct_key] = partner_merchant_configuration
917
+ else:
918
+ partner_merchant_history_dict[merchant_acct_key] = partner_merchant_configuration
919
+
920
+ self.partner_merchant_history_configuration['count']=len(self.partner_merchant_history_configuration['partners'])
896
921
 
897
922
  self.put()
898
923
  deleteFromCache(self.key_in_str)
@@ -18,8 +18,8 @@ from trexconf import conf as model_conf
18
18
  from google.cloud.datastore.helpers import GeoPoint
19
19
  from trexlib.utils.common.cache_util import getFromCache, setCache
20
20
 
21
- #logger = logging.getLogger('model')
22
- logger = logging.getLogger('target_debug')
21
+ logger = logging.getLogger('model')
22
+ #logger = logging.getLogger('target_debug')
23
23
 
24
24
  def clone_entity(entity, parent=None, **extra_args):
25
25
  """
@@ -367,10 +367,11 @@ class BaseNModel(DictModel, NDBModel):
367
367
  )
368
368
 
369
369
  @classmethod
370
- def list_all_with_condition_query(cls, query, offset=0, start_cursor=None, return_with_cursor=False, keys_only=False,
371
- limit=model_conf.MAX_FETCH_RECORD):
370
+ def list_all_with_condition_query(cls, query, offset=0, start_cursor=None, return_with_cursor=False,
371
+ keys_only=False,limit=model_conf.MAX_FETCH_RECORD, order_by=None):
372
372
 
373
373
 
374
+ logger.debug('list_all: start_cursor=%s, order_by=%s, return_with_cursor=%s', start_cursor, order_by, return_with_cursor)
374
375
 
375
376
  if start_cursor or return_with_cursor:
376
377
  if is_not_empty(start_cursor):
@@ -379,12 +380,15 @@ class BaseNModel(DictModel, NDBModel):
379
380
  else:
380
381
  start_cursor = ndb.Cursor()
381
382
 
382
- (search_results, next_cursor, more) = query.fetch_page(page_size=limit, start_cursor=start_cursor, keys_only=keys_only)
383
+ if order_by:
384
+ (search_results, next_cursor, more) = query.order(order_by).fetch_page(page_size=limit, start_cursor=start_cursor, keys_only=keys_only)
385
+ else:
386
+ (search_results, next_cursor, more) = query.fetch_page(page_size=limit, start_cursor=start_cursor, keys_only=keys_only)
383
387
  logger.debug('##########################################')
384
-
385
388
  logger.debug('list_all: results=%s', search_results)
386
389
  logger.debug('list_all: next_cursor=%s', next_cursor)
387
390
  logger.debug('list_all: more=%s', more)
391
+ logger.debug('list_all: return_with_cursor=%s', return_with_cursor)
388
392
 
389
393
  logger.debug('##########################################')
390
394
 
@@ -9,14 +9,16 @@ from trexmodel.models.datastore.ndb_models import BaseNModel, DictModel
9
9
  import logging
10
10
  from trexmodel.models.datastore.merchant_models import MerchantAcct,\
11
11
  MerchantUser
12
- from trexconf import program_conf
13
- from datetime import datetime
12
+ from trexconf import program_conf, conf
13
+ from datetime import datetime, timedelta
14
14
  from trexlib.utils.string_util import is_not_empty
15
15
  from trexmodel.models.datastore.redemption_catalogue_models import RedemptionCatalogue
16
16
  from trexmodel.models.merchant_helpers import convert_points_between_merchants
17
17
  from trexmodel.models.datastore.user_models import User
18
18
  from trexlib.utils.common.cache_util import setCache, getFromCache,\
19
19
  deleteFromCache
20
+ from trexlib.utils.common.date_util import convert_date_to_datetime
21
+
20
22
 
21
23
 
22
24
  logger = logging.getLogger('target_debug')
@@ -322,22 +324,58 @@ class PartnershipRewardTransaction(BaseNModel, DictModel):
322
324
  '''
323
325
  This is used to record convert merchant point to partner merchant point
324
326
  '''
325
- merchant_acct = ndb.KeyProperty(name="merchant_acct", kind=MerchantAcct)
326
- partner_merchant_acct = ndb.KeyProperty(name="partner_merchant_acct", kind=MerchantAcct)
327
+ merchant_acct = ndb.KeyProperty(name="merchant_acct", kind=MerchantAcct)
328
+ partner_merchant_acct = ndb.KeyProperty(name="partner_merchant_acct", kind=MerchantAcct)
327
329
 
328
330
  merchant_point_worth_value_in_currency = ndb.FloatProperty(required=True, default=.0)
329
331
  partner_point_worth_value_in_currency = ndb.FloatProperty(required=True, default=.0)
330
332
 
331
- transact_point_amount = ndb.FloatProperty(required=True)
332
- transact_datetime = ndb.DateTimeProperty(required=True, auto_now_add=True)
333
+ transact_point_amount = ndb.FloatProperty(required=True)
334
+ transact_datetime = ndb.DateTimeProperty(required=True, auto_now_add=True)
335
+
336
+ user_acct = ndb.KeyProperty(name="user_acct", kind=User)
337
+ transaction_id = ndb.StringProperty(required=True)
338
+ reward_summary = ndb.JsonProperty()
339
+
340
+ is_revert = ndb.BooleanProperty(required=False, default=False)
341
+ reverted_datetime = ndb.DateTimeProperty(required=False)
342
+ reverted_by = ndb.KeyProperty(name="reverted_by", kind=MerchantUser)
343
+ reverted_by_username = ndb.StringProperty(required=False)
344
+
345
+ dict_properties = [
346
+ 'partner_merchant_acct_key', 'merchant_point_worth_value_in_currency', 'partner_point_worth_value_in_currency',
347
+ 'transact_point_amount', 'transact_datetime', 'reward_summary', 'transaction_id',
348
+ ]
349
+
350
+ @property
351
+ def merchant_acct_key(self):
352
+ return self.merchant_acct.urlsafe().decode('utf-8')
353
+
354
+ @property
355
+ def partner_merchant_acct_key(self):
356
+ return self.partner_merchant_acct.urlsafe().decode('utf-8')
357
+
358
+ @property
359
+ def merchant_acct_entity(self):
360
+ return self.merchant_acct.get()
361
+
362
+ @property
363
+ def partner_merchant_acct_entity(self):
364
+ return self.partner_merchant_acct.get()
333
365
 
334
- user_acct = ndb.KeyProperty(name="user_acct", kind=User)
366
+ @property
367
+ def user_acct_entity(self):
368
+ return self.user_acct.get()
369
+
370
+ @property
371
+ def user_acct_reference_code(self):
372
+ return self.user_acct_entity.reference_code
335
373
 
336
374
  def convertion_rate(self)->float:
337
375
  return self.merchant_point_worth_value_in_currency/self.partner_point_worth_value_in_currency
338
376
 
339
377
  @staticmethod
340
- def create(merchant_acct, partner_merchant_acct, user_acct, transact_point_amount):
378
+ def create(merchant_acct, partner_merchant_acct, user_acct, transact_point_amount, reward_summary=None):
341
379
  merchant_artnership_settings = PartnershipSettings.get_by_merchant_acct(merchant_acct)
342
380
  partner_partnership_settings = PartnershipSettings.get_by_merchant_acct(partner_merchant_acct)
343
381
 
@@ -353,6 +391,10 @@ class PartnershipRewardTransaction(BaseNModel, DictModel):
353
391
 
354
392
  transact_point_amount = transact_point_amount,
355
393
  user_acct = user_acct.create_ndb_key(),
394
+ reward_summary = {
395
+ 'entitled_voucher_summary': reward_summary.entitled_voucher_summary,
396
+ },
397
+ transaction_id = reward_summary.transaction_id,
356
398
  )
357
399
  partnership_reward_transaction.put()
358
400
  return partnership_reward_transaction
@@ -361,7 +403,42 @@ class PartnershipRewardTransaction(BaseNModel, DictModel):
361
403
  raise Exception('Merchant or partner partnership settings is not enabled or created')
362
404
 
363
405
 
406
+ @staticmethod
407
+ def list_transaction_by_date(enquiry_date, merchant_acct=None, partner_merchant_acct=None, offset=0, limit=conf.PAGINATION_SIZE, return_with_cursor=False, start_cursor=None):
408
+ start_datetime = convert_date_to_datetime(enquiry_date)
409
+ end_datetime = start_datetime + timedelta(days=1)
410
+ query = PartnershipRewardTransaction.query(
411
+ ndb.AND(
412
+ PartnershipRewardTransaction.merchant_acct==merchant_acct.create_ndb_key(),
413
+ PartnershipRewardTransaction.partner_merchant_acct==partner_merchant_acct.create_ndb_key(),
414
+ PartnershipRewardTransaction.transact_datetime>=start_datetime,
415
+ PartnershipRewardTransaction.transact_datetime<end_datetime,
416
+ ))
417
+ if return_with_cursor:
418
+ (result, next_cursor) = PartnershipRewardTransaction.list_all_with_condition_query(query, order_by=PartnershipRewardTransaction.transact_datetime, start_cursor=start_cursor, return_with_cursor=True, limit=limit)
419
+
420
+ return (result, next_cursor)
421
+ else:
422
+ return query.order(PartnershipRewardTransaction.transact_datetime).fetch(offset=offset, limit=limit)
364
423
 
365
424
 
425
+ @staticmethod
426
+ def list_merchant_partnership_reward_transaction(merchant_acct, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True, keys_only=False):
427
+ if keys_only:
428
+ query = PartnershipRewardTransaction.query(ndb.AND(PartnershipRewardTransaction.merchant_acct==merchant_acct.create_ndb_key()))
429
+ return PartnershipRewardTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, keys_only=True)
430
+ else:
431
+ if reverse_order:
432
+ query = PartnershipRewardTransaction.query(ndb.AND(PartnershipRewardTransaction.merchant_acct==merchant_acct.create_ndb_key())).order(-PartnershipRewardTransaction.transact_datetime)
433
+ else:
434
+ query = PartnershipRewardTransaction.query(ndb.AND(PartnershipRewardTransaction.merchant_acct==merchant_acct.create_ndb_key())).order(PartnershipRewardTransaction.transact_datetime)
435
+
436
+ return PartnershipRewardTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
366
437
 
438
+ @staticmethod
439
+ def count_merchant_partnership_reward_transaction(merchant_acct, limit=conf.MAX_FETCH_RECORD):
440
+ query = PartnershipRewardTransaction.query(ndb.AND(PartnershipRewardTransaction.merchant_acct==merchant_acct.create_ndb_key()))
441
+
442
+ return PartnershipRewardTransaction.count_with_condition_query(query, limit=limit)
367
443
 
444
+