diff --git a/account_banking_mandate/models/account_banking_mandate.py b/account_banking_mandate/models/account_banking_mandate.py
index a25664f95..10cb42185 100644
--- a/account_banking_mandate/models/account_banking_mandate.py
+++ b/account_banking_mandate/models/account_banking_mandate.py
@@ -64,12 +64,44 @@ class AccountBankingMandate(models.Model):
payment_line_ids = fields.One2many(
comodel_name='account.payment.line', inverse_name='mandate_id',
string="Related Payment Lines")
+ payment_line_ids_count = fields.Integer(
+ compute='_compute_payment_line_ids_count',
+ )
_sql_constraints = [(
'mandate_ref_company_uniq',
'unique(unique_mandate_reference, company_id)',
'A Mandate with the same reference already exists for this company!')]
+ @api.multi
+ @api.depends('payment_line_ids')
+ def _compute_payment_line_ids_count(self):
+ payment_line_model = self.env['account.payment.line']
+ domain = [('mandate_id', 'in', self.ids)]
+ res = payment_line_model.read_group(
+ domain=domain,
+ fields=['mandate_id'],
+ groupby=['mandate_id'],
+ )
+ payment_line_dict = {}
+ for dic in res:
+ mandate_id = dic['mandate_id'][0]
+ payment_line_dict.setdefault(mandate_id, 0)
+ payment_line_dict[mandate_id] += dic['mandate_id_count']
+ for rec in self:
+ rec.payment_line_ids_count = payment_line_dict.get(rec.id, 0)
+
+ @api.multi
+ def show_payment_lines(self):
+ self.ensure_one()
+ return {
+ 'name': _("Payment lines"),
+ 'type': 'ir.actions.act_window',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.payment.line',
+ 'domain': [('mandate_id', '=', self.id)],
+ }
+
@api.multi
@api.constrains('signature_date', 'last_debit_date')
def _check_dates(self):
diff --git a/account_banking_mandate/tests/test_invoice_mandate.py b/account_banking_mandate/tests/test_invoice_mandate.py
index c05bce6c3..5ccf5bcd3 100644
--- a/account_banking_mandate/tests/test_invoice_mandate.py
+++ b/account_banking_mandate/tests/test_invoice_mandate.py
@@ -31,6 +31,7 @@ class TestInvoiceMandate(TransactionCase):
payment_order.draft2open()
payment_order.open2generated()
payment_order.generated2uploaded()
+ self.assertEqual(self.mandate.payment_line_ids_count, 1)
def test_post_invoice_02(self):
partner_2 = self._create_res_partner('Jane with ACME Bank')
diff --git a/account_banking_mandate/views/account_banking_mandate_view.xml b/account_banking_mandate/views/account_banking_mandate_view.xml
index 64d7c087f..b35b26b2f 100644
--- a/account_banking_mandate/views/account_banking_mandate_view.xml
+++ b/account_banking_mandate/views/account_banking_mandate_view.xml
@@ -23,6 +23,7 @@
+
-
-
-
@@ -56,6 +54,26 @@
+
+ view.mandate.form.buttons
+ account.banking.mandate
+
+
+
+
+
+
+
+
+
view.mandate.tree
account.banking.mandate