Skip to content

Commit

Permalink
[13.0][IMP]stock_account_product_run_fifo_hook: hook on condition to …
Browse files Browse the repository at this point in the history
…update standard price (#3)
  • Loading branch information
AaronHForgeFlow authored and EvaSForgeFlow committed Jun 30, 2023
1 parent 82c17a7 commit f25c9b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 12 additions & 5 deletions stock_account_product_run_fifo_hook/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stock_account_product_run_fifo_hook/model/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f25c9b2

Please sign in to comment.