Skip to content

Commit

Permalink
edi_oca: edi.conf cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Nov 15, 2024
1 parent 963f766 commit 5d22c1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 72 deletions.
22 changes: 8 additions & 14 deletions edi_oca/tests/fake_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,16 @@ class FakeConfigurationListener(FakeComponentMixin):
_inherit = "base.event.listener"
_apply_on = ["edi.exchange.consumer.test"]

def on_record_write_configuration(self, record, fields=None, **kwargs):
def on_record_write(self, record, fields=None, **kwargs):
trigger = "on_record_write"
if kwargs.get("vals", False):
for rec in record:
confs = record.edi_config_ids.edi_get_conf(trigger)
for conf in confs:
conf.edi_exec_snippet_do(rec, **kwargs)
confs = record.edi_config_ids.edi_get_conf(trigger)
for conf in confs:
conf.edi_exec_snippet_do(record, **kwargs)
return True

def on_record_create_configuration(self, record, fields=None, **kwargs):
def on_record_create(self, record, fields=None, **kwargs):
trigger = "on_record_create"
val_list = kwargs.get("vals", False)
if val_list:
for rec, vals in zip(record, val_list):
kwargs["vals"] = {rec.id: vals}
confs = rec.edi_config_ids.edi_get_conf(trigger)
for conf in confs:
conf.edi_exec_snippet_do(rec, **kwargs)
confs = record.edi_config_ids.edi_get_conf(trigger)
for conf in confs:
conf.edi_exec_snippet_do(record, **kwargs)
return True
59 changes: 1 addition & 58 deletions edi_oca/tests/fake_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author: Enric Tobella
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

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


class EdiExchangeConsumerTest(models.Model):
Expand All @@ -22,60 +22,3 @@ class EdiExchangeConsumerTest(models.Model):

def _get_edi_exchange_record_name(self, exchange_record):
return self.id

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
operation = "create"

new_records = self.browse()
new_vals_list = []

for rec, vals in zip(records, vals_list):
if not rec._edi_configuration_skip(operation):
new_records |= rec
new_vals_list.append(vals)

if new_records:
self._event("on_record_create_configuration").notify(
new_records,
operation=operation,
vals=new_vals_list,
)
return records

def write(self, vals):
operation = "write"
new_records = self.browse()

for rec in self:
if not rec._edi_configuration_skip(operation):
new_records |= rec

old_vals = {}
for record in new_records:
old_vals[record.id] = {field: record[field] for field in vals.keys()}

res = super().write(vals)

new_values = {}
for record in new_records:
new_values[record.id] = {field: record[field] for field in vals.keys()}

if new_values:
self._event("on_record_write_configuration").notify(
new_records,
operation=operation,
old_vals=old_vals,
vals=new_values,
)
return res

def _edi_configuration_skip(self, operation):
skip_reason = None
if self.env.context.get("edi_skip_configuration"):
skip_reason = "edi_skip_configuration ctx key found"
# TODO: Add more skip cases
if skip_reason:
return True
return False

0 comments on commit 5d22c1b

Please sign in to comment.