Repository: OCA/bank-payment

Issue:
[12.0][BUG] account_payment_mode
I think I find a bug on payment modes.
If I create a payment mode with a variable link to a several banks, when I get the debit order I can't select the bank. 
![captura de pantalla 2019-01-25 a las 16 21 39](https://user-images.githubusercontent.com/22914905/51754716-5183a300-20bd-11e9-958e-409d9869e6fa.png)



Discussion:
I have just tried and seems to work without problems:

![seleccion_017](https://user-images.githubusercontent.com/7165771/52157962-c34a8680-2693-11e9-9a32-bb4c3b94ac20.png)

![seleccion_018](https://user-images.githubusercontent.com/7165771/52157965-d198a280-2693-11e9-9f37-aa88f36f60ad.png)

But I got the problem: when you save and come back later to the payment order, the journal domain is reset and the list becomes empty.

Investigating to see the source of the problem.

Resolving patch:
diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py
--- a/account_payment_order/models/account_payment_order.py
+++ b/account_payment_order/models/account_payment_order.py
@@ -15,15 +15,6 @@ class AccountPaymentOrder(models.Model):
     _inherit = ['mail.thread']
     _order = 'id desc'
 
-    def domain_journal_id(self):
-        if not self.payment_mode_id:
-            return [('id', '=', False)]
-        if self.payment_mode_id.bank_account_link == 'fixed':
-            return [('id', '=', self.payment_mode_id.fixed_journal_id.id)]
-        elif self.payment_mode_id.bank_account_link == 'variable':
-            jrl_ids = self.payment_mode_id.variable_journal_ids.ids
-            return [('id', 'in', jrl_ids)]
-
     name = fields.Char(
         string='Number', readonly=True, copy=False)  # v8 field : name
     payment_mode_id = fields.Many2one(
@@ -44,10 +35,14 @@ def domain_journal_id(self):
         readonly=True)
     bank_account_link = fields.Selection(
         related='payment_mode_id.bank_account_link', readonly=True)
+    allowed_journal_ids = fields.Many2many(
+        comodel_name='account.journal',
+        compute="_compute_allowed_journal_ids",
+        string="Allowed journals",
+    )
     journal_id = fields.Many2one(
         'account.journal', string='Bank Journal', ondelete='restrict',
         readonly=True, states={'draft': [('readonly', False)]},
-        domain=domain_journal_id,
         track_visibility='onchange')
     # The journal_id field is only required at confirm step, to
     # allow auto-creation of payment order from invoice
@@ -106,6 +101,16 @@ def domain_journal_id(self):
         readonly=True)
     description = fields.Char()
 
+    @api.depends('payment_mode_id')
+    def _compute_allowed_journal_ids(self):
+        for record in self:
+            if record.payment_mode_id.bank_account_link == 'fixed':
+                record.allowed_journal_ids = (
+                    record.payment_mode_id.fixed_journal_id)
+            elif record.payment_mode_id.bank_account_link == 'variable':
+                record.allowed_journal_ids = (
+                    self.payment_mode_id.variable_journal_ids)
+
     @api.multi
     def unlink(self):
         for order in self:
@@ -174,16 +179,10 @@ def create(self, vals):
 
     @api.onchange('payment_mode_id')
     def payment_mode_id_change(self):
-        domain = self.domain_journal_id()
-        res = {'domain': {
-            'journal_id': domain
-        }}
-        journals = self.env['account.journal'].search(domain)
-        if len(journals) == 1:
-            self.journal_id = journals
+        if len(self.allowed_journal_ids) == 1:
+            self.journal_id = self.allowed_journal_ids
         if self.payment_mode_id.default_date_prefered:
             self.date_prefered = self.payment_mode_id.default_date_prefered
-        return res
 
     @api.multi
     def action_done(self):


Test patch: