Skip to content

Commit

Permalink
IMP: printing system on document
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Oct 24, 2023
1 parent a338a3f commit 00106f6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 25 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": "16.0.25",
"version": "16.0.26",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
22 changes: 12 additions & 10 deletions plm/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,24 @@ def get_preview(self, id):
ir_attachement = request.env['ir.attachment'].sudo()
for record in ir_attachement.search_read([('id','=', id)], ['preview']):
return base64.b64decode(record.get('preview'))



@route('/plm/ir_attachment_printout/<int:id>', type='http', auth='user', methods=['GET'], csrf=False)
@webservice
def get_printout(self, id):
try:
ir_attachement = request.env['ir.attachment'].sudo()
for ir_attachement_id in ir_attachement.search_read([('id','=', id)],
['printout','name']):
print_out_data = ir_attachement_id.get('printout')
for ir_attachement_id in request.env['ir.attachment'].sudo().browse(id):
if ir_attachement_id.printout:
print_out_data = request.env['report.plm.ir_attachment_pdf']._render_qweb_pdf(ir_attachement_id)
print_out_data = print_out_data[0]
if print_out_data:
data = base64.b64decode(print_out_data)
headers = [('Content-Type', 'application/pdf'),
('Content-Length', len(data)),
('Content-Disposition', 'inline; filename="%s"' % ir_attachement_id.get('name','no_name') + '.pdf')]
return request.make_response(data, headers)
('Content-Length', len(print_out_data)),
('Content-Disposition', f'inline; filename="{ir_attachement_id.engineering_code}_{ir_attachement_id.engineering_revision}.pdf"')]
return request.make_response(print_out_data, headers)
else:
return request.not_found("Pdf document %s not Available" % ir_attachement_id.get('name','no_name'))
return request.not_found(f"Pdf document {ir_attachement_id.engineering_code} not Available")
else:
return request.not_found(f"Pdf document {ir_attachement_id.engineering_code} not Available")
except Exception as ex:
return Response(f"{ex}", status=500)
14 changes: 10 additions & 4 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def _compute_must_update_from_cad(self):
for ir_attachment in self:
ir_attachment.must_update_from_cad=False
if ir_attachment.document_type =='2d':
ir_attachment.must_update_from_cad=ir_attachment_relation.is_2d_ok(ir_attachment)
if ir_attachment.document_type =='pr':
ir_attachment.must_update_from_cad=ir_attachment_relation.is_pr_ok(ir_attachment)
ir_attachment.must_update_from_cad= not ir_attachment_relation.is_2d_ok(ir_attachment)
elif ir_attachment.document_type =='pr':
ir_attachment.must_update_from_cad= not ir_attachment_relation.is_pr_ok(ir_attachment)

def _getPrintoutName(self):
for ir_attachment_id in self:
Expand All @@ -126,7 +126,13 @@ def _getPrintoutName(self):
def getPrintoutUrl(self):
self.ensure_one()
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
return "%s/plm/ir_attachment_printout/%s" % (base_url, self.id)
return f"{base_url}/plm/ir_attachment_printout/{self.id}"

def download_printout(self):
return {'type': 'ir.actions.act_url',
'url': self.getPrintoutUrl(),
'target': 'new',
}

@property
def actions(self):
Expand Down
4 changes: 2 additions & 2 deletions plm/models/ir_attachment_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ def is_2d_ok(self, from_ir_attachment_id):
('link_kind', '=', 'LyTree')
]):
if relation_id.parent_id.document_type=='2d' and relation_id.child_id.document_type in ['3d','pr']:
if relation_id.parent_id.write_date < relation_id.child_id.write_date:
if relation_id.parent_id.getLastCadSave() < relation_id.child_id.getLastCadSave():
return False
if relation_id.child_id.document_type=='2d' and relation_id.parent_id.document_type in ['3d','pr'] :
if relation_id.child_id.write_date<relation_id.parent_id.write_date:
if relation_id.child_id.getLastCadSave()<relation_id.parent_id.getLastCadSave():
return False
return True

