diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-12 08:56:19 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-12 08:56:19 +0700 |
| commit | 7753f4b1ebf4514863c05d3a92d8c4496d9b344a (patch) | |
| tree | f5315bd826994cc32f1d0f7067f6d535c0b0b18a | |
| parent | 94224e3174bf1370ae8e4ced3271d78beba83cfb (diff) | |
Update voucher time text
| -rw-r--r-- | indoteknik_custom/models/voucher.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index 23285b3a..00192cec 100644 --- a/indoteknik_custom/models/voucher.py +++ b/indoteknik_custom/models/voucher.py @@ -1,5 +1,5 @@ from odoo import models, fields -from datetime import datetime +from datetime import datetime, timedelta class Voucher(models.Model): @@ -52,13 +52,28 @@ class Voucher(models.Model): 'description': self.description, 'discount_amount': self.discount_amount, 'discount_type': discount_type, - 'start_time': self.start_time.strftime('%d-%m-%Y'), - 'end_time': self.end_time.strftime('%d-%m-%Y'), + 'remaining_time': self._res_remaining_time(), 'min_purchase_amount': self.min_purchase_amount, 'max_discount_amount': max_discount_amount, } return data + def _res_remaining_time(self): + seconds = self._get_remaining_time() + remaining_time = timedelta(seconds=seconds) + hours = remaining_time.seconds // 3600 + minutes = remaining_time.seconds // 60 + if remaining_time.days > 0: + time = remaining_time.days + unit = 'hari' + elif hours > 0: + time = hours + unit = 'jam' + else: + time = minutes + unit = 'menit' + return f'{time} {unit}' + def _get_remaining_time(self): calculate_time = self.end_time - datetime.now() return round(calculate_time.total_seconds()) |
