From 4bec0018c4b99a3d36a92d178ddfcd364deb9c1d Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 25 May 2019 19:43:30 +0200 Subject: [PATCH] [FIX] account_payment_order: Fix compute dependency chain Detected doing a migration 8.0 > 9.0. The `amount_company_currency` field computation was not depending on `currency_id` field, and thus that one was being computed before populating the other one. Also having both fields in the same compute method makes them less efficient, as they don't depend on the same source fields. --- .../models/bank_payment_line.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/account_payment_order/models/bank_payment_line.py b/account_payment_order/models/bank_payment_line.py index a32d54837..6474b2fb3 100644 --- a/account_payment_order/models/bank_payment_line.py +++ b/account_payment_order/models/bank_payment_line.py @@ -33,11 +33,11 @@ class BankPaymentLine(models.Model): # But is it still true in v9 ? amount_currency = fields.Monetary( string='Amount', currency_field='currency_id', - compute='_compute_amount', store=True, readonly=True) + compute='_compute_amount_currency', store=True) amount_company_currency = fields.Monetary( string='Amount in Company Currency', currency_field='company_currency_id', - compute='_compute_amount', store=True, readonly=True) + compute='_compute_amount_company_currency', store=True) currency_id = fields.Many2one( 'res.currency', required=True, readonly=True, related='payment_line_ids.currency_id') # v8 field: currency @@ -73,15 +73,20 @@ class BankPaymentLine(models.Model): @api.multi @api.depends('payment_line_ids', 'payment_line_ids.amount_currency') - def _compute_amount(self): + def _compute_amount_currency(self): for bline in self: - amount_currency = sum( + bline.amount_currency = sum( bline.mapped('payment_line_ids.amount_currency')) - amount_company_currency = bline.currency_id.with_context( - date=bline.date).compute( - amount_currency, bline.company_currency_id) - bline.amount_currency = amount_currency - bline.amount_company_currency = amount_company_currency + + @api.multi + @api.depends('currency_id', 'amount_currency', 'company_id') + def _compute_amount_company_currency(self): + for bline in self: + bline.amount_company_currency = bline.currency_id.with_context( + date=bline.date, + ).compute( + bline.amount_currency, bline.company_currency_id, + ) @api.model @api.returns('self')