Commit b17bcabd by Administrator

Merge branch '6286_bug_encaissement_souscription_cheque_espece' into 'dev_cooperatic'

#6286: Correctifs processus enregistrement paiement enveloppe

See merge request !273
parents 9904fbbe 704a0dfb
Pipeline #3497 failed with stage
in 1 minute 6 seconds
......@@ -35,6 +35,40 @@ class CagetteEnvelops(models.Model):
ids.append(key)
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):
"""Save a partner payment"""
res = {
......@@ -43,35 +77,11 @@ class CagetteEnvelops(models.Model):
try:
# Get invoice
# 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]]
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))
[invoice, message] = self.get_related_invoice(data)
if invoice is None:
if len(message) == 0:
message = 'No invoice found for this partner, can\'t create payment.'
res['error'] = message
return res
payment_journal_id = None
......@@ -97,7 +107,7 @@ class CagetteEnvelops(models.Model):
payment_id = self.o_api.create('account.payment', args)
except Exception as 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
marshal_none_error = 'cannot marshal None unless allow_none is enabled'
......
......@@ -51,7 +51,7 @@ def archive_envelop(request):
}
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
# If an error occurs, this payment won't be saved again
envelop['envelop_content'][partner_id]['payment_id'] = res['payment_id']
......
......@@ -302,6 +302,7 @@ def generate_base_and_barcode(request, member_id):
return response
def create_envelops(request):
"""Only used from manage_mess, which was a tempory fonctionality"""
res = {}
is_connected_user = CagetteUser.are_credentials_ok(request)
if is_connected_user is True:
......
......@@ -608,13 +608,11 @@ class CagetteMember(models.Model):
payment_data['checks'] = json.loads(post_data['checks'])
else:
payment_data['checks'] = []
if payment_data['payment_meaning'] == 'cash' or payment_data['payment_meaning'] == 'ch':
res['envelop'] = CagetteEnvelops().create_or_update_envelops(payment_data)
else:
p_data = {'partner_id': partner_id, 'type': payment_data['payment_meaning'], 'amount': post_data['shares_euros']}
res['envelop'] = CagetteEnvelops().save_payment(p_data)
# Send welcome mail
try:
api.execute('res.partner', 'send_welcome_email', [partner_id])
......
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