From d23f91b80fee6f8d502430ce3879b70e688af806 Mon Sep 17 00:00:00 2001 From: william Date: Tue, 28 Jul 2020 09:17:52 +0000 Subject: [PATCH] [FIX] account: partner mapping and model order Because we used the same variable to compute the partner, it was overriden once we went through a model with a partner mapping, and kept for models with lesser priority. Also remove the key param to sort the recocniliation models. We want the models to be sorted according like in the list view, and that is exactly what the .sorted() function does without params. (no need to worry about changing it if we change the _order) --- addons/account/models/account_reconcile_model.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py index d4eca545eeb..18a6bbf1314 100644 --- a/addons/account/models/account_reconcile_model.py +++ b/addons/account/models/account_reconcile_model.py @@ -406,19 +406,17 @@ class AccountReconcileModel(models.Model): results = {line.id: {'aml_ids': []} for line in st_lines} - available_models = self.filtered(lambda m: m.rule_type != 'writeoff_button').sorted(key=lambda m: (m.sequence, m.id)) + available_models = self.filtered(lambda m: m.rule_type != 'writeoff_button').sorted() aml_ids_to_exclude = set() # Keep track of already processed amls. reconciled_amls_ids = set() # Keep track of already reconciled amls. # First associate with each rec models all the statement lines for which it is applicable lines_with_partner_per_model = defaultdict(lambda: []) for st_line in st_lines: - partner = (partner_map and partner_map.get(st_line.id) and self.env['res.partner'].browse(partner_map[st_line.id])) or st_line.partner_id + mapped_partner = (partner_map and partner_map.get(st_line.id) and self.env['res.partner'].browse(partner_map[st_line.id])) or st_line.partner_id for rec_model in available_models: - if not partner: - # The function takes care of returning something only for the rules supporting partner mapping - partner = rec_model._get_partner_from_mapping(st_line) + partner = mapped_partner or rec_model._get_partner_from_mapping(st_line) if rec_model._is_applicable_for(st_line, partner): lines_with_partner_per_model[rec_model].append((st_line, partner))