Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][3702][ADD] base_protected_attachment #40

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base_protected_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions base_protected_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Base Protected Attachment",
"version": "16.0.1.0.0",
"depends": ["mail"],
"author": "Quartile Limited",
"license": "AGPL-3",
"website": "https://www.quartile.co",
"category": "Attachment",
"data": ["security/ir.model.access.csv", "views/protected_attachment_views.xml"],
"installable": True,
}
3 changes: 3 additions & 0 deletions base_protected_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mail_thread
from . import protected_attachment
from . import ir_ui_view
47 changes: 47 additions & 0 deletions base_protected_attachment/models/ir_ui_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from lxml import etree

from odoo import api, models


class Base(models.AbstractModel):
_inherit = "base"

@api.model
def get_view(self, view_id=None, view_type="form", **options):
result = super(Base, self).get_view(
view_id=view_id, view_type=view_type, **options
)
if view_type == "form" and "protected_attachment_ids" in self._fields:
arch = etree.fromstring(result["arch"])

notebook_elem = arch.find(".//notebook")
if notebook_elem is None:
notebook_elem = etree.SubElement(arch, "notebook")
sheet = arch.find(".//sheet")
if sheet is not None:
sheet.append(notebook_elem)
else:
arch.append(notebook_elem)

# Create a new tab/page for the protected attachments
page_elem = etree.SubElement(
notebook_elem, "page", string="Protected Attachments"
)

# Add the one2many field to the new tab/page
field_elem = etree.SubElement(
page_elem, "field", name="protected_attachment_ids"
)
field_elem.set("options", '{"editable": "top"}')

# Define the tree structure for the one2many field
# tree_elem = etree.SubElement(field_elem, 'tree', editable="top")
# etree.SubElement(tree_elem, 'field', name="attachment")
# etree.SubElement(tree_elem, 'field', name="attachment_name")

# Update the architecture of the view
result["arch"] = etree.tostring(arch, encoding="unicode")
return result
14 changes: 14 additions & 0 deletions base_protected_attachment/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

protected_attachment_ids = fields.One2many(
comodel_name="protected.attachment",
inverse_name="object_id",
string="Protected Attachments",
)
18 changes: 18 additions & 0 deletions base_protected_attachment/models/protected_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProtectedAttachment(models.Model):
_name = "protected.attachment"
_description = "Protected Attachment"

object_id = fields.Many2one(
comodel_name="mail.thread",
ondelete="cascade",
required=True,
copy=False,
)
attachment = fields.Binary(string="File", required=True)
attachment_name = fields.Char(string="File Name", readonly=True)
2 changes: 2 additions & 0 deletions base_protected_attachment/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_protected_attachment_user,access.protected.attachment_user,model_protected_attachment,base.group_user,1,1,1,0
28 changes: 28 additions & 0 deletions base_protected_attachment/views/protected_attachment_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_protected_attachment_tree" model="ir.ui.view">
<field name="name">view.protected.attachment.tree</field>
<field name="model">protected.attachment</field>
<field name="arch" type="xml">
<tree>
<field name="attachment" widget="binary" filename="attachment_name" />
</tree>
</field>
</record>
<record id="action_protected_attachment" model="ir.actions.act_window">
<field name="name">Protected Attachment</field>
<field name="res_model">protected.attachment</field>
</record>
<menuitem
id="menu_protected_attachment"
name="Protected Attachment"
parent="base.menu_administration"
sequence="20"
/>
<menuitem
id="menu_protected_attachment_model"
action="action_protected_attachment"
parent="menu_protected_attachment"
sequence="20"
/>
</odoo>
6 changes: 6 additions & 0 deletions setup/base_protected_attachment/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading