Skip to content

Commit

Permalink
[13.0][IMP] stock_account_product_run_fifo_hook: add hook for layer s…
Browse files Browse the repository at this point in the history
…election on out svl creation
  • Loading branch information
AaronHForgeFlow authored and EvaSForgeFlow committed Jun 30, 2023
1 parent cd2951d commit 82c17a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 6 additions & 9 deletions stock_account_product_run_fifo_hook/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ def _run_fifo_new(self, quantity, company):
# Find back incoming stock valuation layers (called candidates here)
# to value `quantity`.
qty_to_take_on_candidates = quantity
# START HOOK Search Candidates
candidates_domain = self._get_candidates_domain(company)
candidates = (
self.env["stock.valuation.layer"]
.sudo()
.with_context(active_test=False)
.search(
[
("product_id", "=", self.id),
("remaining_qty", ">", 0),
("company_id", "=", company.id),
]
)
.search(candidates_domain)
)
# END HOOK Search Candidates
new_standard_price = 0
tmp_value = 0 # to accumulate the value taken on the candidates
for candidate in candidates:
Expand All @@ -46,14 +43,14 @@ def _run_fifo_new(self, quantity, company):
"remaining_qty": candidate.remaining_qty - qty_taken_on_candidate,
"remaining_value": new_remaining_value,
}
# Start Hook
# Start Hook Prepare Candidate
candidate_vals = self._run_fifo_prepare_candidate_update(
candidate,
qty_taken_on_candidate,
value_taken_on_candidate,
candidate_vals,
)
# End Hook
# End Hook Prepare Candidate
candidate.write(candidate_vals)

qty_to_take_on_candidates -= qty_taken_on_candidate
Expand Down
8 changes: 8 additions & 0 deletions stock_account_product_run_fifo_hook/model/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ def _run_fifo_vacuum_prepare_candidate_update(
):
self.ensure_one()
return candidate_vals

def _get_candidates_domain(self, company):
candidates_domain = [
("product_id", "=", self.id),
("remaining_qty", ">", 0),
("company_id", "=", company.id),
]
return candidates_domain

0 comments on commit 82c17a7

Please sign in to comment.