Attachment upload basic principle realization, can refer to this article:
Https://www.cnblogs.com/ljwTiey/p/7348291.html
http://blog.csdn.net/wangnan537/article/details/41903159
First of all we look at the Odoo interface default attachment features, there is no feeling of wood is very friendly! Embarrassed:)
Let's introduce another kind of Odoo's own attachment management method to our small partners!
First, add the following definition to your model:
############################################################################################################ ### #Add attachment upload functionAttachment_number = fields. Integer (compute='_compute_attachment_number', string='Number of Attachments') @api. Multidef_compute_attachment_number (self):"""Attachment upload"""Attachment_data= self.env['ir.attachment'].read_group ([('Res_model','=','Replace with your model name'), ('res_id','inch', Self.ids)], ['res_id'], ['res_id']) Attachment= Dict ((data['res_id'], data['Res_id_count']) forDatainchattachment_data) forExpenseinchSelf:expense.attachment_number=attachment.get (expense.id, 0) @api. MultidefAction_get_attachment_view (self):"""Attachment upload Action View"""Self.ensure_one () Res= self.env['Ir.actions.act_window'].FOR_XML_ID ('Base','action_attachment') res['Domain'] = [('Res_model','=','Replace with your model name'), ('res_id','inch', Self.ids)] res['Context'] = {'Default_res_model':'Replace with your model name','default_res_id': Self.id}returnRes#############################################################################################
The front view view adds the following code:
<divclass="Oe_button_box"Name="Button_box"> <button name="Action_get_attachment_view" class="Oe_stat_button"icon="Fa-book"Type="Object"> <field name="Attachment_number"widget="Statinfo"string="Attachment upload"/> </button></div>
Implementation results:
Notice above this upload interface, Odoo does the permission configuration, in the developer mode, and normal mode, the display interface is different.
Activate developer mode, which shows the effect:
This is actually the addition of the following settings in the View Front Code field:
Try your little friends!!!
Odoo Development Notes--attachment upload