From aed1817bac8a608bfd630acc8d5d406f13732387 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 26 Jan 2023 10:34:05 +0700 Subject: add rest coupon program --- indoteknik_api/models/coupon_program.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 indoteknik_api/models/coupon_program.py (limited to 'indoteknik_api/models/coupon_program.py') 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 -- cgit v1.2.3