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,43 +35,53 @@ class CagetteEnvelops(models.Model): ...@@ -35,43 +35,53 @@ class CagetteEnvelops(models.Model):
ids.append(key) ids.append(key)
return ids return ids
def save_payment(self, data): def get_related_invoice(self, data):
"""Save a partner payment""" invoice = None
res = { message = ""
"done": False
}
try:
# Get invoice
# Get specific invoice if id is given # Get specific invoice if id is given
if 'invoice_id' in data: if 'invoice_id' in data:
cond = [['id', '=', data['invoice_id']], ["number", "!=", False]] cond = [['id', '=', data['invoice_id']], ["number", "!=", False]]
else: else:
cond = [['partner_id', '=', data['partner_id']], ["number", "!=", False]] cond = [['partner_id', '=', data['partner_id']], ["number", "!=", False], ["residual_signed", ">", 0]]
fields = ['id', 'name', 'number', 'partner_id', 'residual_signed'] fields = ['id', 'name', 'number', 'partner_id', 'residual_signed']
invoice_res = self.o_api.search_read('account.invoice', cond, fields) invoice_res = self.o_api.search_read('account.invoice', cond, fields,order="residual_signed DESC")
# Check if invoice exists # Check if invoice exists
if len(invoice_res) > 0: if len(invoice_res) > 0:
invoice = None
# Get first invoice for which amount being paid <= amount left to pay in invoice # Get first invoice for which amount being paid <= amount left to pay in invoice
for invoice_item in invoice_res: for invoice_item in invoice_res:
if int(float(data['amount']) * 100) <= int(float(invoice_item['residual_signed']) * 100): if int(float(data['amount']) * 100) <= int(float(invoice_item['residual_signed']) * 100):
invoice = invoice_item invoice = invoice_item
if invoice is None: if invoice is None:
res['error'] = 'The amount is too high for the invoices found for this partner.' 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 = {
"done": False
}
try: try:
# Got an error while logging... # Get invoice
coop_logger.error(res['error'] + ' : %s', str(data)) [invoice, message] = self.get_related_invoice(data)
except Exception as e: if invoice is None:
print(str(e)) if len(message) == 0:
return res message = 'No invoice found for this partner, can\'t create payment.'
else: res['error'] = message
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'
......
...@@ -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']
......
...@@ -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:
......
...@@ -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])
......
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