-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5452362
commit 9f73709
Showing
8 changed files
with
246 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
plm_report_language_helper/views/plm_component_action_extended.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
plm_report_language_helper/wizard/select_lang_wizard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
plm_report_language_helper/wizard/select_lang_wizard_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.