From f25c9b279021313a478c38f4143b9d3dcedd6031 Mon Sep 17 00:00:00 2001 From: Aaron ForgeFlow Date: Sun, 13 Jun 2021 22:19:11 +0200 Subject: [PATCH] [13.0][IMP]stock_account_product_run_fifo_hook: hook on condition to update standard price (#3) --- stock_account_product_run_fifo_hook/hooks.py | 17 ++++++++++++----- .../model/product.py | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/stock_account_product_run_fifo_hook/hooks.py b/stock_account_product_run_fifo_hook/hooks.py index f999349439b5..ff7a8807044d 100644 --- a/stock_account_product_run_fifo_hook/hooks.py +++ b/stock_account_product_run_fifo_hook/hooks.py @@ -62,11 +62,18 @@ def _run_fifo_new(self, quantity, company): # Update the standard price with the price of the last used candidate, # if any. - if new_standard_price and self.cost_method == "fifo": - self.sudo().with_context( - force_company=company.id - ).standard_price = new_standard_price - + # START HOOK update standard price + if hasattr(self, "_price_updateable"): + if self._price_updateable(new_standard_price): + self.sudo().with_context( + force_company=company.id + ).standard_price = new_standard_price + else: + if new_standard_price and self.cost_method == "fifo": + self.sudo().with_context( + force_company=company.id + ).standard_price = new_standard_price + # END HOOK update standard price # If there's still quantity to value but we're out of candidates, # we fall in the # negative stock use case. We chose to value the out move at the price diff --git a/stock_account_product_run_fifo_hook/model/product.py b/stock_account_product_run_fifo_hook/model/product.py index 26749e909e44..32bca9cd3d60 100644 --- a/stock_account_product_run_fifo_hook/model/product.py +++ b/stock_account_product_run_fifo_hook/model/product.py @@ -34,3 +34,7 @@ def _get_candidates_domain(self, company): ("company_id", "=", company.id), ] return candidates_domain + + def _price_updateable(self, new_standard_price=False): + self.ensure_one() + return new_standard_price and self.cost_method == "fifo"