Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
8528 Tampilan

Hello there,

In Odoo 8, if I'm trying to delete the attachment "/sitemap.xml" each day to refresh it.

I'm trying this way but I get an error :


Error is :

2016-12-08 09:07:37,267 14478 ERROR odoo-iv openerp.addons.base.ir.ir_cron: Call of self.pool.get('ir.attachment')._file_delete(cr, uid, *('/', 's', 'i', 't', 'e', 'm', 'a', 'p', '.', 'x', 'm', 'l')) failed in Job 10
Traceback (most recent call last):
    File "/home/odoo-iv/odoo-8.0-20161109/openerp/addons/base/ir/ir_cron.py", line 138, in _callback    getattr(model, method_name)(cr, uid, *args) 
    File "/home/odoo-iv/odoo-8.0-20161109/openerp/api.py", line 268, in wrapper   
    return old_api(self, *args, **kwargs)
TypeError: _file_delete() takes exactly 4 arguments (15 given)


Somebody could help?


EDIT #1

Answer From Axel was right. 

But I think to delete a file, I have to use the unlink function of ir.attachement class. This function needs IDs to delete attachments. See image below, I have deleted two attachments with this action :

But now, big problem... When the new sitemap.xml attachment is recreated, it doesn't have the same id... So the action is unusable. How to overcome this problem?

Avatar
Buang
Penulis Jawaban Terbai

Here is our solution to this problem.

Since the _file_delete function was not the right method to use to delete an attachment.

Since the unlink method needs an ids list to work.

We had written this method who works well. May be you will have some changes in this method to get it better. We are not very strong in Python...


def delete_sitemap(self, cr, uid):
        id_list = []
        cr.execute("SELECT id FROM ir_attachment WHERE name ilike '%sitemap%'")
        res = cr.fetchall()
        if res:
            for r in res:
                id_list.append(r[0])
                self.unlink(cr, uid, id_list)
                return True
        return False


Avatar
Buang
Jawaban Terbai

Hi Pascal

You just need to put your arguments value as:

("sitemap.xml",)

because in Python a tuple of one element needs a comma after the element to be taken as a tuple, meaning that:

("sitemap.xml") will be taken by Python as "sitemap.xml"

that's why Odoo take the "sitemap.xml" as the arguments tuple due to that strings in Python like many others programming languages could be taken as a list, tuple or array of characters

Avatar
Buang
Penulis

Your answer is good. Thanks. But, I think I used the wrong function. I edit my post.

Post Terkait Replies Tampilan Aktivitas
1
Mar 24
1917
1
Des 21
14059
0
Mar 15
4644
4
Okt 23
12547
4
Jun 23
7545