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
704a0dfb
Commit
704a0dfb
authored
May 06, 2024
by
François COLOMBIER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6286: Correctifs processus enregistrement paiement enveloppe
parent
66e8a55a
Pipeline
#3425
failed with stage
in 1 minute 5 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
33 deletions
+42
-33
models.py
envelops/models.py
+40
-30
views.py
envelops/views.py
+1
-1
admin.py
members/admin.py
+1
-0
models.py
members/models.py
+0
-2
No files found.
envelops/models.py
View file @
704a0dfb
...
@@ -35,6 +35,40 @@ class CagetteEnvelops(models.Model):
...
@@ -35,6 +35,40 @@ class CagetteEnvelops(models.Model):
ids
.
append
(
key
)
ids
.
append
(
key
)
return
ids
return
ids
def
get_related_invoice
(
self
,
data
):
invoice
=
None
message
=
""
# Get specific invoice if id is given
if
'invoice_id'
in
data
:
cond
=
[[
'id'
,
'='
,
data
[
'invoice_id'
]],
[
"number"
,
"!="
,
False
]]
else
:
cond
=
[[
'partner_id'
,
'='
,
data
[
'partner_id'
]],
[
"number"
,
"!="
,
False
],
[
"residual_signed"
,
">"
,
0
]]
fields
=
[
'id'
,
'name'
,
'number'
,
'partner_id'
,
'residual_signed'
]
invoice_res
=
self
.
o_api
.
search_read
(
'account.invoice'
,
cond
,
fields
,
order
=
"residual_signed DESC"
)
# Check if invoice exists
if
len
(
invoice_res
)
>
0
:
# Get first invoice for which amount being paid <= amount left to pay in invoice
for
invoice_item
in
invoice_res
:
if
int
(
float
(
data
[
'amount'
])
*
100
)
<=
int
(
float
(
invoice_item
[
'residual_signed'
])
*
100
):
invoice
=
invoice_item
if
invoice
is
None
:
message
=
'The amount is too high for the invoices found for this partner.'
if
invoice
is
None
and
'invoice_id'
in
data
:
"""Because of a legacy bug,
some capital subscription recording processes
could save a wrong 0 amount invoice in envelop,
instead of the one with right amount.
So, let's retry without invoice_id"""
del
data
[
'invoice_id'
]
[
invoice
,
message
]
=
self
.
get_related_invoice
(
data
)
# Can't fall into a loop since invoice_id key has been deleted
return
[
invoice
,
message
]
def
save_payment
(
self
,
data
):
def
save_payment
(
self
,
data
):
"""Save a partner payment"""
"""Save a partner payment"""
res
=
{
res
=
{
...
@@ -43,35 +77,11 @@ class CagetteEnvelops(models.Model):
...
@@ -43,35 +77,11 @@ class CagetteEnvelops(models.Model):
try
:
try
:
# Get invoice
# Get invoice
[
invoice
,
message
]
=
self
.
get_related_invoice
(
data
)
# Get specific invoice if id is given
if
invoice
is
None
:
if
'invoice_id'
in
data
:
if
len
(
message
)
==
0
:
cond
=
[[
'id'
,
'='
,
data
[
'invoice_id'
]],
[
"number"
,
"!="
,
False
]]
message
=
'No invoice found for this partner, can
\'
t create payment.'
else
:
res
[
'error'
]
=
message
cond
=
[[
'partner_id'
,
'='
,
data
[
'partner_id'
]],
[
"number"
,
"!="
,
False
]]
fields
=
[
'id'
,
'name'
,
'number'
,
'partner_id'
,
'residual_signed'
]
invoice_res
=
self
.
o_api
.
search_read
(
'account.invoice'
,
cond
,
fields
)
# Check if invoice exists
if
len
(
invoice_res
)
>
0
:
invoice
=
None
# Get first invoice for which amount being paid <= amount left to pay in invoice
for
invoice_item
in
invoice_res
:
if
int
(
float
(
data
[
'amount'
])
*
100
)
<=
int
(
float
(
invoice_item
[
'residual_signed'
])
*
100
):
invoice
=
invoice_item
if
invoice
is
None
:
res
[
'error'
]
=
'The amount is too high for the invoices found for this partner.'
try
:
# Got an error while logging...
coop_logger
.
error
(
res
[
'error'
]
+
' :
%
s'
,
str
(
data
))
except
Exception
as
e
:
print
(
str
(
e
))
return
res
else
:
res
[
'error'
]
=
'No invoice found for this partner, can
\'
t create payment.'
coop_logger
.
error
(
res
[
'error'
]
+
' :
%
s'
,
str
(
data
))
return
res
return
res
payment_journal_id
=
None
payment_journal_id
=
None
...
@@ -97,7 +107,7 @@ class CagetteEnvelops(models.Model):
...
@@ -97,7 +107,7 @@ class CagetteEnvelops(models.Model):
payment_id
=
self
.
o_api
.
create
(
'account.payment'
,
args
)
payment_id
=
self
.
o_api
.
create
(
'account.payment'
,
args
)
except
Exception
as
e
:
except
Exception
as
e
:
res
[
'error'
]
=
repr
(
e
)
res
[
'error'
]
=
repr
(
e
)
coop_logger
.
error
(
res
[
'error'
]
+
' :
%
s'
,
str
(
args
))
coop_logger
.
error
(
res
[
'error'
]
+
":
%
s"
,
str
(
args
))
# Exception rises when odoo method returns nothing
# Exception rises when odoo method returns nothing
marshal_none_error
=
'cannot marshal None unless allow_none is enabled'
marshal_none_error
=
'cannot marshal None unless allow_none is enabled'
...
...
envelops/views.py
View file @
704a0dfb
...
@@ -51,7 +51,7 @@ def archive_envelop(request):
...
@@ -51,7 +51,7 @@ def archive_envelop(request):
}
}
coop_logger
.
error
(
"Payment error :
%
s
\n
%
s"
,
str
(
data
),
str
(
e
))
coop_logger
.
error
(
"Payment error :
%
s
\n
%
s"
,
str
(
data
),
str
(
e
))
if
res
[
'done'
]:
if
res
[
'done'
]
is
True
:
# Immediately save a token than this payment has been saved
# Immediately save a token than this payment has been saved
# If an error occurs, this payment won't be saved again
# If an error occurs, this payment won't be saved again
envelop
[
'envelop_content'
][
partner_id
][
'payment_id'
]
=
res
[
'payment_id'
]
envelop
[
'envelop_content'
][
partner_id
][
'payment_id'
]
=
res
[
'payment_id'
]
...
...
members/admin.py
View file @
704a0dfb
...
@@ -302,6 +302,7 @@ def generate_base_and_barcode(request, member_id):
...
@@ -302,6 +302,7 @@ def generate_base_and_barcode(request, member_id):
return
response
return
response
def
create_envelops
(
request
):
def
create_envelops
(
request
):
"""Only used from manage_mess, which was a tempory fonctionality"""
res
=
{}
res
=
{}
is_connected_user
=
CagetteUser
.
are_credentials_ok
(
request
)
is_connected_user
=
CagetteUser
.
are_credentials_ok
(
request
)
if
is_connected_user
is
True
:
if
is_connected_user
is
True
:
...
...
members/models.py
View file @
704a0dfb
...
@@ -608,13 +608,11 @@ class CagetteMember(models.Model):
...
@@ -608,13 +608,11 @@ class CagetteMember(models.Model):
payment_data
[
'checks'
]
=
json
.
loads
(
post_data
[
'checks'
])
payment_data
[
'checks'
]
=
json
.
loads
(
post_data
[
'checks'
])
else
:
else
:
payment_data
[
'checks'
]
=
[]
payment_data
[
'checks'
]
=
[]
if
payment_data
[
'payment_meaning'
]
==
'cash'
or
payment_data
[
'payment_meaning'
]
==
'ch'
:
if
payment_data
[
'payment_meaning'
]
==
'cash'
or
payment_data
[
'payment_meaning'
]
==
'ch'
:
res
[
'envelop'
]
=
CagetteEnvelops
()
.
create_or_update_envelops
(
payment_data
)
res
[
'envelop'
]
=
CagetteEnvelops
()
.
create_or_update_envelops
(
payment_data
)
else
:
else
:
p_data
=
{
'partner_id'
:
partner_id
,
'type'
:
payment_data
[
'payment_meaning'
],
'amount'
:
post_data
[
'shares_euros'
]}
p_data
=
{
'partner_id'
:
partner_id
,
'type'
:
payment_data
[
'payment_meaning'
],
'amount'
:
post_data
[
'shares_euros'
]}
res
[
'envelop'
]
=
CagetteEnvelops
()
.
save_payment
(
p_data
)
res
[
'envelop'
]
=
CagetteEnvelops
()
.
save_payment
(
p_data
)
# Send welcome mail
# Send welcome mail
try
:
try
:
api
.
execute
(
'res.partner'
,
'send_welcome_email'
,
[
partner_id
])
api
.
execute
(
'res.partner'
,
'send_welcome_email'
,
[
partner_id
])
...
...
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