mirror of
https://gitlab.com/flectra-community/devops/odoo-2-flectra-converter.git
synced 2025-08-14 14:45:41 +00:00
[ADD] stock_mrp_kit_product_short_availability
This commit is contained in:
7
odoo/ks_dashboard_ninja/controllers/__init__.py
Normal file
7
odoo/ks_dashboard_ninja/controllers/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import ks_chart_export
|
||||
from . import ks_list_export
|
||||
from . import ks_dashboard_export
|
||||
|
||||
# Pleas pycharm commit this file. PARTY HOGI
|
134
odoo/ks_dashboard_ninja/controllers/ks_chart_export.py
Normal file
134
odoo/ks_dashboard_ninja/controllers/ks_chart_export.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import datetime
|
||||
import io
|
||||
import json
|
||||
import operator
|
||||
import re
|
||||
|
||||
from odoo import http
|
||||
from odoo.addons.web.controllers.main import ExportFormat, serialize_exception
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.http import content_disposition, request
|
||||
from odoo.tools import pycompat
|
||||
from odoo.tools.misc import xlwt
|
||||
from odoo.tools.translate import _
|
||||
|
||||
|
||||
class KsChartExport(ExportFormat, http.Controller):
|
||||
|
||||
def base(self, data, token):
|
||||
params = json.loads(data)
|
||||
header,chart_data = operator.itemgetter('header','chart_data')(params)
|
||||
|
||||
chart_data = json.loads(chart_data)
|
||||
chart_data['labels'].insert(0,'Measure')
|
||||
columns_headers = chart_data['labels']
|
||||
|
||||
import_data = []
|
||||
for dataset in chart_data['datasets']:
|
||||
dataset['data'].insert(0, dataset['label'])
|
||||
import_data.append(dataset['data'])
|
||||
return request.make_response(self.from_data(columns_headers, import_data),
|
||||
headers=[('Content-Disposition',
|
||||
content_disposition(self.filename(header))),
|
||||
('Content-Type', self.content_type)],
|
||||
cookies={'fileToken': token})
|
||||
|
||||
|
||||
class KsChartExcelExport(KsChartExport, http.Controller):
|
||||
|
||||
# Excel needs raw data to correctly handle numbers and date values
|
||||
raw_data = True
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/chart_xls', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'application/vnd.ms-excel'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.xls'
|
||||
|
||||
def from_data(self, fields, rows):
|
||||
if len(rows) > 65535:
|
||||
raise UserError(_
|
||||
('There are too many rows (%s rows, limit: 65535) to export as Excel 97-2003 (.xls) format. Consider splitting the export.') % len
|
||||
(rows))
|
||||
|
||||
workbook = xlwt.Workbook()
|
||||
worksheet = workbook.add_sheet('Sheet 1')
|
||||
|
||||
for i, fieldname in enumerate(fields):
|
||||
worksheet.write(0, i, fieldname)
|
||||
worksheet.col(i).width = 8000 # around 220 pixels
|
||||
|
||||
base_style = xlwt.easyxf('align: wrap yes')
|
||||
date_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD')
|
||||
datetime_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD HH:mm:SS')
|
||||
|
||||
for row_index, row in enumerate(rows):
|
||||
for cell_index, cell_value in enumerate(row):
|
||||
cell_style = base_style
|
||||
|
||||
if isinstance(cell_value, bytes) and not isinstance(cell_value, pycompat.string_types):
|
||||
# because xls uses raw export, we can get a bytes object
|
||||
# here. xlwt does not support bytes values in Python 3 ->
|
||||
# assume this is base64 and decode to a string, if this
|
||||
# fails note that you can't export
|
||||
try:
|
||||
cell_value = pycompat.to_text(cell_value)
|
||||
except UnicodeDecodeError:
|
||||
raise UserError(_
|
||||
("Binary fields can not be exported to Excel unless their content is base64-encoded. That does not seem to be the case for %s.") % fields[cell_index])
|
||||
|
||||
if isinstance(cell_value, pycompat.string_types):
|
||||
cell_value = re.sub("\r", " ", pycompat.to_text(cell_value))
|
||||
# Excel supports a maximum of 32767 characters in each cell:
|
||||
cell_value = cell_value[:32767]
|
||||
elif isinstance(cell_value, datetime.datetime):
|
||||
cell_style = datetime_style
|
||||
elif isinstance(cell_value, datetime.date):
|
||||
cell_style = date_style
|
||||
worksheet.write(row_index + 1, cell_index, cell_value, cell_style)
|
||||
|
||||
fp = io.BytesIO()
|
||||
workbook.save(fp)
|
||||
fp.seek(0)
|
||||
data = fp.read()
|
||||
fp.close()
|
||||
return data
|
||||
|
||||
|
||||
class KsChartCsvExport(KsChartExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/chart_csv', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.csv'
|
||||
|
||||
def from_data(self, fields, rows):
|
||||
fp = io.BytesIO()
|
||||
writer = pycompat.csv_writer(fp, quoting=1)
|
||||
|
||||
writer.writerow(fields)
|
||||
|
||||
for data in rows:
|
||||
row = []
|
||||
for d in data:
|
||||
# Spreadsheet apps tend to detect formulas on leading =, + and -
|
||||
if isinstance(d, pycompat.string_types) and d.startswith(('=', '-', '+')):
|
||||
d = "'" + d
|
||||
|
||||
row.append(pycompat.to_text(d))
|
||||
writer.writerow(row)
|
||||
|
||||
return fp.getvalue()
|
65
odoo/ks_dashboard_ninja/controllers/ks_dashboard_export.py
Normal file
65
odoo/ks_dashboard_ninja/controllers/ks_dashboard_export.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import io
|
||||
import json
|
||||
import operator
|
||||
|
||||
from odoo.addons.web.controllers.main import ExportFormat,serialize_exception
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import content_disposition,request
|
||||
|
||||
|
||||
class KsDashboardExport(ExportFormat, http.Controller):
|
||||
|
||||
def base(self, data, token):
|
||||
params = json.loads(data)
|
||||
header, dashboard_data = operator.itemgetter('header', 'dashboard_data')(params)
|
||||
return request.make_response(self.from_data(dashboard_data),
|
||||
headers=[('Content-Disposition',
|
||||
content_disposition(self.filename(header))),
|
||||
('Content-Type', self.content_type)],
|
||||
cookies={'fileToken': token})
|
||||
|
||||
|
||||
class KsDashboardJsonExport(KsDashboardExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/dashboard_json', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.json'
|
||||
|
||||
def from_data(self, dashboard_data):
|
||||
fp = io.StringIO()
|
||||
fp.write(json.dumps(dashboard_data))
|
||||
|
||||
return fp.getvalue()
|
||||
|
||||
class KsItemJsonExport(KsDashboardExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/item_json', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
data = json.loads(data)
|
||||
item_id = data["item_id"]
|
||||
data['dashboard_data'] = request.env['ks_dashboard_ninja.board'].ks_export_item(item_id)
|
||||
data = json.dumps(data)
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.json'
|
||||
|
||||
def from_data(self, dashboard_data):
|
||||
fp = io.StringIO()
|
||||
fp.write(json.dumps(dashboard_data))
|
||||
|
||||
return fp.getvalue()
|
133
odoo/ks_dashboard_ninja/controllers/ks_list_export.py
Normal file
133
odoo/ks_dashboard_ninja/controllers/ks_list_export.py
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
import re
|
||||
import datetime
|
||||
import io
|
||||
import json
|
||||
import operator
|
||||
|
||||
from odoo.addons.web.controllers.main import ExportFormat,serialize_exception
|
||||
from odoo.tools.translate import _
|
||||
from odoo import http
|
||||
from odoo.http import content_disposition, request
|
||||
from odoo.tools.misc import xlwt
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class KsListExport(ExportFormat, http.Controller):
|
||||
|
||||
def base(self, data, token):
|
||||
params = json.loads(data)
|
||||
header, list_data = operator.itemgetter('header', 'chart_data')(params)
|
||||
list_data = json.loads(list_data)
|
||||
columns_headers = list_data['label']
|
||||
import_data = []
|
||||
|
||||
for dataset in list_data['data_rows']:
|
||||
import_data.append(dataset['data'])
|
||||
|
||||
return request.make_response(self.from_data(columns_headers, import_data),
|
||||
headers=[('Content-Disposition',
|
||||
content_disposition(self.filename(header))),
|
||||
('Content-Type', self.content_type)],
|
||||
cookies={'fileToken': token})
|
||||
|
||||
|
||||
class KsChartExcelExport(KsListExport, http.Controller):
|
||||
|
||||
# Excel needs raw data to correctly handle numbers and date values
|
||||
raw_data = True
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/list_xls', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'application/vnd.ms-excel'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.xls'
|
||||
|
||||
def from_data(self, fields, rows):
|
||||
if len(rows) > 65535:
|
||||
raise UserError(_
|
||||
('There are too many rows (%s rows, limit: 65535) to export as Excel 97-2003 (.xls) format. Consider splitting the export.') % len
|
||||
(rows))
|
||||
|
||||
workbook = xlwt.Workbook()
|
||||
worksheet = workbook.add_sheet('Sheet 1')
|
||||
|
||||
for i, fieldname in enumerate(fields):
|
||||
worksheet.write(0, i, fieldname)
|
||||
worksheet.col(i).width = 8000 # around 220 pixels
|
||||
|
||||
base_style = xlwt.easyxf('align: wrap yes')
|
||||
date_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD')
|
||||
datetime_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD HH:mm:SS')
|
||||
|
||||
for row_index, row in enumerate(rows):
|
||||
for cell_index, cell_value in enumerate(row):
|
||||
cell_style = base_style
|
||||
|
||||
if isinstance(cell_value, bytes) and not isinstance(cell_value, pycompat.string_types):
|
||||
# because xls uses raw export, we can get a bytes object
|
||||
# here. xlwt does not support bytes values in Python 3 ->
|
||||
# assume this is base64 and decode to a string, if this
|
||||
# fails note that you can't export
|
||||
try:
|
||||
cell_value = pycompat.to_text(cell_value)
|
||||
except UnicodeDecodeError:
|
||||
raise UserError(_
|
||||
("Binary fields can not be exported to Excel unless their content is base64-encoded. That does not seem to be the case for %s.") % fields[cell_index])
|
||||
|
||||
if isinstance(cell_value, pycompat.string_types):
|
||||
cell_value = re.sub("\r", " ", pycompat.to_text(cell_value))
|
||||
# Excel supports a maximum of 32767 characters in each cell:
|
||||
cell_value = cell_value[:32767]
|
||||
elif isinstance(cell_value, datetime.datetime):
|
||||
cell_style = datetime_style
|
||||
elif isinstance(cell_value, datetime.date):
|
||||
cell_style = date_style
|
||||
worksheet.write(row_index + 1, cell_index, cell_value, cell_style)
|
||||
|
||||
fp = io.BytesIO()
|
||||
workbook.save(fp)
|
||||
fp.seek(0)
|
||||
data = fp.read()
|
||||
fp.close()
|
||||
return data
|
||||
|
||||
|
||||
class KsChartCsvExport(KsListExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/list_csv', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.csv'
|
||||
|
||||
def from_data(self, fields, rows):
|
||||
fp = io.BytesIO()
|
||||
writer = pycompat.csv_writer(fp, quoting=1)
|
||||
|
||||
writer.writerow(fields)
|
||||
|
||||
for data in rows:
|
||||
row = []
|
||||
for d in data:
|
||||
# Spreadsheet apps tend to detect formulas on leading =, + and -
|
||||
if isinstance(d, pycompat.string_types) and d.startswith(('=', '-', '+')):
|
||||
d = "'" + d
|
||||
|
||||
row.append(pycompat.to_text(d))
|
||||
writer.writerow(row)
|
||||
|
||||
return fp.getvalue()
|
Reference in New Issue
Block a user