Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
ad8063e6 by Cédric Krier at 2023-03-24T13:21:42+01:00
Hide pay button on invoice if there is no payment method

Closes #12160
- - - - -


1 changed file:

- modules/account_invoice/invoice.py


Changes:

=====================================
modules/account_invoice/invoice.py
=====================================
@@ -275,6 +275,8 @@
     invoice_report_format = fields.Char('Invoice Report Format', readonly=True)
     allow_cancel = fields.Function(
         fields.Boolean("Allow Cancel Invoice"), 'get_allow_cancel')
+    has_payment_method = fields.Function(
+        fields.Boolean("Has Payment Method"), 'get_has_payment_method')
 
     del _states
 
@@ -356,8 +358,10 @@
                     'depends': ['state', 'move'],
                     },
                 'pay': {
-                    'invisible': Eval('state') != 'posted',
-                    'depends': ['state'],
+                    'invisible': (
+                        (Eval('state') != 'posted')
+                        | ~Eval('has_payment_method', False)),
+                    'depends': ['state', 'has_payment_method'],
                     },
                 'reschedule_lines_to_pay': {
                     'invisible': (
@@ -927,6 +931,22 @@
             return self.type == 'in' or self.company.cancel_invoice_out
         return False
 
+    @classmethod
+    def get_has_payment_method(cls, invoices, name):
+        pool = Pool()
+        Method = pool.get('account.invoice.payment.method')
+        methods = {}
+        for (company, account), sub_invoices in groupby(
+                invoices, key=lambda i: (i.company, i.account)):
+            sub_invoice_ids = [i.id for i in sub_invoices]
+            value = bool(Method.search([
+                        ('company', '=', company.id),
+                        ('debit_account', '!=', account.id),
+                        ('credit_account', '!=', account.id),
+                        ], limit=1))
+            methods.update(dict.fromkeys(sub_invoice_ids, value))
+        return methods
+
     @property
     def taxable_lines(self):
         taxable_lines = []



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/ad8063e62a0c6832d7c73d7e1b5c5d1e092b95c4

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/ad8063e62a0c6832d7c73d7e1b5c5d1e092b95c4
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to