Skip to content

Commit

Permalink
[MOD] plm_report_language_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Dec 31, 2024
1 parent 5452362 commit 9f73709
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 267 deletions.
2 changes: 1 addition & 1 deletion plm/report/bom_structure_report_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<t t-foreach="docs" t-as="o">
<t t-call="web.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_header_spacing" t-value="18"/>
<t t-set="data_report_dpi" t-value="110"/>

<t t-call="web.internal_layout">
Expand Down
2 changes: 1 addition & 1 deletion plm_report_language_helper/__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
15 changes: 5 additions & 10 deletions plm_report_language_helper/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
Expand All @@ -20,24 +21,18 @@
##############################################################################
{
"name": "Plm Report Language Helper",
"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,
"summary": "Manage multilanguage PLM reports",
"license": "AGPL-3",
"images": [],
"depends": ["plm",
"plm_spare"],
"data": [
# security
"depends": ["plm", "plm_spare"],
"data": [
"security/plm_security.xml",
# views
"views/plm_component_action_extended.xml",
"wizard/select_lang_wizard_view.xml",
],
"demo": [],
"test": [],
"installable": True,
"application": False,
"auto_install": False,
Expand Down
62 changes: 0 additions & 62 deletions plm_report_language_helper/views/plm_component_action_extended.xml

This file was deleted.

4 changes: 2 additions & 2 deletions plm_report_language_helper/wizard/__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 All @@ -19,4 +19,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import wizard
from . import select_lang_wizard
177 changes: 177 additions & 0 deletions plm_report_language_helper/wizard/select_lang_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
"""
Created on Mar 30, 2016
@author: Daniel Smerghetto
"""
import base64
import logging
from email.policy import default

from odoo import _, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


# ************************** SPARE REPORTS *****************
class plm_spareChoseLanguage(models.TransientModel):
_name = "plm.sparechoselanguage"
_description = ("Module for extending the functionality of printing"
"spare_bom reports in a multi language environment")


def getInstalledLanguage(self):
"""
get installed language
"""
out = []
modobj = self.env["res.lang"]
for objBrowse in modobj.search([]):
out.append((objBrowse.code, objBrowse.name))
return out

lang = fields.Selection(getInstalledLanguage, "Language", required=True)
onelevel = fields.Boolean(
string="One Level",
default=False,
help="If you check this box, the report will be made in one level"
)
datas = fields.Binary("Download", readonly=True)
datas_name = fields.Char("Download file name ", size=255, readonly=True)

def print_report(self):
self.ensure_one()
lang = self.lang
if lang:
modobj = self.env["ir.module.module"]
mids = modobj.search([("state", "=", "installed")])
if not mids:
raise UserError("Language not Installed")
reportName = "report.plm_spare.pdf_all"
# 'plm_spare.report_product_product_spare_parts_pdf'
if self.onelevel:
reportName = "report.plm_spare.pdf_one"
# 'plm_spare.report_product_product_spare_parts_pdf_one'
productProductId = self.env.context.get("active_id")
newContext = self.env.context.copy()
newContext["lang"] = lang
newContext["force_report_rendering"] = True

tProductProduct = self.env["product.product"]
brwProduct = tProductProduct.browse(productProductId)
report_context = self.env[reportName].sudo().with_context(newContext)
stream = report_context._create_spare_pdf(brwProduct)
self.datas = base64.encodebytes(stream)
fileName = brwProduct.name + "_" + lang + "_manual.pdf"
self.datas_name = fileName
return {
"context": self.env.context,
"view_type": "form",
"view_mode": "form",
"res_model": plm_spareChoseLanguage._name,
"res_id": self.id,
"view_id": False,
"type": "ir.actions.act_window",
"target": "new",
}
UserError(_("Select a language"))


# ************************** BOM REPORTS *****************

AVAILABLE_REPORT = [
("plm.report_plm_bom_structure_all", "BOM All Levels"),
("plm.report_plm_bom_structure_one", "BOM One Level"),
("plm.report_plm_bom_structure_all_sum", "BOM All Levels Summarized"),
("plm.report_plm_bom_structure_one_sum", "BOM One Level Summarized"),
("plm.report_plm_bom_structure_leaves", "BOM Only Leaves Summarized"),
("plm.report_plm_bom_structure_flat", "BOM All Flat Summarized"),
]


class plm_bomChoseLanguage(models.TransientModel):
_name = "plm.bomchoselanguage"
_description = ("Module for extending the functionality of printing bom reports"
"in a multi language environment")

def getInstalledLanguage(self):
"""
get installed language
"""
out = []
modobj = self.env["res.lang"]
for objBrowse in modobj.search([]):
out.append((objBrowse.code, objBrowse.name))
return out

def print_report(self):
self.ensure_one()
lang = self.lang
if lang:
modobj = self.env["ir.module.module"]
mids = modobj.search([("state", "=", "installed")])
if not mids:
raise UserError("Language not Installed")
reportName = self.bom_type
newContext = self.env.context.copy() # Used to update and generate pdf
newContext["lang"] = lang
newContext["force_report_rendering"] = True
bomId = self.env.context.get("active_id")
stream, fileExtention = (
self.env.ref(reportName)
.sudo()
.with_context(newContext)
._render_qweb_pdf(reportName, bomId)
)
self.datas = base64.b64encode(stream)
tMrpBom = self.env["mrp.bom"]
brwProduct = tMrpBom.browse(bomId)
fileName = (
brwProduct.product_tmpl_id.name + "_" + lang + "_bom." + fileExtention
)
self.datas_name = fileName
return {
"context": self.env.context,
"view_type": "form",
"view_mode": "form",
"res_model": plm_bomChoseLanguage._name,
"res_id": self.id,
"view_id": False,
"type": "ir.actions.act_window",
"target": "new",
}
raise UserError(_("Select a language"))

lang = fields.Selection(getInstalledLanguage, _("Language"), required=True)

bom_type = fields.Selection(
AVAILABLE_REPORT,
_("Bom Report Type"),
required=True,
help=_("Chose the Bom report you would like to print"),
)

datas = fields.Binary(_("Download"), readonly=True)

datas_name = fields.Char(_("Download file name "), size=255, readonly=True)
_defaults = {"bom_type": False}
60 changes: 60 additions & 0 deletions plm_report_language_helper/wizard/select_lang_wizard_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="plm_sparechoselanguage_form" model="ir.ui.view">
<field name="name">plm.sparechoselanguage.form</field>
<field name="model">plm.sparechoselanguage</field>
<field name="arch" type="xml">
<form string="Creation of Spare Bom">
<group col="4" colspan="4">
<field string="Language" name="lang"/>
<field string="First Level" name="onelevel"/>
</group>
<field name="datas" filename="datas_name"/>
<field name="datas_name" invisible="1"/>
<footer>
<button special="cancel" string="Cancel"/>
<button string="Create Spare Report" name="print_report" type="object"/>
</footer>
</form>
</field>
</record>

<record id="act_plm_print_spare_bom" model="ir.actions.act_window">
<field name="name">Create Report Spare Bom</field>
<field name="res_model">plm.sparechoselanguage</field>
<field name="view_mode">form</field>
<field name="binding_model_id" ref="product.model_product_product"/>
<field name="view_id" ref="plm_sparechoselanguage_form"/>
<field name="target">new</field>
</record>

<record id="plm_bomchoselanguage_form" model="ir.ui.view">
<field name="name">plm.bomchoselanguage.form</field>
<field name="model">plm.bomchoselanguage</field>
<field name="arch" type="xml">
<form string="Creation of Spare Bom">
<group col="4" colspan="4">
<field string="Language" name="lang"/>
<field string="Print Bom Type" name="bom_type"/>
</group>
<field name="datas" filename="datas_name"/>
<field name="datas_name" invisible="1"/>
<footer>
<button special="cancel" string="Cancel"/>
<button string="Create Spare Report" name="print_report" type="object"/>
</footer>
</form>
</field>
</record>

<record id="act_plm_print_boms" model="ir.actions.act_window">
<field name="name">Create Boms Report</field>
<field name="res_model">plm.bomchoselanguage</field>
<field name="view_mode">form</field>
<field name="binding_model_id" ref="mrp.model_mrp_bom"/>
<field name="view_id" ref="plm_bomchoselanguage_form"/>
<field name="target">new</field>
</record>
</data>
</odoo>
Loading

0 comments on commit 9f73709

Please sign in to comment.