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)