Skip to content

Commit

Permalink
[IMP] account_payment_term_surcharge: Added restriction setting payme…
Browse files Browse the repository at this point in the history
…nt term surcharge
  • Loading branch information
feg-adhoc committed Dec 2, 2024
1 parent 4cb3b5f commit 83a1c4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
21 changes: 20 additions & 1 deletion account_payment_term_surcharge/models/account_payment_term.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError


class AccountPaymentTerm(models.Model):
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
<field name="line_ids" position="after">
<separator string="Surcharges"/>
<field name="surcharge_ids" nolabel="1" colspan="2"/>
<field name="show_surcharge_warning" invisible="1"/>
</field>

<sheet position="before">
<div class="alert alert-warning" role="alert" invisible="show_surcharge_warning">
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.
</div>
</sheet>
</field>
</record>
</data>
Expand Down

0 comments on commit 83a1c4d

Please sign in to comment.