Skip to content

Commit

Permalink
[IMP] connector_pms_wubook: cron every less than a minute for availab…
Browse files Browse the repository at this point in the history
…ility and enable plan and pricelist cron every minute
  • Loading branch information
eantones committed Jul 25, 2021
1 parent f664c49 commit 42ac139
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions connector_pms_wubook/data/cron.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="active" eval="False" />
<field name="interval_number">1</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_type">days</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="state">code</field>
Expand All @@ -15,7 +15,7 @@
name="nextcall"
eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 09:00:00')"
/>
<field name="code">model._scheduler_export()</field>
<field name="code">model._scheduler_export(interval=1, count=10)</field>
</record>
</data>
</odoo>
43 changes: 28 additions & 15 deletions connector_pms_wubook/models/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ def import_pricelists(self):
rec.pricelist_room_type_ids,
)

def export_pricelists(self):
def export_pricelists(self, *args, **kwargs):
if self.user_id:
self = self.with_user(self.user_id)
for rec in self:
rec.env["channel.wubook.product.pricelist"].with_delay().export_data(
backend_record=rec
)
rec.env["channel.wubook.product.pricelist"].with_delay(
*args, **kwargs
).export_data(backend_record=rec)

# availability plan
plan_date_from = fields.Date("Availability Plan Date From")
Expand Down Expand Up @@ -168,13 +168,13 @@ def import_availability_plans(self):
rec.plan_room_type_ids,
)

def export_availability_plans(self):
def export_availability_plans(self, *args, **kwargs):
if self.user_id:
self = self.with_user(self.user_id)
for rec in self:
rec.env["channel.wubook.pms.availability.plan"].with_delay().export_data(
backend_record=rec
)
rec.env["channel.wubook.pms.availability.plan"].with_delay(
*args, **kwargs
).export_data(backend_record=rec)

# availability
avail_date_from = fields.Date("Availability Date From")
Expand All @@ -201,13 +201,13 @@ def export_availability(self):
)

# property availability
def export_property_availability(self):
def export_property_availability(self, *args, **kwargs):
if self.user_id:
self = self.with_user(self.user_id)
for rec in self:
rec.env[
"channel.wubook.pms.property.availability"
].with_delay().export_data(backend_record=rec)
rec.env["channel.wubook.pms.property.availability"].with_delay(
*args, **kwargs
).export_data(backend_record=rec)

# folio
folio_date_arrival_from = fields.Date(string="Arrival Date From")
Expand Down Expand Up @@ -235,11 +235,24 @@ def import_folios(self):

# scheduler
@api.model
def _scheduler_export(self):
def _scheduler_export(self, interval=1, count=1):
"""
:param interval: minutes
:param count: number of executions for every interval
Examples: interval=1 and num=12 -> execute 12 times every minute
interval=60 and num=6 -> execute 6 times every hour
IF this is called using Odoo Cron job, the interval must be
the same as the interval execution defined in job
"""
interval_sec = interval * 60
now = fields.Datetime.now()
for backend in self.env["channel.wubook.backend"].search([]):
if backend.user_id:
backend = self.with_user(self.user_id)

backend.export_property_availability()
for i in range(0, interval_sec, int(interval_sec / count)):
eta = fields.Datetime.add(now, seconds=i)
backend.export_property_availability(eta=eta)
backend.export_availability_plans()
backend.export_pricelists()

0 comments on commit 42ac139

Please sign in to comment.