Search 1.9 billion lines of Odoo code on GitHub

api_for_download_attachment_directly

Author: Roger
License: no license
Branch: master
Repository: ihatebeans/odoo_addons
Dependencies: base
Languages: HTML (11, 4.3%), Markdown (42, 16.3%), PO File (42, 16.3%), Python (99, 38.4%), and XML (64, 24.8%)
Other repositories: RRRoger/odoo_addons

<h1>api<em>for</em>download<em>attachment</em>directly</h1> <blockquote> <p>下载附件免登陆 / Download Attachment Without Login Odoo</p> </blockquote> <div align=center> <img src="static/description/icon.png" width="80"/> </div> <h3>1. Usage / 如何使用?</h3> <blockquote> <p>Download the avatar of the partner whose id is 999 </p> </blockquote> <p>```python</p> <h1>when you use api</h1> <p>from odoo.http import request attachment<em>factory</em>obj = request.env[&#39;attachment.factory&#39;]</p> <h1>Or Other</h1> <h1>attachment<em>factory</em>obj = self.env[&#39;attachment.factory&#39;]</h1> <p>model = &quot;res.partner&quot; res<em>id = 999 model</em>field = &quot;avatar&quot; filename<em>field = &quot;avatar</em>name&quot; note = &quot;download avatar of partner&quot;</p> <p>af = attachment<em>factory</em>obj.create({ &quot;model&quot;: model, &quot;res<em>id&quot;: res</em>id, &quot;model<em>field&quot;: model</em>field, &quot;filename<em>field&quot;: filename</em>field, &quot;note&quot;: note, })</p> <h1>you will get a file_url and a filename</h1> <h1>file url like: http://localhost:8069/web/download/attachment/1babc64e-6e99-4934-bc84-28263a0fdd88</h1> <h1>Open your browser with this URL and download it directly</h1> <p>file_url = af.url</p> <h1>file name like: xxx.jpg</h1> <p>filename = af.filename ```</p> <h3>2. Automatically delete out-of-date data / 删除失效的数据</h3> <blockquote> <p>code in <code>api_for_download_attachment_directly/data/data.xml</code></p> <p>delete 7 days ago temporary data</p> </blockquote> <p><code>xml &lt;record id=&quot;cron_delete_expired_data&quot; model=&quot;ir.cron&quot;&gt; &lt;field name=&quot;name&quot;&gt;[Download Attachment] 删除失效的数据&lt;/field&gt; ... &lt;/record&gt; </code></p>