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['attachment.factory']</p>
<h1>Or Other</h1>
<h1>attachment<em>factory</em>obj = self.env['attachment.factory']</h1>
<p>model = "res.partner"
res<em>id = 999
model</em>field = "avatar"
filename<em>field = "avatar</em>name"
note = "download avatar of partner"</p>
<p>af = attachment<em>factory</em>obj.create({
"model": model,
"res<em>id": res</em>id,
"model<em>field": model</em>field,
"filename<em>field": filename</em>field,
"note": 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
<record id="cron_delete_expired_data" model="ir.cron">
<field name="name">[Download Attachment] 删除失效的数据</field>
...
</record>
</code></p>