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 @@
from outils.common import OdooAPI
import base64
import logging
from openpyxl import load_workbook
from io import BytesIO
coop_logger = logging.getLogger("coop.framework")
......@@ -208,23 +210,25 @@ def process_received_lines(received_data, coops, full_sumup=False):
def generate_arithmethique_compatible_file (report):
coop_ids = []
received_data = []
content = base64.b64decode(report['datas']).decode('utf-8')
for line in content.split("\r\n"):
items = line.split(';')
if len(items) == 8:
if (items[4].isnumeric() and items[0] != 'VEN'):
if not (items[4] in coop_ids):
coop_ids.append(items[4])
if (items[3] == '409600'):
items[3] == '419600'
if not (items[0] == 'CAP' and items[3] == '101300' and
items[5] != ""):
received_data.append(items)
xlsx_content = base64.b64decode(report['datas'])
excel_file = BytesIO(xlsx_content)
workbook = load_workbook(excel_file, read_only=True)
sheet = workbook.active
#use min_row = 2 to skip headers
for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, values_only=True):
row = [str(item) for item in row]
if len(row) == 8:
if row[4] and row[4].isnumeric() and row[0] != 'VEN':
if not (row[4] in coop_ids):
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)
summarized_lines = process_received_lines(received_data, coops)
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.write(res['csv_content'])
file.close()
......@@ -237,23 +241,25 @@ def generate_quadratus_compatible_file(report):
import io
coop_ids = []
received_data = []
content = base64.b64decode(report['datas']).decode('utf-8')
# content = ''
# with open('outils/exportMaiComptesCorriges.csv', "r", encoding='utf-8') as csvfile:
# content = csvfile.read()
for line in content.split("\n"):
# for line in content.split("\r\n"):
items = line.split(';')
if len(items) == 8:
if (items[4].isnumeric() and items[0] != 'VEN'):
if not (items[4] in coop_ids):
coop_ids.append(items[4])
received_data.append(items)
xlsx_content = base64.b64decode(report['datas'])
excel_file = BytesIO(xlsx_content)
workbook = load_workbook(excel_file, read_only=True)
sheet = workbook.active
#use min_row = 2 to skip headers
for row in sheet.iter_rows(min_row=2, max_row=sheet.max_row, values_only=True):
row = [str(item) for item in row]
if len(row) == 8:
if row[4] and row[4].isnumeric() and row[0] != 'VEN':
if not (row[4] in coop_ids):
coop_ids.append(row[4])
received_data.append(row)
coops = retrieve_odoo_coop_data(coop_ids)
summarized_lines = process_received_lines(received_data, coops, True)
res = generate_quadratus_file(summarized_lines)
files = []
fsuffix = report['name'].replace(".csv", ".txt")
fsuffix = report['name'].replace(".xlsx", ".txt")
if len(res['V']) > 0:
vfn = 'data/ventes_' + fsuffix
vf = open(vfn, 'wb')
......@@ -267,7 +273,7 @@ def generate_quadratus_compatible_file(report):
kf.close()
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:
for f in files:
zipf.write(f)
......
......@@ -25,7 +25,7 @@ jQuery(document).ready(function($) {
dataType :'json'
})
.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.');
$.ajax({url : url + '?phase=2&export_id='+export_id+ '&final_format=' + $('[name="final_format"]').val(),
dataType :'json'
......
......@@ -17,6 +17,8 @@ from openpyxl import Workbook
from openpyxl.writer.excel import save_virtual_workbook
from orders.models import Orders
import traceback
def test_compta(request):
generate_quadratus_compatible_file('bidon')
......@@ -127,8 +129,9 @@ class ExportCompta(View):
response = JsonResponse({'response': val})
except Exception as e:
val = str(e)
response = JsonResponse({'error': val})
# Capture the full stack trace
stack_trace = traceback.format_exc()
response = JsonResponse({'error': str(e), 'stack_trace': stack_trace})
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