From 83a1c4d5c1eb02c2c4bd105b7e57d8e42d29d379 Mon Sep 17 00:00:00 2001 From: Felipe Garcia Suez Date: Thu, 14 Nov 2024 15:39:10 -0300 Subject: [PATCH] [IMP] account_payment_term_surcharge: Added restriction setting payment term surcharge --- .../models/account_payment_term.py | 21 ++++++++++++++++++- .../views/account_payment_term_view.xml | 8 +++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/account_payment_term_surcharge/models/account_payment_term.py b/account_payment_term_surcharge/models/account_payment_term.py index f8d214330..c13063e0d 100644 --- a/account_payment_term_surcharge/models/account_payment_term.py +++ b/account_payment_term_surcharge/models/account_payment_term.py @@ -1,4 +1,5 @@ -from odoo import fields, models +from odoo import api, fields, models +from odoo.exceptions import UserError class AccountPaymentTerm(models.Model): @@ -9,3 +10,21 @@ class AccountPaymentTerm(models.Model): 'payment_term_id', string='Surcharges', copy=True, ) + + show_surcharge_warning = fields.Boolean(compute='_compute_surcharge_product') + + @api.depends('company_id', 'surcharge_ids') + def _compute_surcharge_product(self): + """Check if the surcharge product needs to be updated for the given company context.""" + for rec in self: + if rec.surcharge_ids: + if rec.company_id: # Verificar para una compañía específica + company = rec.company_id + # Devuelve False si falta el producto de recargo + self.show_surcharge_warning = bool(company.payment_term_surcharge_product_id) + else: # Verificar todas las compañías si company_id es False + all_companies = self.env['res.company'].search([]) + # Devuelve False si alguna compañía no tiene configurado el producto de recargo + rec.show_surcharge_warning = all(company.payment_term_surcharge_product_id for company in all_companies) + else: + rec.show_surcharge_warning = True diff --git a/account_payment_term_surcharge/views/account_payment_term_view.xml b/account_payment_term_surcharge/views/account_payment_term_view.xml index 50e0ab34d..95da32c7b 100644 --- a/account_payment_term_surcharge/views/account_payment_term_view.xml +++ b/account_payment_term_surcharge/views/account_payment_term_view.xml @@ -9,7 +9,15 @@ + + + + +