Skip to content

Commit

Permalink
Merge pull request #80 from OmniaGit/16.0
Browse files Browse the repository at this point in the history
This new functionality must be merged in v17
  • Loading branch information
OmniaGit authored Jul 19, 2024
2 parents 0aa8647 + c91fb2a commit 2a9b594
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 68 deletions.
2 changes: 1 addition & 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.2",
"version": "17.0.0.3",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
92 changes: 55 additions & 37 deletions plm/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
import copy
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT


def webservice(f):
@functools.wraps(f)
def wrap(*args, **kw):
try:
return f(*args, **kw)
except Exception as e:
return Response(response=str(e), status=500)
return wrap


logging.error(e)
return Response(response=f"{e}", status=500)
return wrap
class UploadDocument(Controller):

@route('/plm_document_upload/isalive', type='http', auth='none', methods=['GET'], csrf=False)
Expand All @@ -29,7 +28,10 @@ def isalive(self):

@route('/plm_document_upload/login', type='http', auth='none', methods=['POST'], csrf=False)
@webservice
def login(self, login, password, db=None):
def login(self,
login,
password,
db=None):
if db and db != request.db:
raise Exception(_("Could not select database '%s'") % db)
uid = request.session.authenticate(request.db, login, password)
Expand All @@ -41,7 +43,10 @@ def login(self, login, password, db=None):

