trex-model 1.6.3__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.
- {trex_model-1.6.3 → trex_model-1.6.4}/PKG-INFO +1 -1
- {trex_model-1.6.3 → trex_model-1.6.4}/setup.py +1 -1
- {trex_model-1.6.3 → trex_model-1.6.4}/trex_model.egg-info/PKG-INFO +1 -1
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/helper/reward_transaction_helper.py +48 -13
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/lucky_draw_models.py +16 -3
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/ndb_models.py +2 -2
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/reward_models.py +26 -1
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/transaction_models.py +134 -89
- {trex_model-1.6.3 → trex_model-1.6.4}/LICENSE +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/MANIFEST.in +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/README.md +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/setup.cfg +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trex_model.egg-info/SOURCES.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trex_model.egg-info/dependency_links.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trex_model.egg-info/requires.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trex_model.egg-info/top_level.txt +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/admin_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/analytic_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/app_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/coporate_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/customer_model_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/customer_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/fb_subsriber_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/helper/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/helper/reward_model_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/import_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/inventory_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/loyalty_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/marketing_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/membership_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/merchant_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/merchant_promotion_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/message_model_helper.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/message_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/model_decorators.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/partnership_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/pos_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/prepaid_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/product_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/program_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/rating_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/recruit_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/redeem_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/redemption_catalogue_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/referral_program_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/spending_base_program_model.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/system_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/task_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/test_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/user_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/datastore/voucher_models.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/merchant_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/model_decorator.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/models/prepaid_helpers.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/pos_conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/program_conf.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/utils/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/utils/gcloud/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/utils/gcloud/datastore_util.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/utils/model/__init__.py +0 -0
- {trex_model-1.6.3 → trex_model-1.6.4}/trexmodel/utils/model/model_util.py +0 -0
{trex_model-1.6.3 → trex_model-1.6.4}/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
|
|
|
@@ -156,11 +156,11 @@ def create_sales_transaction(transact_outlet=None, sales_amount=.0, tax_amount=.
|
|
|
156
156
|
|
|
157
157
|
)
|
|
158
158
|
|
|
159
|
-
|
|
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
|
|
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,
|
|
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,
|
|
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
|
|
395
|
-
total_accumulated_point = customer_kpi_summary
|
|
396
|
-
total_accumulated_stamp = customer_kpi_summary
|
|
397
|
-
total_accumulated_prepaid = customer_kpi_summary
|
|
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,
|
|
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:
|
|
@@ -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,
|
|
177
|
+
|
|
178
|
+
sales_channel = sales_channel,
|
|
170
179
|
|
|
180
|
+
created_datetime = created_datetime,
|
|
171
181
|
)
|
|
172
182
|
|
|
173
183
|
customer_transaction.put()
|
|
@@ -175,7 +185,114 @@ class SalesTransaction(BaseNModel, DictModel):
|
|
|
175
185
|
|
|
176
186
|
return customer_transaction
|
|
177
187
|
|
|
188
|
+
@staticmethod
|
|
189
|
+
def list_merchant_transaction(transact_merchant, offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
190
|
+
if reverse_order:
|
|
191
|
+
query = SalesTransaction.query(ndb.AND(SalesTransaction.transact_merchant==transact_merchant.create_ndb_key()))
|
|
192
|
+
else:
|
|
193
|
+
query = SalesTransaction.query(ndb.AND(SalesTransaction.transact_merchant==transact_merchant.create_ndb_key()))
|
|
194
|
+
|
|
195
|
+
return SalesTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
196
|
+
|
|
197
|
+
@staticmethod
|
|
198
|
+
def count_by_merchant(transact_merchant, limit=conf.MAX_FETCH_RECORD):
|
|
199
|
+
query = SalesTransaction.query(ndb.AND(SalesTransaction.transact_merchant==transact_merchant.create_ndb_key()))
|
|
200
|
+
|
|
201
|
+
return SalesTransaction.count_with_condition_query(query, limit)
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def list(offset=0, limit=conf.PAGINATION_SIZE, start_cursor=None, return_with_cursor=False, reverse_order=True):
|
|
205
|
+
if reverse_order:
|
|
206
|
+
query = SalesTransaction.query().order(-SalesTransaction.transact_datetime)
|
|
207
|
+
else:
|
|
208
|
+
query = SalesTransaction.query().order(SalesTransaction.transact_datetime)
|
|
209
|
+
|
|
210
|
+
return SalesTransaction.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
211
|
+
|
|
212
|
+
@classmethod
|
|
213
|
+
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):
|
|
214
|
+
|
|
215
|
+
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
216
|
+
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
217
|
+
|
|
218
|
+
logger.debug('transact_datetime=%s',transact_datetime)
|
|
219
|
+
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
220
|
+
logger.debug('including_reverted_transaction=%s',including_reverted_transaction)
|
|
221
|
+
logger.debug('limit=%s',limit)
|
|
222
|
+
|
|
223
|
+
if transact_outlet:
|
|
224
|
+
if including_reverted_transaction:
|
|
225
|
+
query = cls.query(ndb.AND(
|
|
226
|
+
cls.transact_datetime >= transact_datetime,
|
|
227
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
228
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
229
|
+
)).order(-cls.transact_datetime)
|
|
230
|
+
else:
|
|
231
|
+
query = cls.query(ndb.AND(
|
|
232
|
+
cls.transact_datetime >= transact_datetime,
|
|
233
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
234
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
235
|
+
cls.is_revert == False,
|
|
236
|
+
)).order(-cls.transact_datetime)
|
|
237
|
+
else:
|
|
238
|
+
if including_reverted_transaction:
|
|
239
|
+
query = cls.query(ndb.AND(
|
|
240
|
+
cls.transact_datetime >= transact_datetime,
|
|
241
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
242
|
+
)).order(-cls.transact_datetime)
|
|
243
|
+
else:
|
|
244
|
+
query = cls.query(ndb.AND(
|
|
245
|
+
cls.transact_datetime >= transact_datetime,
|
|
246
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
247
|
+
cls.is_revert == False,
|
|
248
|
+
)).order(-cls.transact_datetime)
|
|
249
|
+
|
|
250
|
+
return cls.list_all_with_condition_query(query, offset=offset, limit=limit, start_cursor=start_cursor, return_with_cursor=return_with_cursor)
|
|
251
|
+
@classmethod
|
|
252
|
+
def count_merchant_transaction(cls, merchant_acct, limit=conf.MAX_FETCH_RECORD):
|
|
253
|
+
query = cls.query(ndb.AND(CustomerTransaction.transact_merchant==merchant_acct.create_ndb_key()))
|
|
254
|
+
|
|
255
|
+
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
256
|
+
|
|
257
|
+
@classmethod
|
|
258
|
+
def count_transaction_by_date(cls, transact_date, including_reverted_transaction=False, transact_outlet=None, limit=conf.MAX_FETCH_RECORD):
|
|
259
|
+
|
|
260
|
+
transact_datetime = datetime.combine(transact_date, datetime.min.time())
|
|
261
|
+
next_day_transact_datetime = transact_datetime + timedelta(days=1)
|
|
262
|
+
|
|
263
|
+
logger.debug('transact_datetime=%s',transact_datetime)
|
|
264
|
+
logger.debug('next_day_transact_datetime=%s',next_day_transact_datetime)
|
|
265
|
+
logger.debug('including_reverted_transaction=%s',including_reverted_transaction)
|
|
266
|
+
|
|
267
|
+
if transact_outlet:
|
|
268
|
+
if including_reverted_transaction:
|
|
269
|
+
query = cls.query(ndb.AND(
|
|
270
|
+
cls.transact_datetime >= transact_datetime,
|
|
271
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
272
|
+
cls.transact_outlet == transact_outlet.create_ndb_key()
|
|
273
|
+
))
|
|
274
|
+
else:
|
|
275
|
+
query = cls.query(ndb.AND(
|
|
276
|
+
cls.transact_datetime >= transact_datetime,
|
|
277
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
278
|
+
cls.transact_outlet == transact_outlet.create_ndb_key(),
|
|
279
|
+
cls.is_revert == False,
|
|
280
|
+
))
|
|
281
|
+
else:
|
|
282
|
+
if including_reverted_transaction:
|
|
283
|
+
query = cls.query(ndb.AND(
|
|
284
|
+
cls.transact_datetime >= transact_datetime,
|
|
285
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
286
|
+
))
|
|
287
|
+
else:
|
|
288
|
+
query = cls.query(ndb.AND(
|
|
289
|
+
cls.transact_datetime >= transact_datetime,
|
|
290
|
+
cls.transact_datetime < next_day_transact_datetime,
|
|
291
|
+
cls.is_revert == False,
|
|
292
|
+
))
|
|
178
293
|
|
|
294
|
+
return cls.count_with_condition_query(query, limit=limit)
|
|
295
|
+
|
|
179
296
|
|
|
180
297
|
class CustomerTransaction(SalesTransaction):
|
|
181
298
|
'''
|
|
@@ -249,7 +366,8 @@ class CustomerTransaction(SalesTransaction):
|
|
|
249
366
|
|
|
250
367
|
@property
|
|
251
368
|
def transact_customer_acct(self):
|
|
252
|
-
return Customer.fetch(self.key.parent().urlsafe())
|
|
369
|
+
#return Customer.fetch(self.key.parent().urlsafe())
|
|
370
|
+
return self.key.parent().get()
|
|
253
371
|
|
|
254
372
|
@property
|
|
255
373
|
def transact_user_acct(self):
|
|
@@ -266,7 +384,12 @@ class CustomerTransaction(SalesTransaction):
|
|
|
266
384
|
@property
|
|
267
385
|
def transact_outlet_details(self):
|
|
268
386
|
if self.transact_outlet:
|
|
269
|
-
return
|
|
387
|
+
return self.transact_outlet.get()
|
|
388
|
+
|
|
389
|
+
@property
|
|
390
|
+
def transact_by_entity(self):
|
|
391
|
+
if self.transact_by:
|
|
392
|
+
return self.transact_by.get()
|
|
270
393
|
|
|
271
394
|
@property
|
|
272
395
|
def transact_outlet_name(self):
|
|
@@ -653,43 +776,7 @@ class CustomerTransaction(SalesTransaction):
|
|
|
653
776
|
def get_by_transaction_id(transaction_id):
|
|
654
777
|
return CustomerTransaction.query(CustomerTransaction.transaction_id==transaction_id).get()
|
|
655
778
|
|
|
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)
|
|
779
|
+
|
|
693
780
|
|
|
694
781
|
@staticmethod
|
|
695
782
|
def list_all(offset=0, limit=conf.MAX_FETCH_RECORD):
|
|
@@ -704,49 +791,7 @@ class CustomerTransaction(SalesTransaction):
|
|
|
704
791
|
|
|
705
792
|
return CustomerTransaction.count_with_condition_query(query, limit=limit)
|
|
706
793
|
|
|
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
794
|
|
|
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
795
|
|
|
751
796
|
|
|
752
797
|
|
|
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
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.4}/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.4}/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.4}/trexmodel/models/datastore/redemption_catalogue_models.py
RENAMED
|
File without changes
|
|
File without changes
|
{trex_model-1.6.3 → trex_model-1.6.4}/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
|