Skip to content

Commit

Permalink
FIX: better manage large file
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Sep 27, 2024
1 parent f0159c5 commit 26f533f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "Product Lifecycle Management",
"version": "17.0.0.6",
"version": "17.0.0.7",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand All @@ -30,6 +30,7 @@
"summary": "PLM-PDM Integration with main CAD editors (SolidWorks, SolidEdge, Inventor, Autocad, Thinkdesign, Freecad, Draftsight)",
"images": ["static/img/odoo_plm.png"],
"depends": ["base", "board", "product", "mrp"],
'external_dependencies': {'python': ['base64io']},
"data": [
# data
"data/data.xml",
Expand Down
24 changes: 24 additions & 0 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import random
import string
import os
import io
from base64io import Base64IO
import time
import json
import copy
Expand Down Expand Up @@ -109,6 +111,28 @@ class IrAttachment(models.Model):
must_update_from_cad = fields.Boolean("Must Update form CAD",
compute="_compute_must_update_from_cad",
help="""When this flag is enabled the 2d document must be updated in order to guaranteey the update betwin 2d and 3d document""")

@api.depends('store_fname', 'db_datas', 'file_size')
@api.depends_context('bin_size')
def _compute_datas(self):
if self._context.get('bin_size'):
for attach in self:
attach.datas = human_size(attach.file_size)
return

for attach in self:
attach.datas = self.get_stream_b64encode(attach.raw or b'')

def get_stream_b64encode(self, from_stream):
source = io.BytesIO()
target = io.BytesIO()
source.write(from_stream)
source.seek(0)
with Base64IO(target) as encoded_target:
for line in source:
encoded_target.write(line)
target.seek(0)
return target.read()

def _compute_must_update_from_cad(self):
ir_attachment_relation = self.env['ir.attachment.relation']
Expand Down

0 comments on commit 26f533f

Please sign in to comment.