From aa2340653156986f1c248425c4e00f13c3271171 Mon Sep 17 00:00:00 2001 From: jordan <jordan@le-filament.com> Date: Tue, 4 May 2021 11:03:08 +0200 Subject: [PATCH] [fix] compute state with inner function --- models/scop_cotisations_idf.py | 25 ++++++++++++------------- models/scop_invoice_idf.py | 24 +++++++++++------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/models/scop_cotisations_idf.py b/models/scop_cotisations_idf.py index 2dd5bf4..f7e34d0 100644 --- a/models/scop_cotisations_idf.py +++ b/models/scop_cotisations_idf.py @@ -87,30 +87,29 @@ class ScopCotisationsIDF(models.Model): @api.multi def _compute_state(self): """ - A line can be in different state : + A line can be in different states : - No invoice related to a payment / refund - Too many payments related to one invoice - Some payments are missing - The invoice has been paid """ + + def which_state(amount_residual): + if amount_residual > 0: + return 'awaiting_payments' + elif amount_residual < 0: + return 'overpaid' + else: + return 'paid' + for r in self: if r.type != 'inv': if not r.invoice_id: r.state = 'no_invoice' else: - if r.invoice_id.amount_residual > 0: - r.state = 'awaiting_payments' - elif r.invoice_id.amount_residual < 0: - r.state = 'overpaid' - else: - r.state = 'paid' + r.state = which_state(r.invoice_id.amount_residual) else: - if r.amount_residual > 0: - r.state = 'awaiting_payments' - elif r.amount_residual < 0: - r.state = 'overpaid' - else: - r.state = 'paid' + r.state = which_state(r.amount_residual) @api.multi def _search_state(self, operator, value): diff --git a/models/scop_invoice_idf.py b/models/scop_invoice_idf.py index a19534a..347c181 100644 --- a/models/scop_invoice_idf.py +++ b/models/scop_invoice_idf.py @@ -83,30 +83,28 @@ class ScopInvoiceIDF(models.Model): @api.multi def _compute_state(self): """ - A line can be in different state : + A line can be in different states : - No invoice related to a payment / refund - Too many payments related to one invoice - Some payments are missing - The invoice has been paid """ + def which_state(amount_residual): + if amount_residual > 0: + return 'awaiting_payments' + elif amount_residual < 0: + return 'overpaid' + else: + return 'paid' + for r in self: if r.type != 'inv': if not r.invoice_id: r.state = 'no_invoice' else: - if r.invoice_id.amount_residual > 0: - r.state = 'awaiting_payments' - elif r.invoice_id.amount_residual < 0: - r.state = 'overpaid' - else: - r.state = 'paid' + r.state = which_state(r.invoice_id.amount_residual) else: - if r.amount_residual > 0: - r.state = 'awaiting_payments' - elif r.amount_residual < 0: - r.state = 'overpaid' - else: - r.state = 'paid' + r.state = which_state(r.amount_residual) @api.multi def _search_state(self, operator, value): -- GitLab