Skip to content

Commit

Permalink
[IMP] lcc_lokavaluto_app_connection: clean is_ready_to_invoice function
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphan Sainléger authored and vaab committed Oct 18, 2024
1 parent b840de1 commit dfb8646
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lcc_lokavaluto_app_connection/models/debit_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ class DebitRequest(models.Model):
def create(self, vals):
res = super(DebitRequest, self).create(vals)
for request in res:
if request.is_ready_to_invoice():
request.create_invoices()
try:
if request.is_ready_to_invoice():
request.create_invoices()
except UserError:
# Missing data in not critical at creation step.
pass
return res

def unlink(self):
Expand Down Expand Up @@ -144,15 +148,15 @@ def _convert_status(self, status):
if status == "paid":
return "paid"

def is_ready_to_invoice(self, raise_error=False):
def is_ready_to_invoice(self):
self.ensure_one()
if self.amount <= 0 and raise_error:
if self.amount <= 0:
raise UserError("Amount must be superior to zero.")
if not self.wallet_id and raise_error:
if not self.wallet_id:
raise UserError("The wallet is missing.")
if not self.transaction_id and raise_error:
if not self.transaction_id:
raise UserError("The transaction ID is missing.")
return (self.amount > 0) and self.wallet_id and self.transaction_id
return True

#############################
## INVOICE CREATION PROCESSES
Expand Down

0 comments on commit dfb8646

Please sign in to comment.