Expand Down
26 changes: 24 additions & 2 deletions plm/models/plm_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,29 @@ def action_from_confirmed_to_released(self):
obj.engineering_state = RELEASED_STATUS
obj._mark_worklow_user_date()
obj._mark_obsolete_previous()


def action_un_release(self):
if not self.env.user.has_group("plm.group_plm_admin_unrelease"):
raise UserError("You are not allowed to perform such an action ask to your PLM admin")
for obj in self:
body ="""
FORCE draft action from super plm admin user !!!
data could be not as expected !!!
"""
obj.message_post(body=body)
obj.with_context(check=False).engineering_state=START_STATUS

def action_un_release_release(self):
if not self.env.user.has_group("plm.group_plm_admin_unrelease"):
raise UserError("You are not allowed to perform such an action ask to your PLM admin")
for obj in self:
body ="""
FORCE release action from super plm admin user !!!
data could be not as expected !!!
"""
obj.message_post(body=body)
obj.with_context(check=False).engineering_state=RELEASED_STATUS

def _mark_obsolare(self):
for obj in self:
obj.engineering_state = OBSOLATED_STATUS
Expand All @@ -187,7 +209,7 @@ def _mark_under_modifie(self):
for obj in self:
obj.engineering_state = UNDER_MODIFY_STATUS
obj._mark_worklow_user_date()

def _mark_under_modifie_previous(self):
for obj in self:
if obj.engineering_revision in [False, 0]:
Expand Down
2 changes: 1 addition & 1 deletion plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def action_reactivate(self):
product_product_id.commonWFAction(RELEASED_STATUS,
[OBSOLATED_STATUS])
return True

def commonWFAction(self,
status,
include_statuses=[],
Expand Down
9 changes: 8 additions & 1 deletion plm/security/base_plm_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
<field name="implied_ids" eval="[(4, ref('group_plm_integration_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>


<!-- Un release user -->
<record id="group_plm_admin_unrelease" model="res.groups">
<field name="name">Unrelease User</field>
<field name="category_id" ref="odooplm_module_category"/>
<field name="implied_ids" eval="[(4, ref('group_plm_admin'))]"/>
</record>

<!-- Readonly Released -->
<record id="group_plm_readonly_released" model="res.groups">
<field name="name">PLM Integration Readonly</field>
Expand Down
23 changes: 19 additions & 4 deletions plm/views/ir_attachment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
string="Confirm Document"
class="oe_highlight"
attrs="{'invisible': ['|',('is_checkout','=',True),('engineering_state','!=','draft')]}"/>
<button name="action_un_release"
type="object"
attrs="{'invisible': [('engineering_state','!=','released')]}"
string="Un Release"
groups="plm.group_plm_admin_unrelease"
class="oe_highlight"/>
<button name="action_un_release_release"
type="object"
attrs="{'invisible': [('engineering_state','!=','draft')]}"
string="Re Release"
groups="plm.group_plm_admin_unrelease"
class="oe_highlight"/>
<field name="engineering_state"
widget="statusbar"
statusbar_visible="draft,confirmed,released"
Expand Down Expand Up @@ -224,10 +236,13 @@
decoration-success="engineering_state == 'released'"
decoration-warning="engineering_state == 'undermodify'"
decoration-muted="engineering_state == 'obsoleted'">

<field name="preview" widget="image" options="{ 'size': [60, 60]}"/>
<field name="printout_name" invisible="True"/>
<field name="printout" widget="binary" filename="printout_name" readonly="True"/>
<field name="document_type" invisible="True"/>
<field name="preview" widget="image" options="{ 'size': [60, 60]}"/>
<button
class="fa fa-print"
type="object"
name="download_printout"
attrs="{'invisible':[('document_type','in',['3d','pr','other'])]}"/>
<field name="name" select="True"/>
<field name="engineering_revision" select="True"/>
<field name="engineering_state" select="True"/>
Expand Down

0 comments on commit 00106f6

Please sign in to comment.