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'