Skip to content

Commit

Permalink
migrate the below module.
Browse files Browse the repository at this point in the history
    -> plm_web_3d
  • Loading branch information
jayraj-omnia committed Nov 28, 2024
1 parent a02f5c1 commit eacdc31
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 382 deletions.
2 changes: 1 addition & 1 deletion plm/views/ir_attachment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<button
class="fa fa-print"
type="object"
titel="print"
title="print"
name="download_printout"
invisible="document_type in ['3d','pr','other']"/>
<field name="name" select="True"/>
Expand Down
4 changes: 1 addition & 3 deletions plm_web_3d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Your own solutions
Expand All @@ -18,12 +19,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

"""
Created on 13/11/2020
@author: Matteo Boscolo
"""

from . import models
from . import controllers
12 changes: 5 additions & 7 deletions plm_web_3d/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
Expand All @@ -20,23 +21,20 @@
##############################################################################
{
"name": "PLM Web 3d Support",
"version": "18.0.0.1",
"version": "18.0.1.0.0",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
"sequence": 15,
"license": "AGPL-3",
"summary": "",
"images": [],
"summary": """
This Module allows you to view 3D file.
""",
"depends": ["plm"],
"data": [
# views
"views/ir_attachment.xml",
"views/web_template.xml",
],
"qweb": [],
"demo": [],
"test": [],
"installable": True,
"application": False,
"auto_install": False,
Expand Down
2 changes: 1 addition & 1 deletion plm_web_3d/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
Expand Down
86 changes: 52 additions & 34 deletions plm_web_3d/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# -*- coding: utf-8 -*-
import functools
import base64
import functools
import json
import logging
import os
from odoo import _

from odoo.http import Controller, route, request, Response
import copy
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT


def webservice(f):
Expand All @@ -17,45 +13,53 @@ def wrap(*args, **kw):
return f(*args, **kw)
except Exception as e:
return Response(response=str(e), status=500)

return wrap


class Web3DView(Controller):
@route('/plm/show_treejs_model', type='http', auth='public')
@route("/plm/show_treejs_model", type="http", auth="public")
@webservice
def show_treejs_model(self, document_id, document_name):
return request.render('plm_web_3d.main_treejs_view', {'document_id': document_id,
'document_name': document_name})
return request.render(
"plm_web_3d.main_treejs_view",
{"document_id": document_id, "document_name": document_name},
)

@route('/plm/download_treejs_model', type='http', auth='public')
@route("/plm/download_treejs_model", type="http", auth="public")
@webservice
def download_treejs_model(self, document_id):
for ir_attachment in request.env['ir.attachment'].sudo().search([('id','=', int(document_id))]):
for ir_attachment in (
request.env["ir.attachment"].sudo().search([("id", "=", int(document_id))])
):
if ir_attachment.has_web3d:
headers = []
content_base64 = base64.b64decode(ir_attachment.datas)
headers.append(('Content-Length', len(content_base64)))
headers.append(('file_name', ir_attachment.name))
headers.append(("Content-Length", len(content_base64)))
headers.append(("file_name", ir_attachment.name))
response = request.make_response(content_base64, headers)
return response
return Response(response="Document Not Found %r " % document_id, status=500)

def document_extra(self, document):
"""
this function id for customising the documents attributes
this function id for customising the documents attributes
"""
return document

def component_extra(self, components):
"""
this function id for customising the component attributes
this function id for customising the component attributes
"""
return components
@route('/plm/get_product_info', type='http', auth="user")

@route("/plm/get_product_info", type="http", auth="user")
@webservice
def getProductInfo(self, document_id):
out={}
for ir_attachment in request.env['ir.attachment'].sudo().search([('id','=', int(document_id))]):
out = {}
for ir_attachment in (
request.env["ir.attachment"].sudo().search([("id", "=", int(document_id))])
):
if ir_attachment.has_web3d:
document = """
<li class="attribute_info"><b>Name:</b> %s</li>
Expand All @@ -64,30 +68,44 @@ def getProductInfo(self, document_id):
""" % (
ir_attachment.engineering_code or ir_attachment.name,
ir_attachment.engineering_revision,
ir_attachment.engineering_state
)
ir_attachment.engineering_state,
)
document = self.document_extra(document)
out['document']=document
out["document"] = document
for component in ir_attachment.linkedcomponents:
components = """
<li class="attribute_info"><b>Product Name:</b> %s</li>
<li class="attribute_info"><b>Product Revision:</b> %s</li>
<li class="attribute_info"><b>Description:</b> %s</li>
""" % ( component.engineering_code,
component.engineering_revision,
component.name)
""" % (
component.engineering_code,
component.engineering_revision,
component.name,
)
components = self.component_extra(components)
out['component']=components
out["component"] = components
return json.dumps(out)
@route('/plm/get_3d_web_document_info', type='http', auth="user")

@route("/plm/get_3d_web_document_info", type="http", auth="user")
@webservice
def get_3d_web_document_info(self, src_name):
src_name = src_name.split("(")[0] # this split is needed for solidwoks file the put the configuration on the name filename(<configuration name>)description
src_name = src_name.split("(")[0]
# this split is needed for solidwoks file the put the configuration
# on the name filename(<configuration name>)description
out = f"""<span>{src_name}</span>"""
for ir_attachment in request.env['ir.attachment'].sudo().search(['|',('name','ilike', src_name),('engineering_code','ilike', src_name)]):
for ir_attachment in (
request.env["ir.attachment"].sudo().search([
"|", ("name", "ilike", src_name),
("engineering_code", "ilike", src_name)
])
):
for product_product_id in ir_attachment.linkedcomponents:
out = f"""<span title={product_product_id.name}>{product_product_id.engineering_code} Rev. {product_product_id.engineering_revision}</span>"""
out = f"""
<span title={product_product_id.name}>
{product_product_id.engineering_code}
Rev. {product_product_id.engineering_revision}
</span>
"""
break

return out

5 changes: 1 addition & 4 deletions plm_web_3d/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Your own solutions
Expand All @@ -18,13 +19,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

"""
Created on 13/11/2020
@author: Matteo Boscolo
"""

from . import ir_attachment
from . import product_product_document_rel

106 changes: 59 additions & 47 deletions plm_web_3d/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,85 +18,97 @@
# along with this prograIf not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
'''
"""
Created on 13 Nov 2020
@author: mboscolo
'''
"""
import os
import json
import logging
import datetime
from odoo import models
from odoo import fields
from odoo import api
from odoo import _
from odoo.exceptions import UserError
from datetime import timedelta
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
import urllib.parse
SUPPORTED_WEBGL_EXTENTION = ['.3mf','.gltf','.glb','.fbx','.obj','.wrl','.json', '.stl','.svg', '.dxf']
#
#

from odoo import api, fields, models

SUPPORTED_WEBGL_EXTENTION = [
".3mf",
".gltf",
".glb",
".fbx",
".obj",
".wrl",
".json",
".stl",
".svg",
".dxf",
]


class IrAttachment(models.Model):
_inherit = ['ir.attachment']

has_web3d = fields.Boolean(string="Has 3d Web link",
compute="_compute_web_3d_link",
# store=True,
help='Check if this document has related 3d web document')
_inherit = "ir.attachment"

has_web3d = fields.Boolean(
string="Has 3d Web link",
compute="_compute_web_3d_link",
# store=True,
help="Check if this document has related 3d web document",
)

def isWebGl(self):
for ir_attachment in self:
if ir_attachment.name:
_name, exte = os.path.splitext(ir_attachment.name)
return exte.lower() in SUPPORTED_WEBGL_EXTENTION
return False
@api.depends('name')

@api.depends("name")
def _compute_web_3d_link(self):
attach_relations = self.env['ir.attachment.relation']
attach_relations = self.env["ir.attachment.relation"]
for ir_attachment in self:
if ir_attachment.isWebGl():
ir_attachment.has_web3d = True
continue
ir_attachment.has_web3d = attach_relations.search_count([('parent_id', '=', ir_attachment.id),
('link_kind','=','Web3DTree')])

ir_attachment.has_web3d = attach_relations.search_count([
("parent_id", "=", ir_attachment.id),
("link_kind", "=", "Web3DTree")
])

def get_url_for_3dWebModel(self):
attach_relations = self.env['ir.attachment.relation']
attach_relations = self.env["ir.attachment.relation"]
for ir_attachment in self:
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
url_params = None
if ir_attachment.isWebGl():
url_params = urllib.parse.urlencode({'document_id': ir_attachment.id,
'document_name': ir_attachment.name})
url_params = urllib.parse.urlencode({
"document_id": ir_attachment.id,
"document_name": ir_attachment.name
})
else:
for rel in attach_relations.search([('parent_id', '=', ir_attachment.id),
('link_kind','=','Web3DTree')]):

url_params = urllib.parse.urlencode({'document_id': rel.child_id.id,
'document_name': rel.child_id.name})
for rel in attach_relations.search([
("parent_id", "=", ir_attachment.id),
("link_kind", "=", "Web3DTree")
]):
url_params = urllib.parse.urlencode({
"document_id": rel.child_id.id,
"document_name": rel.child_id.name
})
if url_params:
return f"{base_url}/plm/show_treejs_model?{url_params}"

def show_releted_3d(self):
for ir_attachment in self:
url = ir_attachment.get_url_for_3dWebModel()
if url:
return {'name': 'Odoo TreeJs View',
'res_model': 'ir.actions.act_url',
'type': 'ir.actions.act_url',
'target': self,
'url': url
}
return {
"name": "Odoo TreeJs View",
"res_model": "ir.actions.act_url",
"type": "ir.actions.act_url",
"target": self,
"url": url,
}

def get_all_relation(self, document_id, exte):
out={}
out = {}
if exte in document_id.name:
out[document_id.id] = document_id.name
for child_attachment_id in self.getRelatedHiTree(document_id.id):
if exte in self.browse(child_attachment_id).name:
out[child_attachment_id.id]=child_attachment_id.name
out[child_attachment_id.id] = child_attachment_id.name
return out

Loading

0 comments on commit eacdc31

Please sign in to comment.