@ -1,11 +1,6 @@ |
|||
## Module <manufacturing_reports> |
|||
|
|||
#### 17.02.2023 |
|||
#### 23.08.2023 |
|||
#### Version 15.0.1.0.0 |
|||
##### ADD |
|||
- Initial commit for Manufacturing Reports |
|||
|
|||
#### 10.07.2023 |
|||
#### Version 15.0.1.0.0 |
|||
#### UPDT |
|||
- Bug Fix for the xlsx report not printing issue in Manufacturing Reports |
@ -1,12 +1,11 @@ |
|||
<?xml version="1.0"?> |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Manufacturing Report--> |
|||
<record id="action_mrp_report" model="ir.actions.report"> |
|||
<record id="action_report_mrp" model="ir.actions.report"> |
|||
<field name="name">Manufacturing Report</field> |
|||
<field name="model">mrp.report</field> |
|||
<field name="model">manufacturing.report</field> |
|||
<field name="report_type">qweb-pdf</field> |
|||
<field name="report_name">manufacturing_reports.report_mrp_order</field> |
|||
<field name="report_file">manufacturing_reports.report_mrp_order</field> |
|||
<field name="report_name">manufacturing_reports.report_mrp</field> |
|||
<field name="report_file">manufacturing_reports.report_mrp</field> |
|||
<field name="binding_type">report</field> |
|||
</record> |
|||
</odoo> |
|||
</odoo> |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 310 B After Width: | Height: | Size: 310 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 733 B After Width: | Height: | Size: 733 B |
Before Width: | Height: | Size: 911 B After Width: | Height: | Size: 911 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 673 B After Width: | Height: | Size: 673 B |
Before Width: | Height: | Size: 878 B After Width: | Height: | Size: 878 B |
Before Width: | Height: | Size: 653 B After Width: | Height: | Size: 653 B |
Before Width: | Height: | Size: 905 B After Width: | Height: | Size: 905 B |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 839 B |
Before Width: | Height: | Size: 427 B After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 627 B After Width: | Height: | Size: 627 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 988 B After Width: | Height: | Size: 988 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 589 B |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 967 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 83 KiB |
After Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@ -1,23 +1,21 @@ |
|||
/** @odoo-module */ |
|||
//@odoo-modules
|
|||
|
|||
import { registry } from "@web/core/registry"; |
|||
import { download } from "@web/core/network/download"; |
|||
import framework from 'web.framework'; |
|||
import session from 'web.session'; |
|||
/** |
|||
* @override |
|||
* Add 'xlsx' report type to the report handler |
|||
*/ |
|||
|
|||
//report_type is added into a registry and checks report_type is ‘XLSX.’Then call the corresponding controller function
|
|||
registry.category("ir.actions.report handlers").add("xlsx", async (action) => { |
|||
if (action.report_type === 'xlsx') { |
|||
framework.blockUI(); |
|||
var def = $.Deferred(); |
|||
session.get_file({ |
|||
url: '/xlsx_reports', |
|||
data: action.data, |
|||
success: def.resolve.bind(def), |
|||
error: (error) => this.call('crash_manager', 'rpc_error', error), |
|||
complete: framework.unblockUI, |
|||
}); |
|||
return def; |
|||
} |
|||
}); |
|||
if (action.report_type === 'xlsx') { |
|||
framework.blockUI(); |
|||
var def = $.Deferred(); |
|||
session.get_file({ |
|||
url: '/xlsx_reports', |
|||
data: action.data, |
|||
success: def.resolve.bind(def), |
|||
error: (error) => this.call('crash_manager', 'rpc_error', error), |
|||
complete: framework.unblockUI, |
|||
}); |
|||
return def; |
|||
} |
|||
}) |
|||
|
@ -1,10 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<odoo> |
|||
<!-- Menu for manufacturing report--> |
|||
<menuitem id="menu_mrp_reports" |
|||
parent="mrp.menu_mrp_reporting" |
|||
name="Manufacturing Reports" |
|||
action="manufacturing_reports.mrp_report_action" |
|||
sequence="5"/> |
|||
|
|||
</odoo> |
@ -0,0 +1,175 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Javid A(<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################# |
|||
from odoo import fields, models |
|||
from odoo.tools import date_utils |
|||
from odoo.tools.safe_eval import json |
|||
|
|||
try: |
|||
from odoo.tools.misc import xlsxwriter |
|||
except ImportError: |
|||
import xlsxwriter |
|||
import io |
|||
|
|||
|
|||
class ManufacturingReport(models.TransientModel): |
|||
""" |
|||
This class creates a new model named manufacturing report and has the |
|||
fields to filter the report |
|||
""" |
|||
_name = 'manufacturing.report' |
|||
_description = 'Manufacturing Report' |
|||
|
|||
filter = fields.Boolean(string='Enable Filter by Date', |
|||
help='Enabling filter by date allows you to filter ' |
|||
'the records by date') |
|||
date_from = fields.Date(string='Start Date', |
|||
help='Filter by starting date') |
|||
filter_user = fields.Boolean(string='Filter On Responsible', |
|||
help='Enabling filter on responsible allows ' |
|||
'you to filter the records by ' |
|||
'responsible person') |
|||
responsible_ids = fields.Many2many('res.users', |
|||
string='Responsible', |
|||
help='Filter by Responsible Person') |
|||
product_ids = fields.Many2many('product.product', |
|||
string='Product', |
|||
help='Filter by Products') |
|||
state = fields.Selection( |
|||
[('confirmed', 'Confirmed'), ('planned', 'Planned'), |
|||
('progress', 'In Progress'), |
|||
('done', 'Done'), ('cancel', 'Cancelled')], string="State", |
|||
help='Filter by states') |
|||
|
|||
def fetch_data(self): |
|||
"""fetches the data and append to a list and returns it""" |
|||
conditions = [] |
|||
if self.product_ids: |
|||
conditions.append(('product_id', 'in', self.product_ids.ids)) |
|||
if self.state: |
|||
conditions.append(('state', '=', self.state)) |
|||
if self.date_from: |
|||
conditions.append(('date_planned_start', '>=', self.date_from)) |
|||
if self.responsible_ids: |
|||
conditions.append(('user_id', 'in', self.responsible_ids.ids)) |
|||
mrp_orders = self.env['mrp.production'].search(conditions) |
|||
return mrp_orders |
|||
|
|||
def action_print_xlsx(self): |
|||
"""Calls the fetch_data function and print the Excel report""" |
|||
mrp_orders = self.fetch_data() |
|||
orders = [{ |
|||
'name': rec.name, |
|||
'product': rec.product_id.name, |
|||
'quantity': rec.product_qty, |
|||
'unit': rec.product_uom_category_id.name, |
|||
'responsible': rec.user_id.name, |
|||
'start_date': rec.date_planned_start, |
|||
'state': rec.state, |
|||
} for rec in mrp_orders] |
|||
data = { |
|||
'date_from': self.date_from, |
|||
'state': self.state, |
|||
'mrp': orders |
|||
} |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'data': { |
|||
'model': 'manufacturing.report', |
|||
'options': json.dumps(data, default=date_utils.json_default), |
|||
'output_format': 'xlsx', |
|||
'report_name': 'Manufacturing Report', }, |
|||
'report_type': 'xlsx', |
|||
} |
|||
|
|||
def action_print_pdf(self): |
|||
"""Calls the fetch_data function and print the PDF report""" |
|||
mrp_orders = self.fetch_data() |
|||
orders = [{ |
|||
'name': rec.name, |
|||
'image': rec.product_id.image_1920, |
|||
'product': rec.product_id.name, |
|||
'quantity': rec.product_qty, |
|||
'unit': rec.product_uom_category_id.name, |
|||
'responsible': rec.user_id.name, |
|||
'start_date': rec.date_planned_start, |
|||
'state': rec.state, |
|||
} for rec in mrp_orders] |
|||
data = { |
|||
'date_from': self.date_from, |
|||
'state': self.state, |
|||
'mrp': orders |
|||
} |
|||
return self.env.ref( |
|||
'manufacturing_reports.action_report_mrp').report_action(self, |
|||
data=data) |
|||
|
|||
def get_xlsx_report(self, data, response): |
|||
""" |
|||
Set the rows and column for datas to print in Excel sheet |
|||
:param data: The records data |
|||
:param response: the corresponding response |
|||
:return: XLSX file |
|||
""" |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format({'font_size': '12px', 'bold': True}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '20px'}) |
|||
txt_head = workbook.add_format({'font_size': '12px'}) |
|||
sheet.set_column('B:B', 15) |
|||
sheet.set_column('C:C', 15) |
|||
sheet.set_column('D:D', 16) |
|||
sheet.set_column('E:E', 11) |
|||
sheet.set_column('F:F', 11) |
|||
sheet.set_column('G:G', 15) |
|||
sheet.set_column('H:H', 19) |
|||
sheet.set_column('I:I', 15) |
|||
sheet.merge_range('B2:H3', 'Manufacturing Orders', head) |
|||
if data['date_from']: |
|||
sheet.write('B6', 'From:', cell_format) |
|||
sheet.merge_range('C6:D6', data['date_from'], txt_head) |
|||
if data['state']: |
|||
sheet.write('B7', 'State:', cell_format) |
|||
sheet.merge_range('C7:D7', data['state'], txt_head) |
|||
row = 9 |
|||
col = 2 |
|||
sheet.write(row, col, 'Reference', cell_format) |
|||
sheet.write(row, col + 1, 'Product', cell_format) |
|||
sheet.write(row, col + 2, 'Quantity', cell_format) |
|||
sheet.write(row, col + 3, 'Unit', cell_format) |
|||
sheet.write(row, col + 4, 'Responsible', cell_format) |
|||
sheet.write(row, col + 5, 'Start Date', cell_format) |
|||
sheet.write(row, col + 6, 'State', cell_format) |
|||
for rec in data['mrp']: |
|||
row += 1 |
|||
sheet.write(row, col, rec['name']) |
|||
sheet.write(row, col + 1, rec['product']) |
|||
sheet.write(row, col + 2, rec['quantity']) |
|||
sheet.write(row, col + 3, rec['unit']) |
|||
sheet.write(row, col + 4, rec['responsible']) |
|||
sheet.write(row, col + 5, rec['start_date']) |
|||
sheet.write(row, col + 6, rec['state']) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |
@ -1,43 +1,39 @@ |
|||
<?xml version="1.0" encoding="utf-8" ?> |
|||
<odoo> |
|||
<!-- Form view for mrp.report--> |
|||
<record id="mrp_report_view_form" model="ir.ui.view"> |
|||
<field name="name">mrp.report.view.form</field> |
|||
<field name="model">mrp.report</field> |
|||
<record id="manufacturing_report_view_form" model="ir.ui.view"> |
|||
<field name="name">manufacturing.report.view.form</field> |
|||
<field name="model">manufacturing.report</field> |
|||
<field name="arch" type="xml"> |
|||
<form string="MRP Report"> |
|||
<group> |
|||
<group> |
|||
<field name="product_id" widget="many2many_tags"/> |
|||
<field name="product_ids" widget="many2many_tags"/> |
|||
<field name="filter"/> |
|||
<field name="date_from" |
|||
attrs="{'invisible': [('filter','=',False)], 'required': [('filter', '=', True)]}"/> |
|||
</group> |
|||
<group> |
|||
<field name="stage"/> |
|||
<field name="state"/> |
|||
<field name="filter_user"/> |
|||
<field name="responsible_id" widget="many2many_tags" |
|||
<field name="responsible_ids" widget="many2many_tags" |
|||
attrs="{'invisible': [('filter_user','=',False)], 'required': [('filter_user', '=', True)]}"/> |
|||
</group> |
|||
</group> |
|||
<footer> |
|||
<button name="check_report" string="Export xls" |
|||
type="object" class="oe_highlight" |
|||
icon='fa-download'/> |
|||
<button name="print_pdf" string="Print Pdf" type="object" |
|||
class="oe_highlight" icon='fa-download'/> |
|||
or |
|||
<button name="action_print_xlsx" string="Export XLSX" type="object" class="oe_highlight" icon='fa-download'/> |
|||
<button name="action_print_pdf" string="Print PDF" type="object" class="oe_highlight" icon='fa-download'/> |
|||
<button string="Cancel" class="oe_link" special="cancel"/> |
|||
</footer> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
<!-- Action for the mrp.report--> |
|||
<record id="mrp_report_action" model="ir.actions.act_window"> |
|||
<record id="manufacturing_report_action" model="ir.actions.act_window"> |
|||
<field name="name">MRP Report</field> |
|||
<field name="type">ir.actions.act_window</field> |
|||
<field name="res_model">mrp.report</field> |
|||
<field name="res_model">manufacturing.report</field> |
|||
<field name="view_mode">form</field> |
|||
<field name="target">new</field> |
|||
</record> |
|||
</odoo> |
|||
<menuitem id="manufacturing_report_menu" parent="mrp.menu_mrp_reporting" name="Manufacturing Reports" |
|||
action="manufacturing_report_action" sequence="5" groups="mrp.group_mrp_manager"/> |
|||
</odoo> |
@ -1,285 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Javid A (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import io |
|||
import xlsxwriter |
|||
from odoo import fields, models |
|||
from odoo.tools import date_utils |
|||
from odoo.tools.safe_eval import json |
|||
|
|||
|
|||
class MrpReport(models.TransientModel): |
|||
"""Class for the transient model mrp report.""" |
|||
_name = 'mrp.report' |
|||
_description = 'MRP Report' |
|||
|
|||
filter = fields.Boolean(string='Enable filter by date', |
|||
help='The reports can be filtered by date if ' |
|||
'enabled.') |
|||
date_from = fields.Date(string='Start Date', |
|||
help='Start date for the report data.') |
|||
filter_user = fields.Boolean(string='Filter On Responsible', |
|||
help='The reports can be filtered by ' |
|||
'responsible person, if enabled.') |
|||
responsible_id = fields.Many2many('res.users', string='Responsible', |
|||
help='Responsible person for the ' |
|||
'records.') |
|||
product_id = fields.Many2many('product.product', string='Product', |
|||
help='Id of the product in the manufacturing' |
|||
' order.') |
|||
stage = fields.Selection( |
|||
[('confirmed', 'Confirmed'), ('planned', 'Planned'), |
|||
('progress', 'In Progress'), |
|||
('done', 'Done'), ('cancel', 'Cancelled')], string="Filter State", |
|||
help='Stage of the manufacturing order.') |
|||
|
|||
def check_report(self): |
|||
""" |
|||
Function to fetch the mrp orders according to the filters given in |
|||
the wizard and print the XLS report |
|||
""" |
|||
orders = [] |
|||
if self.product_id and self.stage and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.stage and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.product_id and self.stage and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.stage and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.stage: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage)]) |
|||
elif self.product_id and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.product_id and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.stage and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.stage and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids)]) |
|||
elif self.stage: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage)]) |
|||
elif self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('date_planned_start', '>=', self.date_from)]) |
|||
elif self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('user_id', 'in', self.responsible_id.ids)]) |
|||
else: |
|||
mrp_orders = self.env['mrp.production'].search([]) |
|||
for rec in mrp_orders: |
|||
orders.append({ |
|||
'name': rec.name, |
|||
'product': rec.product_id.name, |
|||
'quantity': rec.product_qty, |
|||
'unit': rec.product_uom_category_id.name, |
|||
'responsible': rec.user_id.name, |
|||
'start_date': rec.date_planned_start, |
|||
'state': rec.state, |
|||
}) |
|||
print('orders', orders) |
|||
data = { |
|||
'date_from': self.date_from, |
|||
'stage': self.stage, |
|||
'mrp': orders |
|||
} |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'data': { |
|||
'model': 'mrp.report', |
|||
'options': json.dumps(data, default=date_utils.json_default), |
|||
'output_format': 'xlsx', |
|||
'report_name': 'Manufacturing Report', }, |
|||
'report_type': 'xlsx', |
|||
} |
|||
|
|||
def print_pdf(self): |
|||
""" |
|||
Function to fetch the mrp orders according to the filters given in |
|||
the wizard and print the PDF report |
|||
""" |
|||
orders = [] |
|||
if self.product_id and self.stage and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.stage and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.product_id and self.stage and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.stage and self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id and self.stage: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('state', '=', self.stage)]) |
|||
elif self.product_id and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.product_id and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.stage and self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('date_planned_start', '>=', self.date_from)]) |
|||
elif self.stage and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.date_from and self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('date_planned_start', '>=', self.date_from), |
|||
('user_id', 'in', self.responsible_id.ids)]) |
|||
elif self.product_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('product_id', 'in', self.product_id.ids)]) |
|||
elif self.stage: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('state', '=', self.stage)]) |
|||
elif self.date_from: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('date_planned_start', '>=', self.date_from)]) |
|||
elif self.responsible_id: |
|||
mrp_orders = self.env['mrp.production'].search( |
|||
[('user_id', 'in', self.responsible_id.ids)]) |
|||
else: |
|||
mrp_orders = self.env['mrp.production'].search([]) |
|||
for rec in mrp_orders: |
|||
orders.append({ |
|||
'name': rec.name, |
|||
'image': rec.product_id.image_1920, |
|||
'product': rec.product_id.name, |
|||
'quantity': rec.product_qty, |
|||
'unit': rec.product_uom_category_id.name, |
|||
'responsible': rec.user_id.name, |
|||
'start_date': rec.date_planned_start, |
|||
'state': rec.state, |
|||
}) |
|||
data = { |
|||
'date_from': self.date_from, |
|||
'stage': self.stage, |
|||
'mrp': orders |
|||
} |
|||
return self.env.ref( |
|||
'manufacturing_reports.action_mrp_report').report_action(self, |
|||
data=data) |
|||
|
|||
def get_xlsx_report(self, data, response): |
|||
print('get_xlsx_report(self, data, response)') |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format({'font_size': '12px', 'bold': True}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '20px'}) |
|||
txt_head = workbook.add_format({'font_size': '12px'}) |
|||
sheet.set_column('B:B', 15) |
|||
sheet.set_column('C:C', 15) |
|||
sheet.set_column('D:D', 16) |
|||
sheet.set_column('E:E', 11) |
|||
sheet.set_column('F:F', 11) |
|||
sheet.set_column('G:G', 15) |
|||
sheet.set_column('H:H', 19) |
|||
sheet.set_column('I:I', 15) |
|||
sheet.merge_range('B2:H3', 'Manufacturing Orders', head) |
|||
if data['date_from']: |
|||
sheet.write('B6', 'From:', cell_format) |
|||
sheet.merge_range('C6:D6', data['date_from'], txt_head) |
|||
if data['stage']: |
|||
sheet.write('B7', 'State:', cell_format) |
|||
sheet.merge_range('C7:D7', data['stage'], txt_head) |
|||
row = 9 |
|||
col = 2 |
|||
sheet.write(row, col, 'Reference', cell_format) |
|||
sheet.write(row, col + 1, 'Product', cell_format) |
|||
sheet.write(row, col + 2, 'Quantity', cell_format) |
|||
sheet.write(row, col + 3, 'Unit', cell_format) |
|||
sheet.write(row, col + 4, 'Responsible', cell_format) |
|||
sheet.write(row, col + 5, 'Start Date', cell_format) |
|||
sheet.write(row, col + 6, 'State', cell_format) |
|||
for rec in data['mrp']: |
|||
row += 1 |
|||
sheet.write(row, col, rec['name']) |
|||
sheet.write(row, col + 1, rec['product']) |
|||
sheet.write(row, col + 2, rec['quantity']) |
|||
sheet.write(row, col + 3, rec['unit']) |
|||
sheet.write(row, col + 4, rec['responsible']) |
|||
sheet.write(row, col + 5, rec['start_date']) |
|||
sheet.write(row, col + 6, rec['state']) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |