Skip to content

[ADD] attachment_pdfa - #651

Open
baimont wants to merge 1 commit into
OCA:18.0from
acsone:bai_pdf_to_pdfa
Open

[ADD] attachment_pdfa#651
baimont wants to merge 1 commit into
OCA:18.0from
acsone:bai_pdf_to_pdfa

Conversation

@baimont

@baimont baimont commented Aug 4, 2026

Copy link
Copy Markdown

Here's a proposal for a new module that will allow to convert PDF attachments to PDF/A.
It does nothing on itself.
Developer has to implement which models must opt-in by inheriting attachment.pdfa.mixin and override _attachment_must_be_pdfa().

@baimont
baimont force-pushed the bai_pdf_to_pdfa branch 2 times, most recently from 10ec074 to e778a80 Compare August 4, 2026 15:03
@baimont

baimont commented Aug 4, 2026

Copy link
Copy Markdown
Author

@sbidoul and @AnizR please take a look?

@AnizR AnizR left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good contribution 🚀

"""Check if attachment creation dictionary qualifies for conversion."""
mimetype = vals.get("mimetype", "")
name = vals.get("name", "")
if not (mimetype == "application/pdf" or name.lower().endswith(".pdf")):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not (mimetype == "application/pdf" or name.lower().endswith(".pdf")):
if not (mimetype == "application/pdf" or not name.lower().endswith(".pdf")):

_logger.exception(msg)
return raw_content, False, msg

def _should_convert_to_pdfa(self, vals):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@api.model

)

@api.model_create_multi
def create(self, vals_list):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the write function?

Odoo has some workflows where they create the attachment then do a write to link to a record. IMO, in this case, the conversion should also be applied.

Comment on lines +36 to +41
ps_content = re.sub(
r"/ICCProfile \((.+)\)",
f"/ICCProfile ({rgb_profile})",
ps_content,
)
try:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary modify the icc_profile_ps each time?
If not, I am wondering if the 'temp_ps' below is still needed

Comment on lines +28 to +34
data_dir = Path(__file__).parent.parent / "data"
icc_profile_ps = data_dir / "pdfa_def.ps"
rgb_profile = data_dir / "iccprofiles_default_rgb.icc"
if not icc_profile_ps.is_file() or not rgb_profile.is_file():
msg = "Ghostscript ICC Profile or PDF/A definition file not found."
_logger.error(msg)
return raw_content, False, msg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paths should be initialized and checked when the module is imported. (at the top of the file).

if not (res_model and res_id):
return False
model_obj = self.env.get(res_model)
if model_obj is None or not hasattr(model_obj, "_attachment_must_be_pdfa"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be put into a dedicated method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants