Help

2

How to delete current record in server action?

I have installed crm_helpdesk and it's working great, when a new emai arrives it creates the help desk ticket correctly. Now i want to check the email_from field for check if the address is in a list. If the address is in a list i want to delete the help-desk record.

I tried to make a action server with the next python code:

# Available locals:
# - time, datetime, dateutil: Python libraries
# - env: Odoo Environement
# - model: Model of the record on which the action is triggered
# - object: Record on which the action is triggered if there is one, otherwise None
# - workflow: Workflow engine
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}
#
#
# Search if the field "object.email_from" contains the string in items of spam[]
# Note: object.email_from can be: "Example" <members@news.thisisspam.com> is for this
# reason that we use find method while iterating all elements. In spam we store only
# mail addresses and object.email contains the name (Example) and addresses are
# enclosed in "<>"

spam = ["members@news.thisisspam.com"]
for item in spam:   
    if item.find(object.email_from) != -1:
#object.unlink()
         self.search([('ID', '=', object.id)]).unlink()


but this seems don't work....i changed the last line for object.unlink() with no result, the tickets from these addresses are always created .

It's possible delete the record from the action server code?

Any suggestions to debug the server action code are too appreciated

Thanks in advance.

Avatar
Discard
1 Answer
0
Best Answer

hi, 


why not simply:


if object.email_from in spam: 
    object.unlink()
Avatar
Discard