Skip to content

Commit

Permalink
[ADD] ir.attachment integration
Browse files Browse the repository at this point in the history
  • Loading branch information
luismalta committed Aug 13, 2020
1 parent 78dad47 commit e396dcc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

from . import res_company
from . import res_config_settings

from . import ir_attachment
6 changes: 6 additions & 0 deletions dms/models/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class Category(models.Model):

count_files = fields.Integer(compute="_compute_count_files", string="Count Files")

ir_model_id = fields.Many2one(
comodel_name='ir.model',
string='Attachment Model',
required=False
)

# ----------------------------------------------------------
# Constrains
# ----------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions dms/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import api, models, fields, tools


class IrAttachment(models.Model):

_inherit = "ir.attachment"

@api.model
def create(self, vals):
category_id = self.env['dms.category'].search([
('ir_model_id', '=', vals['res_model'])])

directory_id = self.env['dms.directory'].search([
('category_id', '=', category_id.id)])

if category_id and directory_id:
self.env['dms.file'].create({
'name': vals['name'],
'category_id': category_id.id,
'directory_id': directory_id.id,
'content': vals['datas'],
})

return super(IrAttachment, self).create(vals)
3 changes: 3 additions & 0 deletions dms/views/category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<field name="count_directories" string="Directories" />
</group>
</group>
<group>
<field name="ir_model_id"/>
</group>
<notebook>
<page string="Tags">
<field
Expand Down

0 comments on commit e396dcc

Please sign in to comment.