Use Function field to test if invoice has an account move

This prevents to hide the post button if the user has no read access to the
account moves.

Closes #13493
This commit is contained in:
Sergi Almacellas Abellana
2024-10-11 15:33:51 +02:00
parent 68d7267502
commit 9a14948fb4
+9 -2
View File
@@ -351,6 +351,8 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
fields.Boolean("Has Payment Method"), 'get_has_payment_method')
has_report_cache = fields.Function(
fields.Boolean("Has Report Cached"), 'get_has_report_cache')
has_account_move = fields.Function(
fields.Boolean("Has Account Move"), 'on_change_with_has_account_move')
del _states
@@ -457,8 +459,9 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
('type', '!=', 'in'),
],
'invisible': (~Eval('state').in_(['draft', 'validated'])
| ((Eval('state') == 'posted') & Bool(Eval('move')))),
'depends': ['state', 'move'],
| ((Eval('state') == 'posted')
& ~Eval('has_account_move', False))),
'depends': ['state', 'has_account_move'],
},
'pay': {
'invisible': (
@@ -628,6 +631,10 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
return self.party.lang.code
return Config.get_language()
@fields.depends('move')
def on_change_with_has_account_move(self, name=None):
return bool(self.move)
@classmethod
def get_type_name(cls, invoices, name):
type_names = {}