Skip to content

Commit

Permalink
[IMP]connector_pms_wubook: generic export cron
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Jan 5, 2022
1 parent 0576a14 commit 12e71ef
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
10 changes: 10 additions & 0 deletions connector_pms_wubook/data/queue_job_function_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,14 @@
<field name="retry_pattern" eval="{1: 10, 5: 30, 10: 60, 15: 300}" />
</record>

<record id="wubook_pms_generic_export_data_job_function" model="queue.job.function">
<field
name="model_id"
ref="connector_pms_wubook.model_channel_wubook_backend"
/>
<field name="method">generic_export</field>
<field name="channel_id" ref="connector_pms_wubook.channel_wubook" />
<field name="retry_pattern" eval="{1: 10, 5: 30, 10: 60, 15: 300}" />
</record>

</odoo>
58 changes: 50 additions & 8 deletions connector_pms_wubook/models/common/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,53 @@ def _scheduler_export(self, interval=1, count=1):
"""
interval_sec = interval * 60
now = fields.Datetime.now()
for backend in self.env["channel.wubook.backend"].search([]):
if backend.user_id:
backend = backend.with_user(self.user_id)
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()
for i in range(0, interval_sec, int(interval_sec / count)):
eta = fields.Datetime.add(now, seconds=i)
self.with_delay(
eta=eta,
).generic_export()

def generic_export(self):
models_to_export = (
self._get_models_to_export_multi() + self._get_models_to_export_one()
)
for model in models_to_export:
records_to_export = self.env[model].search(
[
("synced_export", "=", False),
]
)
if self.user_id:
self = self.with_user(self.user_id)
backends = self.env["channel.wubook.backend"].browse(
records_to_export.backend_id.ids
)
for backend in backends:
# If the model has several records in the same backend,
# we indicate as parameter the records to export
if model in self._get_models_to_export_multi():
self.env[model].with_company(
backend.pms_property_id.company_id
).with_delay().export_data(
backend_record=backend,
record_ids=records_to_export.filtered(
lambda r: r.backend_id.id == backend.id
).ids,
)
else:
self.env[model].with_company(
backend.pms_property_id.company_id
).with_delay().export_data(
backend_record=backend,
)

def _get_models_to_export_multi(self):
return [
"channel.wubook.product.pricelist",
"channel.wubook.pms.availability.plan",
]

def _get_models_to_export_one(self):
return [
"channel.wubook.pms.property.availability",
]
17 changes: 10 additions & 7 deletions connector_pms_wubook/models/pms_availability_plan/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,19 @@ def import_data(
)

@api.model
def export_data(self, backend_record=None):
def export_data(self, backend_record=None, record_ids=False):
""" Prepare the batch export of Availability Plan to Channel """
domain = [
("channel_wubook_bind_ids.backend_id", "in", backend_record.ids),
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", backend_record.pms_property_id.ids),
]
if record_ids:
domain.append(("id", "in", record_ids))
return self.export_batch(
backend_record=backend_record,
domain=[
("channel_wubook_bind_ids.backend_id", "in", backend_record.ids),
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", backend_record.pms_property_id.ids),
],
domain=domain,
)

def resync_import(self):
Expand Down
18 changes: 11 additions & 7 deletions connector_pms_wubook/models/product_pricelist/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,20 @@ def import_data(
)

@api.model
def export_data(self, backend_record=None):
def export_data(self, backend_record=None, record_ids=False):
""" Prepare the batch export of Pricelist to Channel """
domain = [
("channel_wubook_bind_ids.backend_id", "in", backend_record.ids),
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", backend_record.pms_property_id.ids),
]
if record_ids:
domain.append(("id", "in", record_ids))

return self.export_batch(
backend_record=backend_record,
domain=[
("channel_wubook_bind_ids.backend_id", "in", backend_record.ids),
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", backend_record.pms_property_id.ids),
],
domain=domain,
)

def resync_import(self):
Expand Down

0 comments on commit 12e71ef

Please sign in to comment.