Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont unlink emails with non existing reference on read #51

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 6 additions & 47 deletions poweremail_references/poweremail_mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def poweremail_callback(self, cursor, uid, ids, func, vals=None, context=None):
ctx['meta'] = {}
if vals:
init_meta = vals.get('meta', {}) or {}
if isinstance(init_meta, basestring):
if isinstance(init_meta, six.string_types):
init_meta = json.loads(init_meta)
else:
init_meta = {}
Expand Down Expand Up @@ -74,67 +74,26 @@ def create(self, cursor, uid, vals, context=None):
self.poweremail_callback(cursor, uid, pe_id, 'create', vals, context)
return pe_id

def validate_referenced_object_exists(self, cursor, uid, id, vals, context=None):
ret = True
fields = ['reference']
result = self._read_flat(cursor, uid, id, fields, context, '_classic_read')
for r in result:
if 'reference' in r.keys():
v = r['reference']
if v:
model, ref_id = v.split(',')
ref_obj = self.pool.get(model)

if ref_id != '0':
id_exist = ref_obj.search(cursor, 1, [
('id', '=', ref_id)
], context={'active_test': False})
if not id_exist:
ret = False
return ret

def read(self, cursor, uid, ids, fields=None, context=None, load='_classic_read'):
if context is None:
context = {}
select = ids
if isinstance(ids, six.integer_types):
select = [ids]
valid_select = []
for id in select:
res = self.validate_referenced_object_exists(cursor, uid, [id], fields, context=None)
if res:
valid_select.append(id)
else:
super(PoweremailMailbox,
self).unlink(cursor, uid, [id], context)
ret = []
if valid_select:
ret = super(PoweremailMailbox,
self).read(cursor, uid, valid_select, fields, context, load)
if isinstance(ids, six.integer_types) and ret:
return ret[0]
return ret

def write(self, cursor, uid, ids, vals, context=None):
if context is None:
context = {}
meta = context.get('meta')
if meta:
vals['meta'] = json.dumps(meta)
self.poweremail_callback(cursor, uid, ids, 'write', vals, context)
ret = super(PoweremailMailbox,
self).write(cursor, uid, ids, vals, context)
ret = super(PoweremailMailbox, self).write(cursor, uid, ids, vals, context)
return ret

def unlink(self, cursor, uid, ids, context=None):
if context is None:
context = {}
self.poweremail_callback(cursor, uid, ids, 'unlink', context=context)
ret = super(PoweremailMailbox,
self).unlink(cursor, uid, ids, context)
ret = super(PoweremailMailbox, self).unlink(cursor, uid, ids, context)
return ret

def _get_models(self, cursor, uid, context={}):
def _get_models(self, cursor, uid, context=None):
if context is None:
context = {}
cursor.execute('select m.model, m.name from ir_model m order by m.model')
return cursor.fetchall()

Expand Down
Loading