Merge pull request #1623 from expsa/ensan_tasks_19_10

Benefit customization
This commit is contained in:
enagahh 2024-10-26 17:37:49 +03:00 committed by GitHub
commit ed96838495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 7 deletions

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from . import benefit
from . import benefit_services
from . import attchment_preview

View File

@ -0,0 +1,30 @@
import base64
from odoo import http
from odoo.http import request
import urllib.parse # For URL encoding
class MyAttachmentController(http.Controller):
@http.route('/browse/document/<int:id>', type='http', auth="public")
def browse_document(self, id):
model = 'ir.attachment'
attachment = request.env[model].sudo().browse(id)
if not attachment.exists() or not attachment.datas:
return request.not_found()
# Decode the file content
file_data = base64.b64decode(attachment.datas)
file_mimetype = attachment.mimetype or 'application/octet-stream'
# URL-encode the filename for non-ASCII characters
filename = urllib.parse.quote(attachment.name)
# Set HTTP headers with the URL-encoded filename
http_headers = [
('Content-Type', file_mimetype),
('Content-Length', str(len(file_data))),
('Content-Disposition', f'inline; filename*=UTF-8\'\'{filename}')
]
return request.make_response(file_data, headers=http_headers)

View File

@ -22,6 +22,14 @@ class BenefitAttachment(models.Model):
is_required = fields.Boolean(string='Is Required?')
is_default = fields.Boolean(string='Is Default?')
def action_preview_attachment(self):
# Custom function to open the preview
return {
'type': 'ir.actions.act_url',
'url': f'/browse/document/{self.id}',
'target': 'new', # Opens in a new tab
}
@api.depends('expiration_date')
def get_status(self):
for rec in self:
@ -61,4 +69,5 @@ class BenefitAttachment(models.Model):
def onchange_disabilities_id(self):
for rec in self:
if rec.disabilities_id:
rec.name = rec.disabilities_id.name
rec.name = rec.disabilities_id.name

View File

@ -572,7 +572,8 @@
<tree editable="bottom">
<field name="hobbies_id" required="1"/>
<field name="name"/>
<field name="datas" string="File content"/>
<field name="datas" widget="binary" filename="attachment_file_name"/>
<button name="action_preview_attachment" type="object" string="Preview Attachment"/>
<field name="expiration_date"/>
<field name="attach_status"/>
<field name="member_id" invisible="1"/>
@ -584,7 +585,8 @@
<tree editable="bottom">
<field name="diseases_id" required="1"/>
<field name="name"/>
<field name="datas" string="File content"/>
<field name="datas" widget="binary" filename="attachment_file_name"/>
<button name="action_preview_attachment" type="object" string="Preview Attachment"/>
<field name="expiration_date"/>
<field name="attach_status"/>
<field name="member_id" invisible="1"/>
@ -596,7 +598,8 @@
<tree editable="bottom">
<field name="disabilities_id" required="1"/>
<field name="name"/>
<field name="datas" string="File content"/>
<field name="datas" widget="binary" filename="attachment_file_name"/>
<button name="action_preview_attachment" type="object" string="Preview Attachment"/>
<field name="expiration_date"/>
<field name="attach_status"/>
<field name="member_id" invisible="1"/>
@ -670,8 +673,8 @@
<tree editable="bottom" delete="0">
<field name="name" string="Attachment Name" attrs="{'readonly':[('is_default','=',True)]}" force_save="1"/>
<field name="attach_id" invisible="1"/>
<field name="datas" string="File content"/>
<field name="expiration_date"/>
<field name="datas" widget="binary" filename="attachment_file_name"/>
<button name="action_preview_attachment" type="object" string="Preview Attachment"/> <field name="expiration_date"/>
<field name="attach_status"/>
<field name="allow_days"/>
<field name="benefit_id" invisible="1"/>
@ -1005,7 +1008,8 @@
<field name="attachment_ids" widget="one2many_list" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
<tree editable="bottom" delete="0">
<field name="name" attrs="{'readonly':[('is_default','=',True)]}" force_save="1"/>
<field name="datas"/>
<field name="datas" widget="binary" filename="attachment_file_name"/>
<button name="action_preview_attachment" type="object" string="Preview Attachment"/>
<field name="expiration_date"/>
<field name="attach_status"/>
<field name="allow_days"/>