diff --git a/__manifest__.py b/__manifest__.py index 84eb634b9f5890cd86bead5ec74a753d0cd60b50..4978c108800ee81c9de9f74b36045fb491092786 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -11,6 +11,7 @@ "security/ir.model.access.csv", # datas "data/cron_import_data_wts.xml", + "data/queue_data.xml", # views "views/hall.xml", "views/hall_flow.xml", diff --git a/data/queue_data.xml b/data/queue_data.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d03a6f8e64986835d2b420e6fa6df2508cb8b0c --- /dev/null +++ b/data/queue_data.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="channel_wts" model="queue.job.channel"> + <field name="name">wts_channel</field> + <field name="parent_id" ref="queue_job.channel_root" /> + </record> + + <record id="job_function_wts_create_visitor" model="queue.job.function"> + <field name="model_id" ref="hall_flow_whattheshop.model_hall_flow_zone" /> + <field name="method">_wts_create_visitor</field> + <field name="channel_id" ref="channel_wts" /> + <field name="retry_pattern" eval="{1: 10, 5: 20, 10: 60,}" /> + </record> + <record id="job_function_wts_wts_create_passerby" model="queue.job.function"> + <field name="model_id" ref="hall_flow_whattheshop.model_hall_flow_zone" /> + <field name="method">_wts_create_passerby</field> + <field name="channel_id" ref="channel_wts" /> + <field name="retry_pattern" eval="{1: 10, 5: 20, 10: 60,}" /> + </record> + <record id="job_function_wts_create_inout" model="queue.job.function"> + <field name="model_id" ref="hall_flow_whattheshop.model_hall_flow_sensor" /> + <field name="method">_wts_create_inout</field> + <field name="channel_id" ref="channel_wts" /> + <field name="retry_pattern" eval="{1: 10, 5: 20, 10: 60,}" /> + </record> +</odoo> diff --git a/models/hall_flow_log.py b/models/hall_flow_log.py index b3ad3dd54b1fd5f3f4e1e0d7a946474e33a4789a..755ac53b0f5bfe7a71c39c80d03d74f32658ad3a 100644 --- a/models/hall_flow_log.py +++ b/models/hall_flow_log.py @@ -71,18 +71,18 @@ class HallFlowLog(models.Model): if delta_days > 0: start_passerby = start_date for day in range(0, delta_days): - zone.with_delay(description=pass_desc)._wts_create_passerby( + zone.with_delay(description=pass_desc, max_retries=10)._wts_create_passerby( start_passerby, end_date, log_id ) start_passerby = start_passerby + relativedelta(days=1, hours=1) else: - zone.with_delay(description=pass_desc)._wts_create_passerby( + zone.with_delay(description=pass_desc, max_retries=10)._wts_create_passerby( start_date, end_date, log_id ) # Retrieve In/Out datas for sensor in zone.sensor_ids.filtered(lambda s: s.sensor_type == "sensor"): description = log_id.hall_id.name + " - " + sensor.name - sensor.with_delay(description=description)._wts_create_inout( + sensor.with_delay(description=description, max_retries=10)._wts_create_inout( start_date, end_date, log_id ) diff --git a/models/hall_flow_sensor.py b/models/hall_flow_sensor.py index 5b5f3e45ec23dcec416ec7727b57ee4c52873991..6a86e5ac004d49e676adc63270dd271ab226d779 100644 --- a/models/hall_flow_sensor.py +++ b/models/hall_flow_sensor.py @@ -7,9 +7,9 @@ from odoo import fields, models from odoo.addons.api_connector.tools.date_utils import local_to_utc -class HallFlowZone(models.Model): +class HallFlowSensor(models.Model): _name = "hall.flow.sensor" - _description = "Hall Zone Management" + _description = "Hall Sensor Management" # ------------------------------------------------------ # Fields declaration diff --git a/models/hall_flow_zone.py b/models/hall_flow_zone.py index 506b549eb49c702f17a77b6faffd702494da27c2..d39faf939a08e8364840edf48ee69907681a6900 100644 --- a/models/hall_flow_zone.py +++ b/models/hall_flow_zone.py @@ -5,6 +5,7 @@ from datetime import datetime from odoo import fields, models from odoo.addons.api_connector.tools.date_utils import local_to_utc +from odoo.addons.queue_job.exception import FailedJobError class HallFlowZone(models.Model): @@ -100,27 +101,30 @@ class HallFlowZone(models.Model): flow_ids = self.env["hall.flow"] backend_id = log_id.hall_id.backend_id for zone in self: - visitor_datas = backend_id._get_wifi_datas( - url="/visitor/counthourdetails", - zone_ids=zone.mapped("wts_id"), - start_date=start_date, - end_date=end_date, - opening_time=opening_time, - ) - if visitor_datas: - for date, data in visitor_datas.items(): - flow_ids += flow_ids.sudo().create( - { - "date": local_to_utc( - datetime.strptime(date, "%Y-%m-%d %H:%M:%S"), zone.timezone - ), - "flow_type": "visitor", - "count": data, - "log_id": log_id.id, - "hall_id": log_id.hall_id.id, - "zone_id": zone.id, - } - ) + try: + visitor_datas = backend_id._get_wifi_datas( + url="/visitor/counthourdetails", + zone_ids=zone.mapped("wts_id"), + start_date=start_date, + end_date=end_date, + opening_time=opening_time, + ) + if visitor_datas: + for date, data in visitor_datas.items(): + flow_ids += flow_ids.sudo().create( + { + "date": local_to_utc( + datetime.strptime(date, "%Y-%m-%d %H:%M:%S"), zone.timezone + ), + "flow_type": "visitor", + "count": data, + "log_id": log_id.id, + "hall_id": log_id.hall_id.id, + "zone_id": zone.id, + } + ) + except Exception as e: + raise FailedJobError(e.__str__()) return flow_ids