From 60a10352444a3d25114c0375d2665cdc7ade104f Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 20 Mar 2024 11:24:37 +0000 Subject: [PATCH] [IMP] stock_account: refactoring for checking restrict_partner_id Refactored the restrict_partner_id check in the stock_account module to make it more flexible for future updates. Now, it's easier to extend restrict_partner_id check without override the whole method. Related with https://github.com/odoo/odoo/pull/155694 closes odoo/odoo#158687 X-original-commit: 8a4c6e51a200c4b093571d4f2003b39de07fe4b1 Signed-off-by: Quentin Wolfs (quwo) --- addons/stock_account/models/stock_move.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index aef61b99129..02a3e56a491 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -551,6 +551,14 @@ class StockMove(models.Model): if analytic_line_vals: move.analytic_account_line_ids += self.env['account.analytic.line'].sudo().create(analytic_line_vals) + def _should_exclude_for_valuation(self): + """Determines if this move should be excluded from valuation based on its partner. + :return: True if the move's restrict_partner_id is different from the company's partner (indicating + it should be excluded from valuation), False otherwise. + """ + self.ensure_one() + return self.restrict_partner_id and self.restrict_partner_id != self.company_id.partner_id + def _account_entry_move(self, qty, description, svl_id, cost): """ Accounting Valuation Entries """ self.ensure_one() @@ -558,8 +566,7 @@ class StockMove(models.Model): if self.product_id.type != 'product': # no stock valuation for consumable products return am_vals - if self.restrict_partner_id and self.restrict_partner_id != self.company_id.partner_id: - # if the move isn't owned by the company, we don't make any valuation + if self._should_exclude_for_valuation(): return am_vals company_from = self._is_out() and self.mapped('move_line_ids.location_id.company_id') or False