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 @@
+
+
+
+
+ The selected company for this payment term does not have a surcharge product configured.
+ Please configure the product in Settings / Accounting for the selected company or companies.
+