From fde450b599316955a4d9062157b5675f9528cb8a Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 9 Mar 2023 12:55:24 +0000 Subject: [PATCH] [FIX] stock_account: reconcile kit Kit were not reconcile because the `_stock_account_anglo_saxon_reconcile_valuation` method try to match `account.move.line` and `stock.move` base on the product field. However in kit case, the moves are exploded in mutliple moves containing the kit's components. Due to that the matching is not made. To fix this issue we use the `purchase.order.line` that is share between the `stock.move` and `account.move.line` to retrieve them. closes odoo/odoo#114987 X-original-commit: f594c837c8a347abb48015d4e9bb0d5109228539 Signed-off-by: William Henrotin (whe) --- addons/purchase_stock/models/stock_move.py | 8 +++++++- addons/stock_account/models/account_move.py | 5 ++--- addons/stock_account/models/stock_move.py | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/purchase_stock/models/stock_move.py b/addons/purchase_stock/models/stock_move.py index 992f3a07901..4f07686073b 100644 --- a/addons/purchase_stock/models/stock_move.py +++ b/addons/purchase_stock/models/stock_move.py @@ -212,4 +212,10 @@ class StockMove(models.Model): ) def _get_all_related_aml(self): - return super()._get_all_related_aml() | self.purchase_line_id.invoice_lines.move_id.line_ids + # The back and for between account_move and account_move_line is necessary to catch the + # additional lines from a cogs correction + return super()._get_all_related_aml() | self.purchase_line_id.invoice_lines.move_id.line_ids.filtered( + lambda aml: aml.product_id == self.purchase_line_id.product_id) + + def _get_all_related_sm(self, product): + return super()._get_all_related_sm(product) | self.filtered(lambda m: m.purchase_line_id.product_id == product) diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index d767f35cd17..64d1bea1ec1 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -233,10 +233,9 @@ class AccountMove(models.Model): lambda line: line.product_id == prod and line.account_id == product_interim_account and not line.reconciled) # Search for anglo-saxon lines linked to the product in the stock moves. - product_stock_moves = stock_moves.filtered(lambda stock_move: stock_move.product_id == prod) + product_stock_moves = stock_moves._get_all_related_sm(prod) product_account_moves |= product_stock_moves._get_all_related_aml().filtered( - lambda line: line.account_id == product_interim_account and not line.reconciled and line.move_id.state == "posted" and - line.product_id == prod + lambda line: line.account_id == product_interim_account and not line.reconciled and line.move_id.state == "posted" ) # Reconcile. diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index 11743b0484b..e6fb20946ec 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -604,3 +604,6 @@ class StockMove(models.Model): def _get_all_related_aml(self): return self.account_move_ids.line_ids + + def _get_all_related_sm(self, product): + return self.filtered(lambda m: m.product_id == product)