@route('/plm_document_upload/upload_pdf', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload_pdf(self, file_stream=None, doc_id=False, **kw):
def upload_pdf(self,
file_stream=None,
doc_id=False,
**kw):
logging.info('start upload PDF %r' % (doc_id))
if doc_id:
logging.info('start json %r' % (doc_id))
Expand All @@ -58,7 +63,11 @@ def upload_pdf(self, file_stream=None, doc_id=False, **kw):

@route('/plm_document_upload/upload', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload(self, mod_file=None, doc_id=False, filename='', **kw):
def upload(self,
mod_file=None,
doc_id=False,
filename='',
**kw):
logging.info('start upload %r' % (doc_id))
if doc_id:
logging.info('start json %r' % (doc_id))
Expand All @@ -81,7 +90,9 @@ def upload(self, mod_file=None, doc_id=False, filename='', **kw):

@route('/plm_document_upload/download', type='http', auth='user', methods=['GET'])
@webservice
def download(self, requestvals='[[],[],-1]', **kw):
def download(self,
requestvals='[[],[],-1]',
**kw):
logging.info('Download with arguments %r kw %r' % (requestvals, kw))
if not requestvals:
logging.info('No file requests to download')
Expand All @@ -105,7 +116,10 @@ def download(self, requestvals='[[],[],-1]', **kw):

@route('/plm_document_upload/upload_preview', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload_preview(self, mod_file=None, doc_id=False, **kw):
def upload_preview(self,
mod_file=None,
doc_id=False,
**kw):
logging.info('start upload preview %r' % (doc_id))
if doc_id:
logging.info('start json %r' % (doc_id))
Expand All @@ -122,7 +136,9 @@ def upload_preview(self, mod_file=None, doc_id=False, **kw):

@route('/plm_document_upload/zip_archive', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload_zip(self, attachment_id=None, filename='', **kw):
def upload_zip(self,
attachment_id=None,
filename='', **kw):
logging.info('start upload zip %r' % (attachment_id))
if attachment_id:
attachment_id = json.loads(attachment_id)
Expand Down Expand Up @@ -167,38 +183,40 @@ def upload_zip(self, attachment_id=None, filename='', **kw):
@route('/plm_document_upload/get_zip_archive', type='http', auth='user', methods=['get'], csrf=False)
@webservice
def download_zip(self, ir_attachment_id=None, **kw):
try:
ir_attachment_id = json.loads(ir_attachment_id)
attachment = request.env['ir.attachment']
pkg_ids = attachment.getRelatedPkgTree(ir_attachment_id)
for pkg_id in pkg_ids:
pkg_brws = attachment.browse(pkg_id)
return Response(pkg_brws.datas,
headers={'file_name': pkg_brws.name})
return Response(status=200)
except Exception as ex:
return Response(f"{ex}", status=500)
ir_attachment_id = json.loads(ir_attachment_id)
attachment = request.env['ir.attachment']
pkg_ids = attachment.getRelatedPkgTree(ir_attachment_id)
for pkg_id in pkg_ids:
pkg_brws = attachment.browse(pkg_id)
return Response(pkg_brws.datas,
headers={'file_name': pkg_brws.name})
return Response(status=200)


@route('/plm_document_upload/get_files_write_time', type='http', auth='user', methods=['get'], csrf=False)
@webservice
def get_files_write_time(self, ir_attachment_ids=None, **kw):
try:
ir_attachment_ids = json.loads(ir_attachment_ids)
attachment = request.env['ir.attachment']
out = []
for attachment_id in ir_attachment_ids:
attachment_brws = attachment.browse(attachment_id)
out.append((attachment_brws.id,
attachment_brws.name,
attachment_brws.write_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)))
return Response(json.dumps(out))
except Exception as ex:
logging.error(ex)
return Response(f"{ex}", status=500)
def get_files_write_time(self,
ir_attachment_ids=None,
**kw):
ir_attachment_ids = json.loads(ir_attachment_ids)
attachment = request.env['ir.attachment']
out = []
for attachment_id in ir_attachment_ids:
attachment_brws = attachment.browse(attachment_id)
out.append((attachment_brws.id,
attachment_brws.name,
attachment_brws.write_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)))
return Response(json.dumps(out))


@route('/plm_document_upload/extra_file', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload_extra_file(self, product_id='', doc_name='', doc_rev='0', related_attachment_id='', **kw):
def upload_extra_file(self,
product_id='',
doc_name='',
doc_rev='0',
related_attachment_id='',
**kw):
logging.info('Start upload extra file %r' % (product_id))
product_id = eval(product_id)
doc_rev = eval(doc_rev)
Expand Down
20 changes: 12 additions & 8 deletions plm/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,14 @@ def copy(self, default={}):
False,
False)
]) # Get Latest revision of each Part
bom_line.sudo().write({
'engineering_state': 'draft',
'source_id': False,
'name': bom_line.product_id.product_tmpl_id.name,
'product_id': late_rev_id_c[0]
})
for late_rev_id in late_rev_id_c:
bom_line.sudo().write({
'engineering_state': 'draft',
'source_id': False,
'name': bom_line.product_id.product_tmpl_id.name,
'product_id': late_rev_id
})
break
new_bom_brws.sudo().with_context({'check': False}).write({
'source_id': False,
'name': new_bom_brws.product_tmpl_id.name
Expand Down Expand Up @@ -748,10 +750,12 @@ def recursion(bom_brws_list):
return {'name': _('B.O.M. Lines'),
'res_model': 'mrp.bom.line',
'view_type': 'form',
'view_mode': 'pivot,tree',
'view_mode': 'tree',
'view_id': self.env.ref("plm.plm_mrp_bom_line_summarize_tree").id,
'search_view_id': self.env.ref("plm.plm_grp_by_parent").id,
'type': 'ir.actions.act_window',
'domain': [('id', 'in', bom_line_ids)],
'context': {"group_by": ['bom_id']},
'context': {},
}


Expand Down
16 changes: 15 additions & 1 deletion plm/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from odoo import fields
from odoo import api
from odoo import _
import logging


class MrpBomLineExtension(models.Model):
Expand Down Expand Up @@ -193,6 +192,7 @@ def _related_doc_ids(self):
readonly=True,
index=True,
help=_("This is the document object that declares this BoM."))

type = fields.Selection(related="bom_id.type")
itemnum = fields.Integer(_('CAD Item Position'), help=_(
"This is the item reference position into the CAD document that declares this BoM."))
Expand All @@ -218,6 +218,20 @@ def _related_doc_ids(self):
_('Cutted Compute Type'),
default='none')

product_tag_ids = fields.Many2many(related='product_tmpl_id.product_tag_ids')

product_tumbnail = fields.Image(related="product_id.product_tmpl_id.image_1920")

def go_to_product(self):
return {'name': _('Product'),
'res_model': 'product.product',
'res_id':self.product_id.id,
'view_type': 'form',
'view_mode': 'form',
'type': 'ir.actions.act_window',
'domain': [('id', 'in', self.product_id.ids)],
}

