Commit d42f6d4a by Yvon Kerdoncuff

#7095 export compta : do required changes due to account_report now generating…

#7095 export compta : do required changes due to account_report now generating xlsx and not csv, show full traceback for easier debugging, adapt js to new response type of create_report
parent c0243ebb
Pipeline #3945 failed with stage
in 0 seconds
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
from outils.common import OdooAPI from outils.common import OdooAPI
import base64 import base64
import logging import logging
from openpyxl import load_workbook
from io import BytesIO
coop_logger = logging.getLogger("coop.framework") coop_logger = logging.getLogger("coop.framework")
...@@ -208,23 +210,25 @@ def process_received_lines(received_data, coops, full_sumup=False): ...@@ -208,23 +210,25 @@ def process_received_lines(received_data, coops, full_sumup=False):
def generate_arithmethique_compatible_file (report): def generate_arithmethique_compatible_file (report):
coop_ids = [] coop_ids = []
received_data = [] received_data = []
content = base64.b64decode(report['datas']).decode('utf-8')
xlsx_content = base64.b64decode(report['datas'])
for line in content.split("\r\n"): excel_file = BytesIO(xlsx_content)
items = line.split(';') workbook = load_workbook(excel_file, read_only=True)
if len(items) == 8: sheet = workbook.active
if (items[4].isnumeric() and items[0] != 'VEN'):
if not (items[4] in coop_ids): #use min_row = 2 to skip headers
coop_ids.append(items[4]) for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, values_only=True):
if (items[3] == '409600'): row = [str(item) for item in row]
items[3] == '419600' if len(row) == 8:
if not (items[0] == 'CAP' and items[3] == '101300' and if row[4] and row[4].isnumeric() and row[0] != 'VEN':
items[5] != ""): if not (row[4] in coop_ids):
received_data.append(items) coop_ids.append(row[4])
if not (row[0] == 'CAP' and row[3] == '101300' and row[5] != ""):
received_data.append(row)
coops = retrieve_odoo_coop_data(coop_ids) coops = retrieve_odoo_coop_data(coop_ids)
summarized_lines = process_received_lines(received_data, coops) summarized_lines = process_received_lines(received_data, coops)
res = make_csv_content_from_lines(summarized_lines) res = make_csv_content_from_lines(summarized_lines)
file_path = 'data/' + report['name'] file_path = 'data/' + report['name'].replace(".xlsx", ".csv")
file = open(file_path, 'wb') file = open(file_path, 'wb')
file.write(res['csv_content']) file.write(res['csv_content'])
file.close() file.close()
...@@ -237,23 +241,25 @@ def generate_quadratus_compatible_file(report): ...@@ -237,23 +241,25 @@ def generate_quadratus_compatible_file(report):
import io import io
coop_ids = [] coop_ids = []
received_data = [] received_data = []
content = base64.b64decode(report['datas']).decode('utf-8')
# content = '' xlsx_content = base64.b64decode(report['datas'])
# with open('outils/exportMaiComptesCorriges.csv', "r", encoding='utf-8') as csvfile: excel_file = BytesIO(xlsx_content)
# content = csvfile.read() workbook = load_workbook(excel_file, read_only=True)
for line in content.split("\n"): sheet = workbook.active
# for line in content.split("\r\n"):
items = line.split(';') #use min_row = 2 to skip headers
if len(items) == 8: for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, values_only=True):
if (items[4].isnumeric() and items[0] != 'VEN'): row = [str(item) for item in row]
if not (items[4] in coop_ids): if len(row) == 8:
coop_ids.append(items[4]) if row[4] and row[4].isnumeric() and row[0] != 'VEN':
received_data.append(items) if not (row[4] in coop_ids):
coop_ids.append(row[4])
received_data.append(row)
coops = retrieve_odoo_coop_data(coop_ids) coops = retrieve_odoo_coop_data(coop_ids)
summarized_lines = process_received_lines(received_data, coops, True) summarized_lines = process_received_lines(received_data, coops, True)
res = generate_quadratus_file(summarized_lines) res = generate_quadratus_file(summarized_lines)
files = [] files = []
fsuffix = report['name'].replace(".csv", ".txt") fsuffix = report['name'].replace(".xlsx", ".txt")
if len(res['V']) > 0: if len(res['V']) > 0:
vfn = 'data/ventes_' + fsuffix vfn = 'data/ventes_' + fsuffix
vf = open(vfn, 'wb') vf = open(vfn, 'wb')
...@@ -267,7 +273,7 @@ def generate_quadratus_compatible_file(report): ...@@ -267,7 +273,7 @@ def generate_quadratus_compatible_file(report):
kf.close() kf.close()
files.append(kfn) files.append(kfn)
file_path = 'data/' + report['name'].replace(".csv", ".zip") file_path = 'data/' + report['name'].replace(".xlsx", ".zip")
with zipfile.ZipFile(file_path, 'w') as zipf: with zipfile.ZipFile(file_path, 'w') as zipf:
for f in files: for f in files:
zipf.write(f) zipf.write(f)
......
...@@ -25,7 +25,7 @@ jQuery(document).ready(function($) { ...@@ -25,7 +25,7 @@ jQuery(document).ready(function($) {
dataType :'json' dataType :'json'
}) })
.done(function(rData) { .done(function(rData) {
if (rData.response && rData.response == true) { if (rData.response) {
newWaitingMessage('Le document Odoo est terminé.<br/>Les ventes journalières sont compilées et les identifiants de coop. substitués.'); newWaitingMessage('Le document Odoo est terminé.<br/>Les ventes journalières sont compilées et les identifiants de coop. substitués.');
$.ajax({url : url + '?phase=2&export_id='+export_id+ '&final_format=' + $('[name="final_format"]').val(), $.ajax({url : url + '?phase=2&export_id='+export_id+ '&final_format=' + $('[name="final_format"]').val(),
dataType :'json' dataType :'json'
......
...@@ -17,6 +17,8 @@ from openpyxl import Workbook ...@@ -17,6 +17,8 @@ from openpyxl import Workbook
from openpyxl.writer.excel import save_virtual_workbook from openpyxl.writer.excel import save_virtual_workbook
from orders.models import Orders from orders.models import Orders
import traceback
def test_compta(request): def test_compta(request):
generate_quadratus_compatible_file('bidon') generate_quadratus_compatible_file('bidon')
...@@ -127,8 +129,9 @@ class ExportCompta(View): ...@@ -127,8 +129,9 @@ class ExportCompta(View):
response = JsonResponse({'response': val}) response = JsonResponse({'response': val})
except Exception as e: except Exception as e:
val = str(e) # Capture the full stack trace
response = JsonResponse({'error': val}) stack_trace = traceback.format_exc()
response = JsonResponse({'error': str(e), 'stack_trace': stack_trace})
return response return response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment