Skip to content

Commit

Permalink
[REF] connector_pms: pre-commit error
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed May 8, 2024
1 parent 79b5e5c commit 10af8ed
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 59 deletions.
35 changes: 14 additions & 21 deletions connector_pms/components/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,34 @@ class ChannelAdapter(AbstractComponent):
_name = "channel.adapter"
_inherit = "base.backend.adapter.crud"

def chunks(self, l, n):
def chunks(self, lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(l), n):
yield l[i : i + n]
for i in range(0, len(lst), n):
yield lst[i : i + n]

def _filter(self, values, domain=None):
# TODO support for domains with 'or' clauses
# TODO refactor and optimize
if not domain:
return values

operations = {
"=": lambda x, y: x != y,
"!=": lambda x, y: x == y,
">": lambda x, y: x <= y,
"<": lambda x, y: x >= y,
">=": lambda x, y: x < y,
"<=": lambda x, y: x > y,
}

values_filtered = []
for record in values:
for elem in domain:
k, op, v = elem
if k not in record:
raise ValidationError(_("Key %s does not exist") % k)
if op == "=":
if record[k] != v:
break
elif op == "!=":
if record[k] == v:
break
elif op == ">":
if record[k] <= v:
break
elif op == "<":
if record[k] >= v:
break
elif op == ">=":
if record[k] < v:
break
elif op == "<=":
if record[k] > v:
break
if operations[op](record[k], v):
break
elif op == "in":
if not isinstance(v, (tuple, list)):
raise ValidationError(
Expand Down
12 changes: 6 additions & 6 deletions connector_pms/components/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class ChannelExporter(AbstractComponent):
""" Base exporter for Channel """
"""Base exporter for Channel"""

_name = "channel.exporter"
_inherit = "generic.exporter.custom"
Expand All @@ -27,7 +27,7 @@ class ChannelBatchExporter(AbstractComponent):
_inherit = "base.exporter"

def run(self, domain=None):
""" Run the batch synchronization """
"""Run the batch synchronization"""
if not domain:
domain = []
relation_model = self.binder_for().unwrap_model()
Expand All @@ -43,27 +43,27 @@ def _export_record(self, external_id):


class ChannelDirectBatchExporter(AbstractComponent):
""" Import the records directly, without delaying the jobs. """
"""Import the records directly, without delaying the jobs."""

_name = "channel.direct.batch.exporter"
_inherit = "channel.batch.exporter"

_usage = "direct.batch.exporter"

def _export_record(self, relation):
""" export the record directly """
"""export the record directly"""
self.model.export_record(self.backend_record, relation)


class ChannelDelayedBatchExporter(AbstractComponent):
""" Delay import of the records """
"""Delay import of the records"""

_name = "channel.delayed.batch.exporter"
_inherit = "channel.batch.exporter"

_usage = "delayed.batch.exporter"

def _export_record(self, relation, job_options=None):
""" Delay the export of the records"""
"""Delay the export of the records"""
delayable = self.model.with_delay(**job_options or {})
delayable.export_record(self.backend_record, relation)
12 changes: 6 additions & 6 deletions connector_pms/components/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class ChannelImporter(AbstractComponent):
""" Base importer for Channel """
"""Base importer for Channel"""

_name = "channel.importer"
_inherit = "generic.importer.custom"
Expand All @@ -33,7 +33,7 @@ class ChannelBatchImporter(AbstractComponent):
# self._import_record(record_id)

def run(self, domain=None):
""" Run the synchronization """
"""Run the synchronization"""
if domain is None:
domain = []
records = self.backend_adapter.search_read(domain)
Expand All @@ -49,15 +49,15 @@ def _import_record(self, external_id, external_data=None):


class ChannelDirectBatchImporter(AbstractComponent):
""" Import the records directly, without delaying the jobs. """
"""Import the records directly, without delaying the jobs."""

_name = "channel.direct.batch.importer"
_inherit = "channel.batch.importer"

_usage = "direct.batch.importer"

def _import_record(self, external_id, external_data=None):
""" Import the record directly """
"""Import the record directly"""
if external_data is None:
external_data = {}
self.model.import_record(
Expand All @@ -66,15 +66,15 @@ def _import_record(self, external_id, external_data=None):


class ChannelDelayedBatchImporter(AbstractComponent):
""" Delay import of the records """
"""Delay import of the records"""

_name = "channel.delayed.batch.importer"
_inherit = "channel.batch.importer"

_usage = "delayed.batch.importer"

def _import_record(self, external_id, external_data=None, job_options=None):
""" Delay the import of the records"""
"""Delay the import of the records"""
if external_data is None:
external_data = {}
delayable = self.model.with_delay(**job_options or {})
Expand Down
5 changes: 3 additions & 2 deletions connector_pms/components_custom/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ def wrap_record(self, relation, force=False):
return binding

def _check_domain(self, domain):
for field, _, value in domain:
for field, _r, value in domain:
if isinstance(value, (list, tuple)):
for e in value:
if isinstance(e, (tuple, list, set, dict)):
raise ValidationError(
_(
"Wrong domain value type '%s' on value '%s' of field '%s'"
"Wrong domain value type '%s' "
"on value '%s' of field '%s'"
)
% (type(e), e, field)
)
Expand Down
12 changes: 5 additions & 7 deletions connector_pms/data/queue_data.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Eric Antones <eantones@nuobit.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data noupdate="0">
<record id="channel_pms" model="queue.job.channel">
<field name="name">pms</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>
</data>
<odoo noupdate="0">
<record id="channel_pms" model="queue.job.channel">
<field name="name">pms</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>
</odoo>
9 changes: 4 additions & 5 deletions connector_pms/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from odoo import models, fields, api
from odoo import api, fields, models

_logger = logging.getLogger(__name__)

Expand All @@ -11,12 +11,12 @@ class QueueJob(models.Model):
_inherit = "queue.job"

pms_property_id = fields.Many2one(
comodel_name='pms.property',
string='Property',
comodel_name="pms.property",
string="Property",
store=True,
)

@api.depends('args')
@api.depends("args")
def _compute_pms_property_id(self):
for rec in self:
if rec.args[1:2] and isinstance(
Expand All @@ -25,4 +25,3 @@ def _compute_pms_property_id(self):
rec.pms_property_id = rec.args[1:2][0]
else:
rec.pms_property_id = False

2 changes: 1 addition & 1 deletion connector_pms/views/channel_backend_log_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<field name="name">channel.backend.log.tree</field>
<field name="model">channel.backend.log</field>
<field name="arch" type="xml">
<tree string="PMS Channel Backend Log">
<tree>
<field name="backend_id" />
<field name="timestamp" />
<field name="method_id" />
Expand Down
2 changes: 1 addition & 1 deletion connector_pms/views/channel_backend_method_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<field name="name">channel.backend.method.tree</field>
<field name="model">channel.backend.method</field>
<field name="arch" type="xml">
<tree string="PMS Channel Backend Method">
<tree>
<field name="backend_type_id" />
<field name="name" />
<field name="max_calls" />
Expand Down
2 changes: 1 addition & 1 deletion connector_pms/views/channel_backend_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<field name="name">channel.backend.type.tree</field>
<field name="model">channel.backend.type</field>
<field name="arch" type="xml">
<tree string="PMS Backend Type">
<tree>
<field name="name" />
<field name="model_type_id" />
<button
Expand Down
2 changes: 1 addition & 1 deletion connector_pms/views/channel_backend_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<field name="name">channel.backend.tree</field>
<field name="model">channel.backend</field>
<field name="arch" type="xml">
<tree string="PMS Backend">
<tree>
<field name="name" />
<field name="backend_type_id" />
<field name="pms_property_id" />
Expand Down
12 changes: 6 additions & 6 deletions connector_pms/views/pms_availability_plan_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
eval="[(4, ref('connector.group_connector_manager'))]"
/>
<field name="arch" type="xml">
<field name="rule_ids" position="replace">
<xpath expr="//field[@name='rule_ids']" position="after">
<notebook>
<page name="rules" string="Rules">
<field name="rule_ids" nolabel="1" />
</page>
<page name="rules" string="Rules" />
<page string="Connectors" name="connector" />
</notebook>

</field>
</xpath>
<page name="rules" position="inside">
<field name="rule_ids" position="move" />
</page>
</field>
</record>
</odoo>
9 changes: 7 additions & 2 deletions connector_pms/views/queue_job_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
<field name="inherit_id" ref="queue_job.view_queue_job_search" />
<field name="arch" type="xml">
<xpath expr="//field[@name='result']" position="after">
<filter name="pms_property_id"/>
<filter name="pms_property_id" />
</xpath>
<xpath expr="//filter[@name='group_by_channel']" position="after">
<filter name="group_by_property" string="Property" domain="[]" context="{'group_by':'pms_property_id'}"/>
<filter
name="group_by_property"
string="Property"
domain="[]"
context="{'group_by':'pms_property_id'}"
/>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 10af8ed

Please sign in to comment.