trex-model 1.6.3__tar.gz → 1.6.5__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.
- {trex_model-1.6.3 → trex_model-1.6.5}/PKG-INFO +1 -1
- {trex_model-1.6.3 → trex_model-1.6.5}/setup.py +1 -1
- {trex_model-1.6.3 → trex_model-1.6.5}/trex_model.egg-info/PKG-INFO +1 -1
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/customer_models.py +4 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/helper/reward_transaction_helper.py +51 -17
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/lucky_draw_models.py +16 -3
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/ndb_models.py +2 -2
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/reward_models.py +26 -1
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/transaction_models.py +153 -223
- {trex_model-1.6.3 → trex_model-1.6.5}/LICENSE +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/MANIFEST.in +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/README.md +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/setup.cfg +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trex_model.egg-info/SOURCES.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trex_model.egg-info/dependency_links.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trex_model.egg-info/requires.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trex_model.egg-info/top_level.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/admin_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/analytic_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/app_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/coporate_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/customer_model_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/fb_subsriber_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/helper/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/helper/reward_model_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/import_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/inventory_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/loyalty_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/marketing_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/membership_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/merchant_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/merchant_promotion_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/message_model_helper.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/message_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/model_decorators.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/partnership_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/pos_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/prepaid_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/product_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/program_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/rating_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/recruit_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/redeem_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/redemption_catalogue_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/referral_program_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/spending_base_program_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/system_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/task_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/test_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/user_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/voucher_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/merchant_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/model_decorator.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/prepaid_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/pos_conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/program_conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/utils/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/utils/gcloud/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/utils/gcloud/datastore_util.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/utils/model/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/utils/model/model_util.py +0 -0
{trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/helper/reward_transaction_helper.py
RENAMED
|
@@ -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
|
-
|
|
29
|
-
|
|
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
|
|
142
|
+
def __start_transaction_for_sales_transaction():
|
|
143
143
|
sales_transaction = SalesTransaction.create(
|
|
144
144
|
transact_outlet = transact_outlet,
|
|
145
145
|
|
|
@@ -152,15 +152,14 @@ def create_sales_transaction(transact_outlet=None, sales_amount=.0, tax_amount=.
|
|
|
152
152
|
transact_by = transact_by,
|
|
153
153
|
|
|
154
154
|
transact_datetime = transact_datetime,
|
|
155
|
-
promotion_code = promotion_code,
|
|
156
155
|
|
|
157
156
|
)
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
create_merchant_sales_transaction_upstream_for_merchant(sales_transaction,)
|
|
160
159
|
|
|
161
160
|
return sales_transaction
|
|
162
161
|
|
|
163
|
-
return
|
|
162
|
+
return __start_transaction_for_sales_transaction()
|
|
164
163
|
|
|
165
164
|
def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, tax_amount=.0, invoice_id=None, remarks=None,
|
|
166
165
|
transact_by=None, transact_datetime=None, invoice_details=None, promotion_code=None):
|
|
@@ -171,6 +170,25 @@ def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, t
|
|
|
171
170
|
|
|
172
171
|
@model_transactional(desc='create_reward_transaction')
|
|
173
172
|
def __start_transaction_for_customer_transaction():
|
|
173
|
+
|
|
174
|
+
sales_transaction = SalesTransaction.create(
|
|
175
|
+
transact_outlet = transact_outlet,
|
|
176
|
+
|
|
177
|
+
transact_amount = sales_amount,
|
|
178
|
+
tax_amount = tax_amount,
|
|
179
|
+
|
|
180
|
+
invoice_id = invoice_id,
|
|
181
|
+
remarks = remarks,
|
|
182
|
+
|
|
183
|
+
transact_by = transact_by,
|
|
184
|
+
|
|
185
|
+
transact_datetime = transact_datetime,
|
|
186
|
+
|
|
187
|
+
)
|
|
188
|
+
create_merchant_sales_transaction_upstream_for_merchant(sales_transaction)
|
|
189
|
+
|
|
190
|
+
#customer_transaction = give_reward_from_sales_transaction(customer, sales_transaction)
|
|
191
|
+
|
|
174
192
|
customer_transaction = CustomerTransaction.create_system_transaction(
|
|
175
193
|
customer,
|
|
176
194
|
transact_outlet = transact_outlet,
|
|
@@ -196,7 +214,8 @@ def create_reward_transaction(customer, transact_outlet=None, sales_amount=.0, t
|
|
|
196
214
|
|
|
197
215
|
if trigger_check_reward_success:
|
|
198
216
|
create_transaction_message(customer_transaction)
|
|
199
|
-
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction,
|
|
217
|
+
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction, )
|
|
218
|
+
|
|
200
219
|
|
|
201
220
|
return customer_transaction
|
|
202
221
|
|
|
@@ -216,7 +235,7 @@ def give_reward_from_sales_transaction(customer, sales_transaction, for_testing=
|
|
|
216
235
|
|
|
217
236
|
if trigger_check_reward_success:
|
|
218
237
|
create_transaction_message(customer_transaction)
|
|
219
|
-
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction,
|
|
238
|
+
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction,)
|
|
220
239
|
|
|
221
240
|
return customer_transaction
|
|
222
241
|
|
|
@@ -389,12 +408,12 @@ def check_for_tier_membership_upgrade_downgrade(customer_acct, merchant_acct, tr
|
|
|
389
408
|
existing_tier_membership = None
|
|
390
409
|
membership_to_assign = None
|
|
391
410
|
|
|
392
|
-
customer_kpi_summary = customer_acct.kpi_summary
|
|
411
|
+
customer_kpi_summary = customer_acct.kpi_summary or {}
|
|
393
412
|
|
|
394
|
-
total_transact_amount = customer_kpi_summary
|
|
395
|
-
total_accumulated_point = customer_kpi_summary
|
|
396
|
-
total_accumulated_stamp = customer_kpi_summary
|
|
397
|
-
total_accumulated_prepaid = customer_kpi_summary
|
|
413
|
+
total_transact_amount = customer_kpi_summary.get('total_transact_amount',0)
|
|
414
|
+
total_accumulated_point = customer_kpi_summary.get('total_accumulated_point',0)
|
|
415
|
+
total_accumulated_stamp = customer_kpi_summary.get('total_accumulated_stamp',0)
|
|
416
|
+
total_accumulated_prepaid = customer_kpi_summary.get('total_accumulated_prepaid',0)
|
|
398
417
|
|
|
399
418
|
logger.debug('check_for_tier_membership_upgrade_downgrade: total_transact_amount=%s', total_transact_amount)
|
|
400
419
|
logger.debug('check_for_tier_membership_upgrade_downgrade: total_accumulated_point=%s', total_accumulated_point)
|
|
@@ -712,7 +731,7 @@ def redeem_reward_transaction(customer, redeem_outlet=None, reward_format=None,
|
|
|
712
731
|
|
|
713
732
|
if customer_redemption:
|
|
714
733
|
create_redemption_message(customer_redemption)
|
|
715
|
-
create_merchant_customer_redemption_upstream_for_merchant(customer_redemption,
|
|
734
|
+
create_merchant_customer_redemption_upstream_for_merchant(customer_redemption, )
|
|
716
735
|
if reward_format == program_conf.REWARD_FORMAT_VOUCHER:
|
|
717
736
|
for voucher_key in redeemed_voucher_keys_list:
|
|
718
737
|
customer_voucher = CustomerEntitledVoucher.fetch(voucher_key)
|
|
@@ -752,7 +771,7 @@ def prepaid_payment_transaction(customer, redeem_outlet=None, reward_format=None
|
|
|
752
771
|
|
|
753
772
|
if customer_redemption:
|
|
754
773
|
create_payment_message(customer_redemption)
|
|
755
|
-
create_merchant_customer_redemption_upstream_for_merchant(customer_redemption,
|
|
774
|
+
create_merchant_customer_redemption_upstream_for_merchant(customer_redemption, )
|
|
756
775
|
|
|
757
776
|
return customer_redemption
|
|
758
777
|
|
|
@@ -920,6 +939,21 @@ def revert_transaction(transaction_details, reverted_by, reverted_datetime=None,
|
|
|
920
939
|
transaction_details.reverted_by_username = reverted_by.username
|
|
921
940
|
transaction_details.put()
|
|
922
941
|
|
|
942
|
+
create_merchant_customer_transaction_upstream_for_merchant(transaction_details, Reverted=True)
|
|
943
|
+
|
|
944
|
+
if transaction_details.is_sales_transaction:
|
|
945
|
+
sales_transaction = SalesTransaction.get_by_transaction_id(transaction_id)
|
|
946
|
+
|
|
947
|
+
if sales_transaction:
|
|
948
|
+
sales_transaction.is_revert = True
|
|
949
|
+
sales_transaction.reverted_datetime = reverted_datetime
|
|
950
|
+
sales_transaction.reverted_by = reverted_by_key
|
|
951
|
+
sales_transaction.reverted_by_username = reverted_by.username
|
|
952
|
+
sales_transaction.put()
|
|
953
|
+
|
|
954
|
+
create_merchant_sales_transaction_upstream_for_merchant(sales_transaction, Reverted=True)
|
|
955
|
+
|
|
956
|
+
|
|
923
957
|
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
958
|
for p in reverting_point_details_list:
|
|
925
959
|
if p.is_valid:
|
|
@@ -1163,8 +1197,8 @@ def create_topup_prepaid_transaction(customer, prepaid_program, topup_outlet=Non
|
|
|
1163
1197
|
update_customer_kpi_summary_and_transact_summary(customer, customer_transaction)
|
|
1164
1198
|
|
|
1165
1199
|
create_transaction_message(customer_transaction)
|
|
1166
|
-
create_merchant_customer_prepaid_upstream_for_merchant(customer_transaction, prepaid_topup_reward,
|
|
1167
|
-
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction,
|
|
1200
|
+
create_merchant_customer_prepaid_upstream_for_merchant(customer_transaction, prepaid_topup_reward, )
|
|
1201
|
+
create_merchant_customer_transaction_upstream_for_merchant(customer_transaction, )
|
|
1168
1202
|
|
|
1169
1203
|
return (customer_transaction, prepaid_summary)
|
|
1170
1204
|
|
|
@@ -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
|
|
682
|
-
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 = {
|
|
@@ -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
|
-
|
|
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
|
"""
|
|
@@ -396,7 +396,7 @@ class CustomerEntitledVoucher(CustomerEntitledReward):
|
|
|
396
396
|
|
|
397
397
|
dict_properties = [
|
|
398
398
|
'redeem_code', 'configuration', 'rewarded_datetime', 'transaction_id',
|
|
399
|
-
'status', 'is_reverted', 'is_used', '
|
|
399
|
+
'status', 'is_reverted', 'is_used', 'partner_merchant_acct_key',
|
|
400
400
|
]
|
|
401
401
|
|
|
402
402
|
@property
|
|
@@ -430,6 +430,21 @@ class CustomerEntitledVoucher(CustomerEntitledReward):
|
|
|
430
430
|
|
|
431
431
|
return result
|
|
432
432
|
|
|
433
|
+
@staticmethod
|
|
434
|
+
def list_by_merchant_voucher(merchant_voucher, entitled_datetime_start=None, entitled_datetime_end=None):
|
|
435
|
+
if entitled_datetime_start and entitled_datetime_end:
|
|
436
|
+
result = CustomerEntitledVoucher.query(ndb.AND(
|
|
437
|
+
CustomerEntitledVoucher.entitled_voucher==merchant_voucher.create_ndb_key(),
|
|
438
|
+
CustomerEntitledVoucher.rewarded_datetime>=entitled_datetime_start,
|
|
439
|
+
CustomerEntitledVoucher.rewarded_datetime<entitled_datetime_end,
|
|
440
|
+
)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
441
|
+
else:
|
|
442
|
+
result = CustomerEntitledVoucher.query(ndb.AND(
|
|
443
|
+
CustomerEntitledVoucher.entitled_voucher==merchant_voucher.create_ndb_key(),
|
|
444
|
+
)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
445
|
+
|
|
446
|
+
return result
|
|
447
|
+
|
|
433
448
|
@staticmethod
|
|
434
449
|
def count_redeemed_by_merchant_voucher(customer, merchant_voucher, passed_day_count=1):
|
|
435
450
|
|
|
@@ -506,6 +521,16 @@ class CustomerEntitledVoucher(CustomerEntitledReward):
|
|
|
506
521
|
|
|
507
522
|
return result
|
|
508
523
|
|
|
524
|
+
@staticmethod
|
|
525
|
+
def count_merchant_voucher(merchant_voucher):
|
|
526
|
+
|
|
527
|
+
result = CustomerEntitledVoucher.query(ndb.AND(
|
|
528
|
+
CustomerEntitledVoucher.entitled_voucher==merchant_voucher.create_ndb_key(),
|
|
529
|
+
)).count(limit=conf.MAX_FETCH_RECORD)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
return result
|
|
533
|
+
|
|
509
534
|
def revert_from_redemption(self):
|
|
510
535
|
self.status = program_conf.REDEEM_STATUS_VALID
|
|
511
536
|
self.redeemed_datetime = None
|
|
@@ -19,7 +19,8 @@ from trexmodel.utils.model.model_util import generate_transaction_id
|
|
|
19
19
|
from trexmodel.models.datastore.membership_models import MerchantMembership,\
|
|
20
20
|
MerchantTierMembership
|
|
21
21
|
|
|
22
|
-
logger = logging.getLogger('model')
|
|
22
|
+
#logger = logging.getLogger('model')
|
|
23
|
+
logger = logging.getLogger('target_debug')
|
|
23
24
|
|
|
24
25
|
class SalesTransaction(BaseNModel, DictModel):
|
|
25
26
|
transact_merchant = ndb.KeyProperty(name="transact_merchant", kind=MerchantAcct)
|
|
@@ -93,11 +94,11 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
93
94
|
@property
|
|
94
95
|
def transact_by_user(self):
|
|
95
96
|
if self.transact_by:
|
|
96
|
-
return
|
|
97
|
+
return self.transact_by.get()
|
|
97
98
|
|
|
98
99
|
@property
|
|
99
100
|
def transact_by_user_acct_key(self):
|
|
100
|
-
return self.transact_by.urlsafe()
|
|
101
|
+
return self.transact_by.urlsafe().decode('utf-8')
|
|
101
102
|
|
|
102
103
|
@property
|
|
103
104
|
def after_deduct_tax_sales_amount(self):
|
|
@@ -124,8 +125,9 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
124
125
|
|
|
125
126
|
@staticmethod
|
|
126
127
|
def create(transact_amount=.0, tax_amount=.0, invoice_id=None, remarks=None, system_remarks=None,
|
|
127
|
-
transact_outlet=None, transact_by=None, transact_datetime=None,
|
|
128
|
-
|
|
128
|
+
transact_outlet=None, transact_by=None, transact_datetime=None, transaction_id=None,
|
|
129
|
+
allow_to_revert = True, is_revert=False, reverted_datetime=None, reverted_by=None, reverted_by_username=None,
|
|
130
|
+
sales_channel=None, created_datetime=None,
|
|
129
131
|
):
|
|
130
132
|
|
|
131
133
|
transact_by_username = None
|
|
@@ -134,8 +136,8 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
134
136
|
if isinstance(transact_by, MerchantUser):
|
|
135
137
|
transact_by_username = transact_by.username
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
if transaction_id is None:
|
|
140
|
+
transaction_id = generate_transaction_id()
|
|
139
141
|
|
|
140
142
|
if transact_datetime is None:
|
|
141
143
|
transact_datetime = datetime.utcnow()
|
|
@@ -166,8 +168,16 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
166
168
|
transact_datetime = transact_datetime,
|
|
167
169
|
|
|
168
170
|
is_sales_transaction = True,
|
|
169
|
-
allow_to_revert =
|
|
171
|
+
allow_to_revert = allow_to_revert,
|
|
172
|
+
|
|
173
|
+
is_revert = is_revert,
|
|
174
|
+
reverted_datetime = reverted_datetime,
|
|
175
|
+
reverted_by = reverted_by,
|
|
176
|
+
reverted_by_username = reverted_by_username,
|
|
170
177
|
|
|
178
|
+
sales_channel = sales_channel,
|
|
179
|
+
|
|
180
|
+
created_datetime = created_datetime,
|
|
171
181
|
)
|
|
172
182
|
|
|
173
183
|
customer_transaction.put()
|
|
@@ -175,7 +185,130 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
175
185
|
|
|
176
186
|
return customer_transaction
|
|
177
187
|
|
|
188
|
+
@classmethod
|
|
189
|
+
def list_outlet_transaction(cls, transact_outlet, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
190
|
+
if reverse_order:
|
|
191
|
+
query = cls.query(ndb.AND(cls.transact_outlet==transact_outlet.create_ndb_key())).order(-cls.transact_datetime)
|
|
192
|
+
else:
|
|
193
|
+
query = cls.query(ndb.AND(cls.transact_outlet==transact_outlet.create_ndb_key())).order(cls.transact_datetime)
|
|
194
|
+
|
|
195
|
+
return cls.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
196
|
+
|
|
197
|
+
@classmethod
|
|
198
|
+
def count_outlet_transaction(cls, transact_outlet, limit=conf.MAX_FETCH_RECORD):
|
|
199
|
+
query = cls.query(ndb.AND(cls.transact_outlet==transact_outlet.create_ndb_key()))
|
|
200
|
+
|
|
201
|
+
return cls.count_with_condition_query(query, limit=limit)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@classmethod
|
|
205
|
+
def list_merchant_transaction(cls, transact_merchant, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
206
|
+
if reverse_order:
|
|
207
|
+
query = cls.query(ndb.AND(cls.transact_merchant==transact_merchant.create_ndb_key()))
|
|
208
|
+
else:
|
|
209
|
+
query = cls.query(ndb.AND(cls.transact_merchant==transact_merchant.create_ndb_key()))
|
|
210
|
+
|
|
211
|
+
return cls.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
212
|
+
|
|
213
|
+
@classmethod
|
|
214
|
+
def count_by_merchant(cls, transact_merchant, limit=conf.MAX_FETCH_RECORD):
|
|
215
|
+
query = cls.query(ndb.AND(cls.transact_merchant==transact_merchant.create_ndb_key()))
|
|
216
|
+
|
|
217
|
+
return cls.count_with_condition_query(query, limit)
|
|
218
|
+
|
|
219
|
+
@classmethod
|
|
220
|
+
def list(cls, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
221
|
+
if reverse_order:
|
|
222
|
+
query = cls.query().order(-cls.transact_datetime)
|
|
223
|
+
else:
|
|
224
|
+
query = cls.query().order(cls.transact_datetime)
|
|
225
|
+
|
|
226
|
+
return cls.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
227
|
+
|
|
228
|
+
@classmethod
|
|
229
|
+
def list_transaction_by_date(cls, transact_date, transact_outlet=None, including_reverted_transaction=True, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False):
|
|
230
|
+
|
|
231
|
+
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
232
|
+
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
233
|
+
|
|
234
|
+
logger.debug('transact_datetime=%s',transact_datetime)
|
|
235
|
+
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
236
|
+
logger.debug('including_reverted_transaction=%s',including_reverted_transaction)
|
|
237
|
+
logger.debug('limit=%s',limit)
|
|
238
|
+
|
|
239
|
+
if transact_outlet:
|
|
240
|
+
if including_reverted_transaction:
|
|
241
|
+
query = cls.query(ndb.AND(
|
|
242
|
+
cls.transact_datetime >= transact_datetime,
|
|
243
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
244
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
245
|
+
)).order(-cls.transact_datetime)
|
|
246
|
+
else:
|
|
247
|
+
query = cls.query(ndb.AND(
|
|
248
|
+
cls.transact_datetime >= transact_datetime,
|
|
249
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
250
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
251
|
+
cls.is_revert == False,
|
|
252
|
+
)).order(-cls.transact_datetime)
|
|
253
|
+
else:
|
|
254
|
+
if including_reverted_transaction:
|
|
255
|
+
query = cls.query(ndb.AND(
|
|
256
|
+
cls.transact_datetime >= transact_datetime,
|
|
257
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
258
|
+
)).order(-cls.transact_datetime)
|
|
259
|
+
else:
|
|
260
|
+
query = cls.query(ndb.AND(
|
|
261
|
+
cls.transact_datetime >= transact_datetime,
|
|
262
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
263
|
+
cls.is_revert == False,
|
|
264
|
+
)).order(-cls.transact_datetime)
|
|
265
|
+
|
|
266
|
+
return cls.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
267
|
+
@classmethod
|
|
268
|
+
def count_merchant_transaction(cls, merchant_acct, limit=conf.MAX_FETCH_RECORD):
|
|
269
|
+
query = cls.query(ndb.AND(CustomerTransaction.transact_merchant==merchant_acct.create_ndb_key()))
|
|
270
|
+
|
|
271
|
+
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
272
|
+
|
|
273
|
+
@classmethod
|
|
274
|
+
def count_transaction_by_date(cls, transact_date, including_reverted_transaction=False, transact_outlet=None, limit=conf.MAX_FETCH_RECORD):
|
|
275
|
+
|
|
276
|
+
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
277
|
+
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
178
278
|
|
|
279
|
+
logger.debug('transact_datetime=%s',transact_datetime)
|
|
280
|
+
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
281
|
+
logger.debug('including_reverted_transaction=%s',including_reverted_transaction)
|
|
282
|
+
|
|
283
|
+
if transact_outlet:
|
|
284
|
+
if including_reverted_transaction:
|
|
285
|
+
query = cls.query(ndb.AND(
|
|
286
|
+
cls.transact_datetime >= transact_datetime,
|
|
287
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
288
|
+
cls.transact_outlet == transact_outlet.create_ndb_key()
|
|
289
|
+
))
|
|
290
|
+
else:
|
|
291
|
+
query = cls.query(ndb.AND(
|
|
292
|
+
cls.transact_datetime >= transact_datetime,
|
|
293
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
294
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
295
|
+
cls.is_revert == False,
|
|
296
|
+
))
|
|
297
|
+
else:
|
|
298
|
+
if including_reverted_transaction:
|
|
299
|
+
query = cls.query(ndb.AND(
|
|
300
|
+
cls.transact_datetime >= transact_datetime,
|
|
301
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
302
|
+
))
|
|
303
|
+
else:
|
|
304
|
+
query = cls.query(ndb.AND(
|
|
305
|
+
cls.transact_datetime >= transact_datetime,
|
|
306
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
307
|
+
cls.is_revert == False,
|
|
308
|
+
))
|
|
309
|
+
|
|
310
|
+
return cls.count_with_condition_query(query, limit=limit)
|
|
311
|
+
|
|
179
312
|
|
|
180
313
|
class CustomerTransaction(SalesTransaction):
|
|
181
314
|
'''
|
|
@@ -249,7 +382,8 @@ class CustomerTransaction(SalesTransaction):
|
|
|
249
382
|
|
|
250
383
|
@property
|
|
251
384
|
def transact_customer_acct(self):
|
|
252
|
-
return Customer.fetch(self.key.parent().urlsafe())
|
|
385
|
+
#return Customer.fetch(self.key.parent().urlsafe())
|
|
386
|
+
return self.key.parent().get()
|
|
253
387
|
|
|
254
388
|
@property
|
|
255
389
|
def transact_user_acct(self):
|
|
@@ -266,7 +400,12 @@ class CustomerTransaction(SalesTransaction):
|
|
|
266
400
|
@property
|
|
267
401
|
def transact_outlet_details(self):
|
|
268
402
|
if self.transact_outlet:
|
|
269
|
-
return
|
|
403
|
+
return self.transact_outlet.get()
|
|
404
|
+
|
|
405
|
+
@property
|
|
406
|
+
def transact_by_entity(self):
|
|
407
|
+
if self.transact_by:
|
|
408
|
+
return self.transact_by.get()
|
|
270
409
|
|
|
271
410
|
@property
|
|
272
411
|
def transact_outlet_name(self):
|
|
@@ -388,9 +527,9 @@ class CustomerTransaction(SalesTransaction):
|
|
|
388
527
|
|
|
389
528
|
transact_datetime = sales_transaction.transact_datetime,
|
|
390
529
|
is_from_instant_transaction = True,
|
|
391
|
-
is_rating_review_enabled = is_rating_review_enabled
|
|
530
|
+
is_rating_review_enabled = is_rating_review_enabled,
|
|
392
531
|
#is_sales_transaction = True,
|
|
393
|
-
|
|
532
|
+
allow_to_revert = False,
|
|
394
533
|
#is_membership_purchase = False,
|
|
395
534
|
#is_membership_renew = False,
|
|
396
535
|
#purchased_merchant_membership = False,
|
|
@@ -466,105 +605,7 @@ class CustomerTransaction(SalesTransaction):
|
|
|
466
605
|
#customer.put()
|
|
467
606
|
|
|
468
607
|
return customer_transaction
|
|
469
|
-
|
|
470
|
-
def revert(self, customer_acct, reverted_by):
|
|
471
|
-
transaction_id = self.transaction_id
|
|
472
|
-
|
|
473
|
-
entitled_point_details_list = CustomerPointReward.list_by_transaction_id(transaction_id)
|
|
474
|
-
|
|
475
|
-
entitled_stamp_details_list = CustomerStampReward.list_by_transaction_id(transaction_id)
|
|
476
|
-
|
|
477
|
-
entiteld_vouchers_list = CustomerEntitledVoucher.list_by_transaction_id(transaction_id)
|
|
478
|
-
|
|
479
|
-
entitled_prepaid_list = CustomerPrepaidReward.list_by_transaction_id(transaction_id)
|
|
480
|
-
|
|
481
|
-
is_transaction_reward_used = False
|
|
482
|
-
|
|
483
|
-
customer_reward_summary = customer_acct.reward_summary or {}
|
|
484
|
-
entitled_voucher_summary = customer_acct.entitled_voucher_summary or {}
|
|
485
|
-
|
|
486
|
-
logger.debug('revert: transaction_id=%s', transaction_id)
|
|
487
|
-
logger.debug('revert: entitled_point_details_list count=%s', len(entitled_point_details_list))
|
|
488
|
-
logger.debug('revert: entitled_stamp_details_list count=%s', len(entitled_stamp_details_list))
|
|
489
|
-
logger.debug('revert: entiteld_vouchers_list count=%s', len(entiteld_vouchers_list))
|
|
490
|
-
|
|
491
|
-
for p in entitled_point_details_list:
|
|
492
|
-
if p.is_used:
|
|
493
|
-
is_transaction_reward_used = True
|
|
494
|
-
break
|
|
495
|
-
|
|
496
|
-
if is_transaction_reward_used is False:
|
|
497
|
-
for p in entitled_stamp_details_list:
|
|
498
|
-
if p.is_used:
|
|
499
|
-
is_transaction_reward_used = True
|
|
500
|
-
break
|
|
501
|
-
|
|
502
|
-
if is_transaction_reward_used is False:
|
|
503
|
-
for p in entiteld_vouchers_list:
|
|
504
|
-
if p.is_used:
|
|
505
|
-
is_transaction_reward_used = True
|
|
506
|
-
break
|
|
507
|
-
|
|
508
|
-
logger.debug('revert: is_transaction_reward_used=%s', is_transaction_reward_used)
|
|
509
|
-
|
|
510
|
-
if is_transaction_reward_used is False:
|
|
511
|
-
|
|
512
|
-
logger.debug('Going to revert transqction')
|
|
513
|
-
reverted_by_key = reverted_by.create_ndb_key()
|
|
514
|
-
|
|
515
|
-
reverted_datetime = datetime.now()
|
|
516
|
-
self.is_revert = True
|
|
517
|
-
self.reverted_datetime = reverted_datetime
|
|
518
|
-
self.reverted_by = reverted_by_key
|
|
519
|
-
self.reverted_by_username = reverted_by.username
|
|
520
|
-
self.put()
|
|
521
|
-
|
|
522
|
-
for p in entitled_point_details_list:
|
|
523
|
-
if p.is_valid:
|
|
524
|
-
customer_reward_summary = update_reward_summary_with_reverted_reward(customer_reward_summary, p.to_reward_summary())
|
|
525
|
-
p.status = program_conf.REWARD_STATUS_REVERTED
|
|
526
|
-
p.reverted_datetime = reverted_datetime
|
|
527
|
-
p.reverted_by = reverted_by_key
|
|
528
|
-
p.reverted_by_username = reverted_by.username
|
|
529
|
-
p.put()
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
for p in entitled_stamp_details_list:
|
|
533
|
-
if p.is_valid:
|
|
534
|
-
customer_reward_summary = update_reward_summary_with_reverted_reward(customer_reward_summary, p.to_reward_summary())
|
|
535
|
-
p.status = program_conf.REWARD_STATUS_REVERTED
|
|
536
|
-
p.reverted_datetime = reverted_datetime
|
|
537
|
-
p.reverted_by = reverted_by_key
|
|
538
|
-
p.reverted_by_username = reverted_by.username
|
|
539
|
-
p.put()
|
|
540
|
-
|
|
541
|
-
for p in entiteld_vouchers_list:
|
|
542
|
-
if p.is_valid:
|
|
543
|
-
p.status = program_conf.REWARD_STATUS_REVERTED
|
|
544
|
-
p.reverted_datetime = reverted_datetime
|
|
545
|
-
p.reverted_by = reverted_by_key
|
|
546
|
-
p.reverted_by_username = reverted_by.username
|
|
547
|
-
p.put()
|
|
548
|
-
|
|
549
|
-
entitled_voucher_summary = update_customer_entiteld_voucher_summary_after_reverted_voucher(entitled_voucher_summary, p)
|
|
550
|
-
|
|
551
|
-
updated_voucher_summary = {}
|
|
552
|
-
|
|
553
|
-
logger.debug('revert transaction debug: entitled_voucher_summary=%s', entitled_voucher_summary)
|
|
554
|
-
|
|
555
|
-
for voucher_key, details in entitled_voucher_summary.items():
|
|
556
|
-
if len(details.get('redeem_info_list'))>0:
|
|
557
|
-
updated_voucher_summary[voucher_key] = details
|
|
558
|
-
|
|
559
|
-
customer_acct.reward_summary = customer_reward_summary
|
|
560
|
-
customer_acct.entitled_voucher_summary = updated_voucher_summary or {}
|
|
561
|
-
customer_acct.put()
|
|
562
|
-
|
|
563
|
-
return True
|
|
564
|
-
|
|
565
|
-
else:
|
|
566
|
-
raise Exception('Transaction reward have been used')
|
|
567
|
-
'''
|
|
608
|
+
|
|
568
609
|
@staticmethod
|
|
569
610
|
def list_customer_transaction(customer_acct, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True, keys_only=False):
|
|
570
611
|
if keys_only:
|
|
@@ -583,45 +624,12 @@ class CustomerTransaction(SalesTransaction):
|
|
|
583
624
|
query = CustomerTransaction.query(ancestor = customer_acct.create_ndb_key())
|
|
584
625
|
CustomerTransaction.delete_multiples(query)
|
|
585
626
|
|
|
586
|
-
@staticmethod
|
|
587
|
-
def list(offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
588
|
-
if reverse_order:
|
|
589
|
-
query = CustomerTransaction.query().order(-CustomerTransaction.transact_datetime)
|
|
590
|
-
else:
|
|
591
|
-
query = CustomerTransaction.query().order(CustomerTransaction.transact_datetime)
|
|
592
|
-
|
|
593
|
-
return CustomerTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
594
|
-
|
|
595
|
-
@staticmethod
|
|
596
|
-
def list_outlet_transaction(transact_outlet, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
597
|
-
if reverse_order:
|
|
598
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_outlet==transact_outlet.create_ndb_key())).order(-CustomerTransaction.transact_datetime)
|
|
599
|
-
else:
|
|
600
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_outlet==transact_outlet.create_ndb_key())).order(CustomerTransaction.transact_datetime)
|
|
601
|
-
|
|
602
|
-
return CustomerTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
603
|
-
|
|
604
|
-
@staticmethod
|
|
605
|
-
def list_merchant_transaction(transact_merchant, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
606
|
-
if reverse_order:
|
|
607
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_merchant==transact_merchant.create_ndb_key()))
|
|
608
|
-
else:
|
|
609
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_merchant==transact_merchant.create_ndb_key()))
|
|
610
|
-
|
|
611
|
-
return CustomerTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
612
|
-
|
|
613
627
|
@staticmethod
|
|
614
628
|
def count_valid_customer_transaction(customer_acct, limit=conf.MAX_FETCH_RECORD):
|
|
615
629
|
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.is_revert==False), ancestor = customer_acct.create_ndb_key())
|
|
616
630
|
|
|
617
631
|
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
618
632
|
|
|
619
|
-
@staticmethod
|
|
620
|
-
def count_outlet_transaction(transact_outlet, limit=conf.MAX_FETCH_RECORD):
|
|
621
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_outlet==transact_outlet.create_ndb_key()))
|
|
622
|
-
|
|
623
|
-
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
624
|
-
|
|
625
633
|
@staticmethod
|
|
626
634
|
def list_valid_customer_transaction(customer_acct, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False):
|
|
627
635
|
|
|
@@ -653,43 +661,7 @@ class CustomerTransaction(SalesTransaction):
|
|
|
653
661
|
def get_by_transaction_id(transaction_id):
|
|
654
662
|
return CustomerTransaction.query(CustomerTransaction.transaction_id==transaction_id).get()
|
|
655
663
|
|
|
656
|
-
|
|
657
|
-
def list_transaction_by_date(transact_date, transact_outlet=None, including_reverted_transaction=True, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False):
|
|
658
|
-
|
|
659
|
-
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
660
|
-
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
661
|
-
|
|
662
|
-
logger.debug('transact_datetime=%s',transact_datetime)
|
|
663
|
-
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
664
|
-
|
|
665
|
-
if transact_outlet:
|
|
666
|
-
if including_reverted_transaction:
|
|
667
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
668
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
669
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
670
|
-
CustomerTransaction.transact_outlet == transact_outlet.create_ndb_key(),
|
|
671
|
-
)).order(-CustomerTransaction.transact_datetime)
|
|
672
|
-
else:
|
|
673
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
674
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
675
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
676
|
-
CustomerTransaction.transact_outlet == transact_outlet.create_ndb_key(),
|
|
677
|
-
CustomerTransaction.is_revert == False,
|
|
678
|
-
)).order(-CustomerTransaction.transact_datetime)
|
|
679
|
-
else:
|
|
680
|
-
if including_reverted_transaction:
|
|
681
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
682
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
683
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
684
|
-
)).order(-CustomerTransaction.transact_datetime)
|
|
685
|
-
else:
|
|
686
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
687
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
688
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
689
|
-
CustomerTransaction.is_revert == False,
|
|
690
|
-
)).order(-CustomerTransaction.transact_datetime)
|
|
691
|
-
|
|
692
|
-
return CustomerTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
664
|
+
|
|
693
665
|
|
|
694
666
|
@staticmethod
|
|
695
667
|
def list_all(offset=0, limit=conf.MAX_FETCH_RECORD):
|
|
@@ -704,49 +676,7 @@ class CustomerTransaction(SalesTransaction):
|
|
|
704
676
|
|
|
705
677
|
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
706
678
|
|
|
707
|
-
@staticmethod
|
|
708
|
-
def count_merchant_transaction(merchant_acct, limit=conf.MAX_FETCH_RECORD):
|
|
709
|
-
query = CustomerTransaction.query(ndb.AND(CustomerTransaction.transact_merchant==merchant_acct.create_ndb_key()))
|
|
710
|
-
|
|
711
|
-
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
712
679
|
|
|
713
|
-
@staticmethod
|
|
714
|
-
def count_transaction_by_date(transact_date, including_reverted_transaction=True, transact_outlet=None, limit=conf.MAX_FETCH_RECORD):
|
|
715
|
-
|
|
716
|
-
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
717
|
-
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
718
|
-
|
|
719
|
-
logger.debug('transact_datetime=%s',transact_datetime)
|
|
720
|
-
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
721
|
-
|
|
722
|
-
if transact_outlet:
|
|
723
|
-
if including_reverted_transaction:
|
|
724
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
725
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
726
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
727
|
-
CustomerTransaction.transact_outlet == transact_outlet.create_ndb_key()
|
|
728
|
-
))
|
|
729
|
-
else:
|
|
730
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
731
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
732
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
733
|
-
CustomerTransaction.transact_outlet == transact_outlet.create_ndb_key(),
|
|
734
|
-
CustomerTransaction.is_revert == False,
|
|
735
|
-
))
|
|
736
|
-
else:
|
|
737
|
-
if including_reverted_transaction:
|
|
738
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
739
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
740
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
741
|
-
))
|
|
742
|
-
else:
|
|
743
|
-
query = CustomerTransaction.query(ndb.AND(
|
|
744
|
-
CustomerTransaction.transact_datetime >= transact_datetime,
|
|
745
|
-
CustomerTransaction.transact_datetime < next_day_transact_datetime,
|
|
746
|
-
CustomerTransaction.is_revert == False,
|
|
747
|
-
))
|
|
748
|
-
|
|
749
|
-
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
750
680
|
|
|
751
681
|
|
|
752
682
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/helper/reward_model_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/merchant_promotion_models.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/redemption_catalogue_models.py
RENAMED
|
File without changes
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.5}/trexmodel/models/datastore/spending_base_program_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|