From 0b1b87ce290df3dfa1880a033dd46787f0488329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Fri, 18 Oct 2024 11:12:44 +0200 Subject: [PATCH] [IMP] lcc_lokavaluto_app_connection: change credit/debit pages display rules --- .../models/account_invoice.py | 30 ++++++++++--------- .../views/account_invoice.xml | 7 +++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lcc_lokavaluto_app_connection/models/account_invoice.py b/lcc_lokavaluto_app_connection/models/account_invoice.py index ef965886..a5f3629f 100644 --- a/lcc_lokavaluto_app_connection/models/account_invoice.py +++ b/lcc_lokavaluto_app_connection/models/account_invoice.py @@ -13,9 +13,15 @@ class AccountInvoice(models.Model): credit_request_ids = fields.One2many( "credit.request", "invoice_id", string="Credit Requests" ) + has_credit_requests = fields.Boolean( + compute="_compute_has_credit_requests", store=False + ) debit_request_ids = fields.Many2many( "debit.request", compute="_compute_debit_request_ids", string="Debit Requests" ) + has_debit_requests = fields.Boolean( + compute="_compute_has_debit_requests", store=False + ) global_credit_status = fields.Selection( [ ("todo", "To do"), @@ -32,11 +38,6 @@ class AccountInvoice(models.Model): global_lcc_amount_to_credit = fields.Float( string="LCC amount to credit", compute="_compute_global_lcc_amounts" ) - digital_currency_invoice_type = fields.Selection( - [("none", "None"), ("credit", "Credit"), ("debit", "Debit")], - string="Digital Currency Invoice Type", - compute="_compute_digital_currency_invoice_type", - ) @api.depends("credit_request_ids") def _compute_global_credit_status(self): @@ -44,6 +45,16 @@ def _compute_global_credit_status(self): r.state == "done" for r in self.credit_request_ids ) + @api.depends("credit_request_ids") + def _compute_has_credit_requests(self): + for record in self: + record.has_credit_requests = bool(record.credit_request_ids) + + @api.depends("debit_request_ids") + def _compute_has_debit_requests(self): + for record in self: + record.has_debit_requests = bool(record.debit_request_ids) + @api.depends("credit_request_ids") def _compute_global_lcc_amounts(self): done_requests = self.credit_request_ids.filtered(lambda x: x.state == "done") @@ -78,15 +89,6 @@ def _compute_debit_request_ids(self): ] ) - @api.depends("debit_request_ids", "credit_request_ids") - def _compute_digital_currency_invoice_type(self): - if self.debit_request_ids: - self.digital_currency_invoice_type = "debit" - elif self.credit_request_ids: - self.digital_currency_invoice_type = "credit" - else: - self.digital_currency_invoice_type = "none" - def _invoice_paid_hook(self): res = super(AccountInvoice, self)._invoice_paid_hook() for invoice in self: diff --git a/lcc_lokavaluto_app_connection/views/account_invoice.xml b/lcc_lokavaluto_app_connection/views/account_invoice.xml index 6e2a00f5..85778d1d 100644 --- a/lcc_lokavaluto_app_connection/views/account_invoice.xml +++ b/lcc_lokavaluto_app_connection/views/account_invoice.xml @@ -6,9 +6,10 @@ - + + + attrs="{'invisible': [('has_credit_requests', '=', False)]}">