summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/coupon_program.py
blob: 7ca003cdf6967acea952869915ad2473e3dc655d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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