Skip to content

Commit

Permalink
[T2031] Added upload button for the code of conduct (#2023)
Browse files Browse the repository at this point in the history
* [T2031] Added upload button for the code of conduct

* [T2031] Added upload button for the code of conduct

---------

Co-authored-by: auclerc <[email protected]>
  • Loading branch information
Nath-S07 and auclerc authored Mar 4, 2025
1 parent e6df3a8 commit f2444ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 23 additions & 5 deletions child_protection/models/partner_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging

from odoo import fields, models
from odoo.tools.mimetypes import guess_mimetype

logger = logging.getLogger(__name__)

Expand All @@ -29,23 +28,42 @@ class ResPartner(models.Model):
criminal_record_name = fields.Char(compute="_compute_criminal_record_name")
criminal_record_date = fields.Date(tracking=True)

code_of_conduct_file = fields.Binary(
string="Code of Conduct",
attachment=True,
help="Upload file",
)
code_of_conduct_filename = fields.Char(
string="File Name",
compute="_compute_code_of_conduct_filename",
)

##########################################################################
# FIELDS METHODS #
##########################################################################
def _compute_criminal_record_name(self):
for partner in self:
if partner.criminal_record:
ftype = guess_mimetype(
partner.with_context(bin_size=False).criminal_record
)
partner.criminal_record_name = f"Criminal record {partner.name}{ftype}"
partner.criminal_record_name = f"Criminal_Record_{partner.name}"
else:
partner.criminal_record_name = False

def _compute_code_of_conduct_filename(self):
for record in self:
if record.code_of_conduct_file:
record.code_of_conduct_filename = f"Code_of_Conduct_{record.name}"
else:
record.code_of_conduct_filename = False

##########################################################################
# ORM METHODS #
##########################################################################
def write(self, vals):
if vals.get("criminal_record"):
vals["criminal_record_date"] = fields.Date.today()

if vals.get("code_of_conduct_file"):
for partner in self:
if not partner.date_agreed_child_protection_charter:
vals["date_agreed_child_protection_charter"] = fields.Datetime.now()
return super().write(vals)
6 changes: 6 additions & 0 deletions child_protection/views/partner_compassion_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
string="Child Protection"
name="child_protection_charter_fields"
>
<field name="code_of_conduct_filename" invisible="1" />
<field
name="code_of_conduct_file"
filename="code_of_conduct_filename"
/>
<field
string="Date agreed"
name="date_agreed_child_protection_charter"
/>

<field name="criminal_record_name" invisible="1" />
<field
name="criminal_record"
Expand Down

0 comments on commit f2444ae

Please sign in to comment.