-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a means of resolving conflicts, update readme
- Loading branch information
1 parent
9d5d4d2
commit fa44d0d
Showing
18 changed files
with
291 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import models | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2024 Quartile (https://www.quartile.co) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import SUPERUSER_ID, api | ||
from odoo.tools import float_is_zero | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
|
||
svls = env["stock.valuation.layer"].search([("stock_move_id", "!=", False)]) | ||
for svl in svls: | ||
svl.lot_ids = svl.stock_move_id.lot_ids | ||
if not svl.lot_ids: | ||
continue | ||
if svl.quantity <= 0: # Skip outgoing ones | ||
continue | ||
if svl.product_id.with_company(svl.company_id.id).cost_method != "fifo": | ||
continue | ||
svl_consumed_qty = svl_consumed_qty_bal = svl.quantity - svl.remaining_qty | ||
if not svl_consumed_qty: | ||
continue | ||
svl_total_value = svl.value + sum(svl.stock_valuation_layer_ids.mapped("value")) | ||
svl_consumed_value = svl_total_value - svl.remaining_value | ||
product_uom = svl.product_id.uom_id | ||
for ml in svl.stock_move_id.move_line_ids.sorted("id"): | ||
ml_uom = ml.product_uom_id | ||
ml_qty = ml_uom._compute_quantity(ml.qty_done, product_uom) | ||
qty_to_allocate = min(svl_consumed_qty_bal, ml_qty) | ||
ml.qty_consumed += product_uom._compute_quantity(qty_to_allocate, ml_uom) | ||
svl_consumed_qty_bal -= qty_to_allocate | ||
ml.value_consumed += svl_consumed_value * qty_to_allocate / svl_consumed_qty | ||
if float_is_zero(svl_consumed_qty_bal, precision_rounding=ml_uom.rounding): | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 Quartile (https://www.quartile.co) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class StockLot(models.Model): | ||
_inherit = "stock.lot" | ||
|
||
is_force_fifo_candidate = fields.Boolean( | ||
compute="_compute_is_force_fifo_candidate", | ||
store=True, | ||
help="Technical field to indicate that the lot has no on-hand quantity but has " | ||
"a remaining value in FIFO valuation terms.", | ||
) | ||
|
||
@api.depends( | ||
"quant_ids.quantity", "product_id.stock_move_ids.move_line_ids.qty_remaining" | ||
) | ||
def _compute_is_force_fifo_candidate(self): | ||
for lot in self: | ||
if lot.product_id.cost_method != "fifo": | ||
continue | ||
if not self.env["stock.move.line"].search( | ||
[("lot_id", "=", lot.id), ("qty_remaining", ">", 0)] | ||
): | ||
continue | ||
lot.is_force_fifo_candidate = not bool( | ||
lot.quant_ids.filtered( | ||
lambda x: x.location_id.usage == "internal" and x.quantity | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
If necessary, update the 'Use FIFO cost by lot' setting under Inventory > Configuration > Settings to use the lot cost instead of the standard _get_price() behavior when there is no relation to a purchase order in the stock move. | ||
(enabled by default). | ||
Disable the 'Use Last Lot/Serial Cost for New Stock' setting under *Inventory > | ||
Configuration > Settings*, which is enabled by default, to use the standard | ||
`_get_price()` behavior instead of the lot cost, for receipts of specific lots/serials | ||
with no link to a purchase order (i.e. customer returns and positive inventory | ||
adjustments). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
* `Quartile <https://www.quartile.co>`__: | ||
|
||
* Aung Ko Ko Lin | ||
|
||
* Yoshi Tashiro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
This module is used to calculate FIFO cost by lot. | ||
This module changes the scope of FIFO cost calculation to specific lots/serials (as | ||
opposed to products), effectively achieving Specific Identification costing method. | ||
|
||
Example: Lot-Level Costing | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- Purchase: | ||
|
||
- Lot A: 100 units at $10 each. | ||
- Lot B: 100 units at $12 each. | ||
|
||
- Sale: | ||
|
||
- 50 units from Lot B. | ||
|
||
- COGS Calculation: | ||
|
||
- 50 units * $12 = $600 assigned to COGS. | ||
|
||
- Ending Inventory: | ||
|
||
- Lot A: 100 units at $10 each. | ||
- Lot B: 50 units at $12 each. | ||
|
||
Main UI Changes | ||
~~~~~~~~~~~~~~~ | ||
|
||
- Stock Valuation Layer | ||
|
||
- Adds the following field: | ||
|
||
- 'Lots/Serials': Taken from related stock moves. | ||
|
||
- Stock Move Line | ||
|
||
- Adds the following fields: | ||
|
||
- 'Qty Consumed' [*]_: Consumed quantity by outgoing moves. | ||
- 'Value Consumed' [*]_: Consumed value by outgoing moves. | ||
- 'Qty Remaining' [*]_: Remaining quantity (the total by product should match that | ||
of the inventory valuation). | ||
- 'Value Remaining' [*]_: Remaining value (the total by product should match that | ||
of the inventory valuation). | ||
- 'Force FIFO Lot/Serial': Used when you are stuck by not being able to find a FIFO | ||
balance for the lot in an outgoing move line. | ||
|
||
.. [*] Updated only for valued incoming moves of the products with FIFO costing method. | ||
The values here represent the theoretical figures in terms of FIFO costing, | ||
meaning that they may differ from the actual stock situation especially for | ||
those updated at the installation of this module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Process an outgoing move with a lot/serial for a product of FIFO costing method, and the | ||
costs are calculated based on the lot/serial. | ||
|
||
You will get a user error in case the lot/serial of your choice (in an outgoing move) | ||
does not have a FIFO balance (i.e. there is no remaining quantity for the incoming move | ||
lines linked to the candidate SVL; this is expected to happen for lots/serials created | ||
before the installation of this module, unless your actual inventory operations have | ||
been strictly FIFO). In such situations, you should select a "rogue" lot/serial (one | ||
that still exists in terms of FIFO costing, but not in reality, due to the inconsistency | ||
carried over from the past) in the 'Force FIFO Lot/Serial' field so that this lot/serial | ||
is used for FIFO costing instead. |
Oops, something went wrong.