[FIX] account: payment method dependencies

Change dependencies of a few computed fields in order
to avoid triggering them wrongly when migrating.

Also add a company check on the constrains blocking
deletion of payment method lines linked to an active
acquirer.

closes odoo/odoo#73731

X-original-commit: e94b4f09a4c5664360594bee6475cb2ef756be47
Related: odoo/enterprise#19663
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Nicolas (vin)
2021-07-14 15:22:31 +00:00
parent c80002f660
commit 3a98bf80ec
3 changed files with 8 additions and 10 deletions
+1 -3
View File
@@ -396,9 +396,7 @@ class AccountPayment(models.Model):
else:
pay.payment_method_line_id = False
@api.depends('payment_type',
'journal_id.inbound_payment_method_line_ids',
'journal_id.outbound_payment_method_line_ids')
@api.depends('payment_type', 'journal_id')
def _compute_payment_method_line_fields(self):
for pay in self:
pay.available_payment_method_line_ids = pay.journal_id._get_available_payment_method_lines(pay.payment_type)
@@ -289,9 +289,7 @@ class AccountPaymentRegister(models.TransientModel):
else:
wizard.partner_bank_id = False
@api.depends('payment_type',
'journal_id.inbound_payment_method_line_ids',
'journal_id.outbound_payment_method_line_ids')
@api.depends('payment_type', 'journal_id')
def _compute_payment_method_line_fields(self):
for wizard in self:
wizard.available_payment_method_line_ids = wizard.journal_id._get_available_payment_method_lines(wizard.payment_type)
@@ -303,9 +301,7 @@ class AccountPaymentRegister(models.TransientModel):
wizard.hide_payment_method_line = len(wizard.available_payment_method_line_ids) == 1 \
and wizard.available_payment_method_line_ids.code == 'manual'
@api.depends('payment_type',
'journal_id.inbound_payment_method_line_ids',
'journal_id.outbound_payment_method_line_ids')
@api.depends('payment_type', 'journal_id')
def _compute_payment_method_line_id(self):
for wizard in self:
if wizard.payment_type == 'inbound':
+5 -1
View File
@@ -13,6 +13,9 @@ class AccountJournal(models.Model):
"""
Check and ensure that the user do not remove a apml that is linked to an acquirer in the test or enabled state.
"""
if not self.company_id:
return
self.env['account.payment.method'].flush(['code', 'payment_type'])
self.env['account.payment.method.line'].flush(['payment_method_id'])
self.env['payment.acquirer'].flush(['provider', 'state'])
@@ -24,7 +27,8 @@ class AccountJournal(models.Model):
LEFT JOIN account_payment_method_line apml ON apm.id = apml.payment_method_id
WHERE acquirer.state IN ('enabled', 'test') AND apm.payment_type = 'inbound'
AND apml.id IS NULL
''')
AND acquirer.company_id IN %(company_ids)s
''', {'company_ids': tuple(self.company_id.ids)})
ids = [r[0] for r in self._cr.fetchall()]
acquirers = self.env['payment.acquirer'].browse(ids)
if acquirers: