summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/coupon_program.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-26 10:34:05 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-26 10:34:05 +0700
commitaed1817bac8a608bfd630acc8d5d406f13732387 (patch)
tree7488b0f1352ca8b276871db446c6673cf0626ed3 /indoteknik_api/models/coupon_program.py
parent9df53ac2b48ee5f6285715f642b341dff93ad295 (diff)
add rest coupon program
Diffstat (limited to 'indoteknik_api/models/coupon_program.py')
-rw-r--r--indoteknik_api/models/coupon_program.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/indoteknik_api/models/coupon_program.py b/indoteknik_api/models/coupon_program.py
new file mode 100644
index 00000000..7ca003cd
--- /dev/null
+++ b/indoteknik_api/models/coupon_program.py
@@ -0,0 +1,36 @@
+from odoo import models
+import datetime
+from pytz import timezone
+
+
+class CouponProgram(models.Model):
+ _inherit = 'coupon.program'
+
+ def api_single_response(self, coupon):
+ # print (coupon.display_name)
+ data = {
+ 'active': coupon.active,
+ 'discount_percentage': coupon.discount_percentage,
+ 'display_name': coupon.display_name,
+ 'id': coupon.id,
+ 'reward_type': coupon.reward_type,
+ 'reward_id': coupon.reward_id.id,
+ 'reward_product_id': coupon.reward_product_id.id,
+ 'reward_product_quantity': coupon.reward_product_quantity,
+ 'rule_date_from': self.time_to_str(coupon.rule_date_from, '%d/%m/%Y %H:%M:%S'),
+ 'rule_date_to': self.time_to_str(coupon.rule_date_to, '%d/%m/%Y %H:%M:%S'),
+ 'rule_id': coupon.rule_id.id,
+ 'rule_products_domain': coupon.rule_products_domain,
+ 'icon_program_promo': self.env['ir.attachment'].api_image('coupon.program', 'x_studio_field_Ifopn', coupon.id),
+ 'icon_program_promo2': self.env['ir.attachment'].api_image('coupon.program', 'x_studio_field_2Ul77', coupon.id),
+ 'discount_line_product_id': coupon.discount_line_product_id.id,
+ 'image_promo': self.env['ir.attachment'].api_image('coupon.program', 'x_studio_image_promo', coupon.id),
+ 'image_banner_promo': self.env['ir.attachment'].api_image('coupon.program', 'x_studio_banner_promo', coupon.id),
+ }
+ return data
+
+ def time_to_str(self, object, format):
+ time = ''
+ if isinstance(object, datetime.datetime):
+ time = object.astimezone(timezone('Asia/Jakarta')).strftime(format)
+ return time