def plm_sanitize(self, vals):
all_keys = self._fields
if isinstance(vals, dict):
Expand Down
5 changes: 3 additions & 2 deletions plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def on_change_stdvalue(self):
self.std_value1,
self.std_value2,
self.std_value3)


@api.onchange('tmp_material')
def on_change_tmpmater(self):
if self.tmp_material:
Expand Down Expand Up @@ -913,7 +913,7 @@ def _commonWFAction(obj,
return _commonWFAction(self, status, include_statuses, recursive,check_in_check=check_in_check)

# ######################################################################################################################################33
def plm_sanitize(self, vals):
def plm_sanitize(self, vals):
all_keys = self._fields
if isinstance(vals, dict):
valsKey = list(vals.keys())
Expand Down Expand Up @@ -1883,6 +1883,7 @@ def populate(product_id):
populate(self)
return out


@api.model
def get_all_document_source_path(self, attributes, *k, **kw):
out_src = []
Expand Down
16 changes: 11 additions & 5 deletions plm/report/document_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class ReportDocumentPdf(models.AbstractModel):
_name = 'report.plm.ir_attachment_pdf'
_description = 'Report Document PDF'

@api.model
def _render_qweb_pdf(self, documents=None, data=None):
docType = self.env['ir.attachment']
docRepository = docType._get_filestore()
def get_custom_text(self):
to_zone = tz.gettz(self.env.context.get('tz', 'Europe/Rome'))
from_zone = tz.tzutc()
dt = datetime.now()
Expand All @@ -48,7 +45,16 @@ def _render_qweb_pdf(self, documents=None, data=None):
'date_now': localDT.ctime(),
'state': 'doc_obj.engineering_state',
}
output = BookCollector(jumpFirst=False, customText=(msg, msg_vals), bottomHeight=10, poolObj=self.env)
return (msg, msg_vals)

@api.model
def _render_qweb_pdf(self, documents=None, data=None):
docType = self.env['ir.attachment']
docRepository = docType._get_filestore()
output = BookCollector(jumpFirst=False,
customText=self.get_custom_text(),
bottomHeight=10,
poolObj=self.env)
return packDocuments(docRepository, documents, output)

@api.model
Expand Down
38 changes: 38 additions & 0 deletions plm/views/mrp_extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@
<odoo>
<!-- View customization on MRP -->

<record id="plm_mrp_bom_line_summarize_tree" model="ir.ui.view">
<field name="name">plm.mrp.bom.line.summarize.tree</field>
<field name="model">mrp.bom.line</field>
<field name="arch" type="xml">
<tree>
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
<field name="product_id"/>
<button name="go_to_product"
icon="fa-external-link"
type="object"
title="Compute Cost"/>
<field name="description"/>
<field name="engineering_revision"/>
<field name="engineering_state"/>
<field name="product_qty"/>
<field name="product_uom_id"/>
<field name="product_tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" />
<field name="source_id" optional="hide"/>
</tree>
</field>
</record>

<record id="plm_grp_by_parent" model="ir.ui.view">
<field name="name">plm.grp.by.parente</field>
<field name="model">mrp.bom.line</field>
<field eval="100" name="priority" />
<field name="arch" type="xml">
<search string="Product line search">
<filter string="Group By Parent" name="grp_by_parent" context="{'group_by':'bom_id'}"/>
<field string="Product" name="product_id"/>
<field string="Description" name="description"/>
<field string="Tags" name="product_tag_ids"/>
</search>
</field>
</record>

<record id="plm_mrp_bom_line_view_form" model="ir.ui.view">
<field name="name">plm.mrp.bom.line.view.form</field>
<field name="model">mrp.bom.line</field>
Expand All @@ -10,6 +46,7 @@
<field name="arch" type="xml">
<field name="product_id" position="before">
<field name="itemnum"/>
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
</field>
<field name="product_id" position="after">
<field name="engineering_revision" readonly="True"/>
Expand Down Expand Up @@ -124,6 +161,7 @@
<xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_id']" position="before">
<field name="related_bom_ids" invisible="True"/>
<field name="hasChildBoms" invisible="True"/>
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
<button name="openRelatedBoms"
type="object"
icon="fa-level-down"
Expand Down
Loading

0 comments on commit 2a9b594

Please sign in to comment.