[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) <quwo@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user