Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emgidi_export_intercom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Le Filament
emgidi
emgidi_export_intercom
Commits
fd2cfa6e
Commit
fd2cfa6e
authored
9 months ago
by
Thibaud - Le Filament
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] Refactor account.move.line filtering in controller
parent
3f99de09
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
controllers/main.py
+36
-92
36 additions, 92 deletions
controllers/main.py
datas/export_intercom_datas.xml
+11
-7
11 additions, 7 deletions
datas/export_intercom_datas.xml
with
47 additions
and
99 deletions
controllers/main.py
+
36
−
92
View file @
fd2cfa6e
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import
csv
import
csv
from
datetime
import
date
,
datetime
from
datetime
import
date
,
datetime
from
io
import
BytesIO
,
StringIO
from
io
import
BytesIO
,
StringIO
from
odoo.addons.lefilament_export_journal_tool.controllers.main
import
JournalDatasExport
from
odoo
import
http
from
odoo
import
http
from
odoo.http
import
request
from
odoo.http
import
request
from
odoo.tools.misc
import
xlwt
from
odoo.tools.misc
import
xlwt
...
@@ -13,7 +13,7 @@ from odoo.tools.safe_eval import safe_eval
...
@@ -13,7 +13,7 @@ from odoo.tools.safe_eval import safe_eval
from
odoo.addons.web.controllers.main
import
content_disposition
,
serialize_exception
from
odoo.addons.web.controllers.main
import
content_disposition
,
serialize_exception
class
JournalDatasExport
(
http
.
Controller
):
class
JournalDatasExport
(
JournalDatasExport
):
# ------------------------------------------------------
# ------------------------------------------------------
# Routes
# Routes
# ------------------------------------------------------
# ------------------------------------------------------
...
@@ -46,22 +46,19 @@ class JournalDatasExport(http.Controller):
...
@@ -46,22 +46,19 @@ class JournalDatasExport(http.Controller):
domain
+=
safe_eval
(
export_id
.
export_domain
)
domain
+=
safe_eval
(
export_id
.
export_domain
)
export_line_ids
=
request
.
env
[
"
account.move.line
"
].
search
(
domain
)
export_line_ids
=
request
.
env
[
"
account.move.line
"
].
search
(
domain
)
# FIXME: Crappy could refactor to [[]] or {} to group by invoice name as key
# FIXME: Crappy could refactor to [[]] or {} to group by invoice name as key
export_line_grouped_by_invoice
=
export_line_ids
.
sorted
(
lambda
l
:
l
.
move_id
.
name
)
export_line_grouped_by_invoice
=
{}
for
el
in
export_line_ids
:
if
not
export_line_grouped_by_invoice
.
get
(
el
.
move_id
.
name
):
export_line_grouped_by_invoice
[
el
.
move_id
.
name
]
=
[]
export_line_grouped_by_invoice
[
el
.
move_id
.
name
].
append
(
el
)
# export_line_grouped_by_invoice = export_line_ids.sorted(lambda l: l.move_id.name)
lines_to_export
=
[]
lines_to_export
=
[]
initial_sum_line
=
[
''
for
_
in
range
(
len
(
export_id
.
fields_ids
))]
initial_sum_line
=
[
''
for
_
in
range
(
len
(
export_id
.
fields_ids
))]
sum_line
=
initial_sum_line
[:]
sum_line
=
initial_sum_line
[:]
big_sum_line
=
None
big_sum_line
=
None
previous_invoice_name
=
export_line_grouped_by_invoice
[
0
].
move_id
.
name
for
line
in
export_line_grouped_by_invoice
:
for
invoice_name
,
move_lines
in
export_line_grouped_by_invoice
.
items
():
if
line
.
name
!=
previous_invoice_name
:
for
line
in
move_lines
:
lines_to_export
.
append
(
sum_line
)
if
not
big_sum_line
:
# Initialise bigsum to the same size and value of the sum_line
# So it has not to be initialized with list of empty string
big_sum_line
=
sum_line
[:]
else
:
big_sum_line
=
[
value
+
sum_line
[
i
]
for
i
,
value
in
enumerate
(
big_sum_line
)]
sum_line
=
initial_sum_line
[:]
row
=
[]
row
=
[]
for
key
,
field
in
enumerate
(
export_id
.
fields_ids
):
for
key
,
field
in
enumerate
(
export_id
.
fields_ids
):
if
field
.
is_python
:
if
field
.
is_python
:
...
@@ -75,9 +72,18 @@ class JournalDatasExport(http.Controller):
...
@@ -75,9 +72,18 @@ class JournalDatasExport(http.Controller):
row
.
append
(
value
)
row
.
append
(
value
)
lines_to_export
.
append
(
row
)
lines_to_export
.
append
(
row
)
line
.
write
({
"
date_export
"
:
datetime
.
now
()})
line
.
write
({
"
date_export
"
:
datetime
.
now
()})
previous_invoice_name
=
line
.
name
lines_to_export
.
append
(
sum_line
)
lines_to_export
.
append
(
sum_line
)
lines_to_export
.
append
([
value
+
sum_line
[
i
]
for
i
,
value
in
enumerate
(
big_sum_line
)])
if
not
big_sum_line
:
# Initialise bigsum to the same size and value of the sum_line
# So it has not to be initialized with list of empty string
big_sum_line
=
sum_line
[:]
else
:
big_sum_line
=
[
value
+
sum_line
[
i
]
for
i
,
value
in
enumerate
(
big_sum_line
)]
sum_line
=
initial_sum_line
[:]
else
:
# lines_to_export.append(sum_line)
lines_to_export
.
append
(
big_sum_line
)
filename_
=
(
filename_
=
(
export_id
.
company_id
.
name
.
title
().
replace
(
"
"
,
""
)
export_id
.
company_id
.
name
.
title
().
replace
(
"
"
,
""
)
...
@@ -94,65 +100,3 @@ class JournalDatasExport(http.Controller):
...
@@ -94,65 +100,3 @@ class JournalDatasExport(http.Controller):
# ------------------------------------------------------
# ------------------------------------------------------
# Common function
# Common function
# ------------------------------------------------------
# ------------------------------------------------------
def
export_csv
(
self
,
export_id
,
lines_to_export
,
filename_
):
fp
=
StringIO
()
export_file
=
csv
.
writer
(
fp
,
delimiter
=
export_id
.
delimiter
,
quoting
=
csv
.
QUOTE_ALL
)
# Add header line
if
export_id
.
is_header
:
row
=
[]
for
head
in
export_id
.
fields_ids
.
mapped
(
"
name
"
):
row
.
append
(
head
)
export_file
.
writerow
(
row
)
for
line
in
lines_to_export
:
# Format date value
line_values
=
[
value
if
not
isinstance
(
value
,
date
)
else
value
.
strftime
(
export_id
.
csv_datestyle
)
for
value
in
line
]
export_file
.
writerow
(
line_values
)
fp
.
seek
(
0
)
data
=
fp
.
read
()
fp
.
close
()
filename
=
filename_
+
"
.csv
"
csvhttpheaders
=
[
(
"
Content-Type
"
,
"
text/csv;charset=utf8
"
),
(
"
Content-Disposition
"
,
content_disposition
(
filename
)),
]
return
request
.
make_response
(
data
,
headers
=
csvhttpheaders
)
def
export_xls
(
self
,
export_id
,
lines_to_export
,
filename_
):
workbook
=
xlwt
.
Workbook
()
worksheet
=
workbook
.
add_sheet
(
filename_
)
base_style
=
xlwt
.
easyxf
(
"
align: wrap yes
"
)
date_style
=
xlwt
.
XFStyle
()
date_style
.
num_format_str
=
export_id
.
xls_datestyle
if
export_id
.
is_header
:
for
i
,
fieldname
in
enumerate
(
export_id
.
fields_ids
.
mapped
(
"
name
"
)):
worksheet
.
write
(
0
,
i
,
fieldname
)
worksheet
.
col
(
i
).
width
=
4000
# around 220 pixels
for
row_index
,
line
in
enumerate
(
lines_to_export
):
for
cell_index
,
value
in
enumerate
(
line
):
cell_style
=
base_style
if
isinstance
(
value
,
date
):
cell_style
=
date_style
worksheet
.
write
(
row_index
+
1
,
cell_index
,
value
,
cell_style
)
fp
=
BytesIO
()
workbook
.
save
(
fp
)
fp
.
seek
(
0
)
data
=
fp
.
read
()
fp
.
close
()
filename
=
filename_
+
"
.xls
"
xlshttpheaders
=
[
(
"
Content-Type
"
,
"
text/csv;charset=utf8
"
),
(
"
Content-Disposition
"
,
content_disposition
(
filename
)),
]
return
request
.
make_response
(
data
,
headers
=
xlshttpheaders
)
This diff is collapsed.
Click to expand it.
datas/export_intercom_datas.xml
+
11
−
7
View file @
fd2cfa6e
...
@@ -76,7 +76,7 @@
...
@@ -76,7 +76,7 @@
<record
id=
"intercom_vt_7"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_7"
model=
"export.journal.field"
>
<field
name=
"name"
>
Description du produit
</field>
<field
name=
"name"
>
Description du produit
</field>
<field
name=
"sequence"
>
7
</field>
<field
name=
"sequence"
>
7
</field>
<field
name=
"field_name"
>
''
</field>
<field
name=
"field_name"
>
line.product_id.name
</field>
<field
<field
name=
"export_id"
name=
"export_id"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
...
@@ -95,6 +95,7 @@
...
@@ -95,6 +95,7 @@
<field
name=
"name"
>
Quantité
</field>
<field
name=
"name"
>
Quantité
</field>
<field
name=
"sequence"
>
9
</field>
<field
name=
"sequence"
>
9
</field>
<field
name=
"field_name"
>
line.quantity
</field>
<field
name=
"field_name"
>
line.quantity
</field>
<field
name=
"is_sum"
>
True
</field>
<field
<field
name=
"export_id"
name=
"export_id"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
...
@@ -112,7 +113,7 @@
...
@@ -112,7 +113,7 @@
<record
id=
"intercom_vt_11"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_11"
model=
"export.journal.field"
>
<field
name=
"name"
>
Montant Hors-taxe Signé
</field>
<field
name=
"name"
>
Montant Hors-taxe Signé
</field>
<field
name=
"sequence"
>
11
</field>
<field
name=
"sequence"
>
11
</field>
<field
name=
"field_name"
>
line.price_subtotal
</field>
<field
name=
"field_name"
>
-
line.price_subtotal
</field>
<field
name=
"is_sum"
>
True
</field>
<field
name=
"is_sum"
>
True
</field>
<field
<field
name=
"export_id"
name=
"export_id"
...
@@ -122,7 +123,7 @@
...
@@ -122,7 +123,7 @@
<record
id=
"intercom_vt_12"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_12"
model=
"export.journal.field"
>
<field
name=
"name"
>
Total signé
</field>
<field
name=
"name"
>
Total signé
</field>
<field
name=
"sequence"
>
12
</field>
<field
name=
"sequence"
>
12
</field>
<field
name=
"field_name"
>
''
</field>
<field
name=
"field_name"
>
-line.balance
</field>
<field
name=
"is_sum"
>
True
</field>
<field
name=
"is_sum"
>
True
</field>
<field
<field
name=
"export_id"
name=
"export_id"
...
@@ -130,9 +131,9 @@
...
@@ -130,9 +131,9 @@
/>
/>
</record>
</record>
<record
id=
"intercom_vt_13"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_13"
model=
"export.journal.field"
>
<field
name=
"name"
>
Total s
igné en devises
</field>
<field
name=
"name"
>
S
igné en devises
</field>
<field
name=
"sequence"
>
13
</field>
<field
name=
"sequence"
>
13
</field>
<field
name=
"field_name"
>
''
</field>
<field
name=
"field_name"
>
-line.amount_currency
</field>
<field
name=
"is_sum"
>
True
</field>
<field
name=
"is_sum"
>
True
</field>
<field
<field
name=
"export_id"
name=
"export_id"
...
@@ -151,7 +152,9 @@
...
@@ -151,7 +152,9 @@
<record
id=
"intercom_vt_15"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_15"
model=
"export.journal.field"
>
<field
name=
"name"
>
Pays de destination
</field>
<field
name=
"name"
>
Pays de destination
</field>
<field
name=
"sequence"
>
15
</field>
<field
name=
"sequence"
>
15
</field>
<field
name=
"field_name"
>
line.move_id.partner_shipping_id.country_id.display_name
</field>
<field
name=
"field_name"
>
line.move_id.partner_shipping_id.country_id.display_name
</field>
<field
<field
name=
"export_id"
name=
"export_id"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
...
@@ -178,7 +181,8 @@
...
@@ -178,7 +181,8 @@
<record
id=
"intercom_vt_18"
model=
"export.journal.field"
>
<record
id=
"intercom_vt_18"
model=
"export.journal.field"
>
<field
name=
"name"
>
Département d'expédition
</field>
<field
name=
"name"
>
Département d'expédition
</field>
<field
name=
"sequence"
>
18
</field>
<field
name=
"sequence"
>
18
</field>
<field
name=
"field_name"
>
''
</field>
<field
name=
"field_name"
>
31
</field>
<field
name=
"is_python"
eval=
"False"
/>
<field
<field
name=
"export_id"
name=
"export_id"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
ref=
"emgidi_export_intercom.emgidi_export_intercom_journal"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment