summaryrefslogtreecommitdiff
path: root/fixco_custom/models/webhook_ginee.py
blob: fb1bbf69c676be442fb2c126ebd65442f4cc446c (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
37
38
39
40
41
42
43
44
45
from odoo import api, fields, models, _
from odoo.exceptions import UserError
import time
import requests
import json
import hmac
import base64
from hashlib import sha256

class WebhookGinee(models.Model):
    _name = "webhook.ginee"
    _inherit = ['mail.thread']

    json_ginee = fields.Text()
    execute_status = fields.Selection([
        ('success', 'Success'),
        ('failed', 'Failed'),
        ('done', 'Done'),
        ('not_found', 'Record not found')
    ], 'Execute Status')

    def process_queue_item(self, limit=100, max_exec_time=30):
        domain = [('execute_status', '=', False), ('json_ginee', 'not ilike', 'BLIBLI_ID')]
        records = self.search(domain, order='create_date asc', limit=limit)
        start_time = time.time()
        for rec in records:
            end_time = time.time()
            elapsed_time = end_time - start_time
            if elapsed_time > max_exec_time:
                break
            rec.execute_queue()

    # def process_queue_item(self, limit=100):
    #     domain = [('create_date', '>', '2025-12-31 23:59:59')]
    #     records = self.search(domain, order='create_date asc', limit=limit)
    #     for rec in records:
    #         rec.execute_queue()


    def execute_queue(self):
        detail_order = self.env['detail.order'].create({
            'json_ginee': self.json_ginee,
            'source': 'webhook'
            })
        self.execute_status = 'success'