Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
31e0ecb2
Commit
31e0ecb2
authored
Jul 10, 2021
by
François C.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better save reception errors report logs
parent
86219535
Pipeline
#1195
passed with stage
in 1 minute 21 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
37 deletions
+51
-37
reception_index.js
reception/static/js/reception_index.js
+1
-1
views.py
reception/views.py
+50
-36
No files found.
reception/static/js/reception_index.js
View file @
31e0ecb2
...
...
@@ -212,7 +212,7 @@ function validatePrices() {
var
updates
=
{
'group_amount_total'
:
order
[
'amount_total'
],
'update_type'
:
'br_vaid'
,
'update_type'
:
'br_va
l
id'
,
'updated_products'
:
[],
'user_comments'
:
""
,
'orders'
:
[
order
]
...
...
reception/views.py
View file @
31e0ecb2
...
...
@@ -259,54 +259,59 @@ def save_error_report(request):
save it to an excel file,
attach file to order in odoo
"""
if
request
.
is_ajax
():
if
request
.
method
==
'POST'
:
data
=
None
try
:
myJson
=
request
.
body
data
=
json
.
loads
(
myJson
.
decode
())
except
Exception
as
e1
:
coop_logger
.
error
(
"Save reception report : Unable to load data
%
s (
%
s)"
,
str
(
e1
),
str
(
myJson
))
temp_files_name
=
[]
orders_name
=
""
if
data
and
(
'orders'
in
data
):
orders_name
_elts
=
[]
orders_partner
=
""
group_ids
=
[]
try
:
for
i
,
order
in
enumerate
(
data
[
'orders'
])
:
# list of temp files: 1 report per order & group
data
[
'orders'
][
i
][
'temp_file_name'
]
=
"temp/"
+
order
[
'name'
]
+
"_rapport-reception_temp.xlsx"
group_ids
.
append
(
order
[
'id'
])
# Concatenate orders name
if
orders_name
!=
""
:
orders_name
=
orders_name
+
'-'
orders_name
=
orders_name
+
order
[
'name'
]
orders_name_elts
.
append
(
order
[
'name'
])
# Concatenate orders partner
if
order
[
'partner'
]
!=
orders_partner
:
if
orders_partner
!=
""
:
if
order
[
'partner'
]
!=
orders_partner
:
if
orders_partner
!=
""
:
orders_partner
=
orders_partner
+
', '
orders_partner
=
orders_partner
+
order
[
'partner'
]
+
' du '
+
order
[
'date_order'
]
# If group of orders
if
len
(
data
[
'orders'
])
>
1
:
if
len
(
data
[
'orders'
])
>
1
:
orders_name
=
'-'
.
join
(
orders_name_elts
)
temp_group_file_name
=
"temp/"
+
orders_name
+
"_rapport-reception_temp.xlsx"
# Add group in data['orders']
group_order
=
{
'name'
:
orders_name
,
'partner'
:
orders_partner
,
'date_order'
:
data
[
'orders'
][
0
][
'date_order'
],
'amount_total'
:
data
[
'group_amount_total'
],
'updated_products'
:
data
[
'updated_products'
],
'temp_file_name'
:
temp_group_file_name
,
'group_ids'
:
group_ids
'name'
:
orders_name
,
'partner'
:
orders_partner
,
'date_order'
:
data
[
'orders'
][
0
][
'date_order'
],
'amount_total'
:
data
[
'group_amount_total'
],
'updated_products'
:
data
[
'updated_products'
],
'temp_file_name'
:
temp_group_file_name
,
'group_ids'
:
group_ids
}
data
[
'orders'
]
.
append
(
group_order
)
except
Exception
as
e2
:
coop_logger
.
error
(
"Save reception report : Error while create group_order
%
s"
,
str
(
e2
))
# Save qties & comments after step 1
if
data
[
'update_type'
]
==
'qty_valid'
:
for
order
in
data
[
'orders'
]:
try
:
wb
=
Workbook
()
ws
=
wb
.
active
ws
.
title
=
"Commande "
+
order
[
'name'
]
...
...
@@ -321,8 +326,8 @@ def save_error_report(request):
'supplier_shortage'
])
# If in group add group name
if
len
(
data
[
'orders'
])
>
1
:
ws
.
append
(
[
'group'
,
orders_name
]
)
if
len
(
data
[
'orders'
])
>
1
:
ws
.
append
([
'group'
,
orders_name
]
)
try
:
if
'updated_products'
in
order
:
for
product
in
order
[
'updated_products'
]:
...
...
@@ -338,17 +343,17 @@ def save_error_report(request):
else
:
supplier_shortage
=
''
ws
.
append
(
[
'produit'
,
ws
.
append
(
[
'produit'
,
product
[
'product_id'
][
1
],
supplier_code
,
str
(
product
[
'barcode'
]),
product
[
'old_qty'
],
product
[
'product_qty'
],
product
[
'price_unit'
],
supplier_shortage
]
)
supplier_shortage
]
)
except
Exception
as
exp
:
print
(
"Error while updating products"
)
print
(
exp
)
coop_logger
.
error
(
"Error while updating products in report :
%
s"
,
str
(
exp
)
)
if
(
'user_comments'
in
data
)
and
data
[
'user_comments'
]
!=
""
:
ws
.
append
(
[
'commentaire'
,
data
[
'user_comments'
]]
)
else
:
...
...
@@ -356,7 +361,8 @@ def save_error_report(request):
# Save file
wb
.
save
(
filename
=
order
[
'temp_file_name'
])
except
Exception
as
e3
:
coop_logger
.
error
(
"Save reception report : Error while create order Workbook
%
s"
,
str
(
e3
))
# Create report with data from steps 1 & 2
...
...
@@ -385,13 +391,14 @@ def save_error_report(request):
'supplier_shortage'
:
row
[
7
]
}
elif
row
[
0
]
==
'group'
:
group_name
=
row
[
1
]
# group's orders name
group_name
=
row
[
1
]
# group's orders name
: Unused
elif
row
[
0
]
==
'commentaire'
:
data_comment_s1
=
row
[
1
]
# user comments
# Clear step 1 temp file
os
.
remove
(
order
[
'temp_file_name'
])
except
:
except
Exception
as
e4
:
coop_logger
.
error
(
"Save reception report : reloading first step xlsx file
%
s"
,
str
(
e4
))
data_comment_s1
=
"Données de la première étape absentes !"
# Add data from step 2
...
...
@@ -450,13 +457,13 @@ def save_error_report(request):
error_total_abs
+=
abs
(
item
[
'error_line'
])
data_full
.
append
(
item
)
except
Exception
as
exp
:
except
Exception
as
e5
:
coop_logger
.
error
(
"Save reception report : Error while updating products
%
s"
,
str
(
e5
))
# no updated products, do nothing
print
(
"Error while updating products"
)
print
(
exp
)
# Add remaining products, the ones edited only in step 1
for
product
in
data_qties
.
values
():
try
:
item
=
{
'product_id'
:
product
[
'nom_contenu'
],
'product_supplier_code'
:
product
[
'supplier_code'
],
...
...
@@ -474,7 +481,9 @@ def save_error_report(request):
error_total_abs
+=
abs
(
item
[
'error_line'
])
data_full
.
append
(
item
)
except
Exception
as
e6
:
coop_logger
.
error
(
"Save reception report : Error while creating item from product
%
s (
%
s)"
,
str
(
e6
),
str
(
e6
))
try
:
# Sort by error amount
def
sortByError
(
e
):
return
abs
(
e
[
'error_line'
])
...
...
@@ -567,23 +576,28 @@ def save_error_report(request):
length
=
20
ws
.
column_dimensions
[
column_cells
[
3
]
.
column_letter
]
.
width
=
length
except
Exception
as
e7
:
coop_logger
.
error
(
"PO save report : error while creating final Workbook
%
s"
,
str
(
e7
))
# Save file
fileName
=
"temp/"
+
order
[
'name'
]
+
"_rapport-reception.xlsx"
try
:
wb
.
save
(
filename
=
fileName
)
except
Exception
as
exp
:
print
(
"Error while saving file
%
s"
%
fileName
)
print
(
str
(
exp
))
#Attach file to order
if
'group_ids'
in
order
:
# group report
if
'group_ids'
in
order
:
# group report
# Attach group report to each order
for
group_item_id
in
order
[
'group_ids'
]
:
for
group_item_id
in
order
[
'group_ids'
]
:
m
=
CagetteReception
(
group_item_id
)
m
.
attach_file
(
fileName
,
False
)
os
.
remove
(
fileName
)
else
:
m
=
CagetteReception
(
order
[
'id'
])
m
.
attach_file
(
fileName
)
except
Exception
as
e8
:
coop_logger
.
error
(
"PO save report Error while saving file
%
s (
%
s)"
,
fileName
,
str
(
e8
))
else
:
coop_logger
.
error
(
"Cant find 'orders' in data (
%
s)"
,
str
(
data
))
else
:
coop_logger
.
info
(
"Was waiting for a POST method (
%
s)"
,
str
(
request
.
method
))
return
JsonResponse
(
"ok"
,
safe
=
False
)
def
reception_FAQ
(
request
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment