Skip to content

Conversation

@AungKoKoLin1997
Copy link
Contributor

@AungKoKoLin1997 AungKoKoLin1997 commented Aug 20, 2024

Superseding of #1527

In this PR, I address the following points:

  • Standard migration
  • Improved code by using the Odoo standard function _get_fifo_candidates() and adjustments to _get_price_unit()
  • Fixed the issue proposed in [15.0][ADD] stock_valuation_fifo_lot #1350 (comment)
  • Avoid completely overriding _run_fifo() and use the standard behavior.
  • Update the product's standard price to the first available lot price.
  • Improve _get_price_unit() to retrieve the value from the most recent incoming move line for the lot for the No PO (e.g. customer returns) stock moves.
  • Add quantity and value-related fields in stock_move_line to cover all cases including multiple lots exist in an SVL record, and it is unclear which lot's remaining quantity is being delivered(Eg. Receive serials 001, 002 and 003 for an incoming move. Deliver 002, return 002 and deliver 002 again.)
  • Add force_fifo_lot_id in stock_move_line to handle cases where a delivery needs to be made for an existing lot created before the installation of this module (e.g., lots 001 and 002 were received, lot 002 was delivered before the module's installation, and lot 001 is delivered after the module is installed).
  • Add a post_init_hook to update the lot_ids in SVL for existing records and to update the field values in existing stock_move_line records.

Depends on odoo/odoo#180245
@qrtl QT4650

@AungKoKoLin1997
Copy link
Contributor Author

AungKoKoLin1997 commented Aug 21, 2024

Test failed from stock_picking_line_sequence is fixed at #1557.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from b60bb4e to 71c8a67 Compare August 21, 2024 08:19
@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as ready for review August 21, 2024 08:19
@AungKoKoLin1997
Copy link
Contributor Author

@matt454357
Can you please review this PR and bring your ideas from your module OCA/stock-logistics-warehouse#2139 as we talked?

@matt454357
Copy link

matt454357 commented Aug 21, 2024

I started a review, and will post some suggestions.

@AungKoKoLin1997
Copy link
Contributor Author

@matt454357
What I am thinking is that I will handle adding the option for a single lot/serial per SVL record or multiple lots/serials per SVL record in this PR (since some users may not need a single lot/serial per SVL).

After you review and the PR is merged, you can create a new PR to follow up on your idea.
Or would you prefer to include your idea as a new commit in this PR by creating a PR in our repository?

What do you think?

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 71c8a67 to 07a5f63 Compare August 22, 2024 06:57
@AungKoKoLin1997
Copy link
Contributor Author

I will handle adding the option for a single lot/serial per SVL record or multiple lots/serials per SVL record in this PR (since some users may not need a single lot/serial per SVL).

@matt454357 I will not add this enhancement in the current PR because it is not related to migration, and there is no use case with the current design. So, could you please handle this when you work on revaluation?

@matt454357
Copy link

I think it's a good idea to finish this migration PR, and then do a follow up PR. And, I'm happy to do the follow up PR. However, there a couple of problems with allowing multiple lots/serials per SVL.

Maybe this initial migration should prevent revaluation of tracked products?

Maybe also raise an error when _get_price_unit() is called with multiple lot_ids?

@matt454357
Copy link

The believe PR #1677 supports the idea of enforcing single lot/serial per SVL.

Copy link

@matt454357 matt454357 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just commenting on this PR, not suggesting that we make these changes immediately.

"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock_account", "stock_no_negative", "mrp_landed_costs"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should depend on mrp_landed_costs. Could that be handled in a separate module?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move to a separate module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I will handle it.

if not self.company_id.use_lot_get_price_unit_fifo:
return super()._get_price_unit()
if (
not self.purchase_line_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on purchase module, which I guess is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added hasattr(self, "purchase_line_id") in the conditon. So, there is no issue I guess.

if (
not self.purchase_line_id
and self.product_id.cost_method == "fifo"
and len(self.lot_ids) == 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise an error when len(self.lot_ids) > 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any concerns or inconveniences if we use Odoo's standard behavior for this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise an error when len(self.lot_ids) > 1?

I think we could make it configurable if the community requires it. I don't have a strong need for that at the moment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, single lot per SVL would not work when migrating/installing with existing data. So, I don't think we can do that.

@AungKoKoLin1997
Copy link
Contributor Author

I think it's a good idea to finish this migration PR, and then do a follow up PR. And, I'm happy to do the follow up PR. However, there a couple of problems with allowing multiple lots/serials per SVL.

Thanks for the pointer and your interest in following up. What do you think of my idea of adding an option to choose a single or multiple lot/serial per SVL? As I mentioned, I don't want to make this adjustment in the migration PR because it would make the module bigger, and the community might be less interested in reviewing it. So, my idea is to get this PR merged quickly and then follow up with the changes.

@matt454357
Copy link

Yes, keep this PR small.

Regarding the option to choose between multiple or single lot per SVL: I'm not sure why someone would want multiple, but it sounds like you have a use case in mind. So, I suppose it's fine, as long as we raise errors for the issues described above.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 07a5f63 to 2a2dfb9 Compare August 23, 2024 08:58
@AungKoKoLin1997
Copy link
Contributor Author

@TheerayutEncoder
I have separated the module for passing lot_producing_id of mrp_production_ids to the SVL when adding the landed cost for these MOs, as you proposed in this commit.
What do you think about it?
Additionally, I am not entirely sure of the purpose of this, since the remaining_qty of the SVL for landed costs is 0.0, and I believe these SVLs will not be considered when _run_fifo() is called, if I understand correctly. Is this intended for user experience, to see the related lot_ids in the SVL? Could you please explain the initial purpose?

@AungKoKoLin1997
Copy link
Contributor Author

What do you think of my idea of adding an option to choose a single or multiple lot/serial per SVL?

@matt454357 Please let me handle this part and include it in this PR because we urgently need this module, and I don't know when this PR will be merged.

@matt454357
Copy link

@AungKoKoLin1997 any contribution you make is very much appreciated, Do it the way you feel is best, and I will work with it.

Copy link

@matt454357 matt454357 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from fbff13d to a7a187c Compare September 5, 2024 09:13
if (
not self.purchase_line_id
and self.product_id.cost_method == "fifo"
and len(self.lot_ids) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise an error when len(self.lot_ids) > 1?

I think we could make it configurable if the community requires it. I don't have a strong need for that at the moment.

@rousseldenis
Copy link
Contributor

/ocabot migration stock_valuation_fifo_lot

@OCA-git-bot OCA-git-bot added this to the 16.0 milestone Sep 20, 2024
@OCA-git-bot OCA-git-bot mentioned this pull request Sep 20, 2024
75 tasks
@matt454357
Copy link

We will also need odoo/odoo#179447, in order to do revaluation (later).

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 6f75469 to 6d0c7c6 Compare March 7, 2025 08:43
@AungKoKoLin1997
Copy link
Contributor Author

I squashed the commits.

…ility

- Adapt Odoo's standard method _get_fifo_candidates.
- Improve _get_price_unit to retrieve the value from the most recent incoming move line for the lot in No PO stock moves (e.g., customer returns)
  and make the logic configurable to also support Odoo’s standard behavior.
- Add test cases
- Enhances stock_valuation_layer handling for deliveries when products were received before this module was installed.
  Previously, missing lot_ids in older valuation records led to incorrect valuations.
  This update ensures accurate cost calculations during deliveries.
  Related Link: OCA#1350 (comment)
- Add lot_ids in search view
- Avoid completely overriding _run_fifo and use the standard behavior.
- Add quantity and value-related fields in stock_move_line to cover all cases including multiple lots exist in an SVL record,
  and it is unclear which lot's remaining quantity is being delivered(Eg. Receive serials 001, 002 and 003 for an incoming move. Deliver 002, return 002 and deliver >
- Add force_fifo_lot_id in stock_move_line to handle cases where a delivery needs to be made for an existing lot created before the installation of this module
  (e.g., lots 001 and 002 were received, lot 002 was delivered before the module's installation, and lot 001 is delivered after the module is installed).
- Add a post_init_hook to update the lot_ids in SVL for existing records and to update the field values in existing stock_move_line records.
- Remove stock_no_negative from dependency and check negative inventory is created when SVL is created for delivery.
- Remove updating standard price
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 6d0c7c6 to 9d7ddec Compare March 10, 2025 01:24
Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used in production now.

kanda999

This comment was marked as duplicate.

Copy link

@kanda999 kanda999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't review latest code. I couldn't approve this yet.

@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as draft April 16, 2025 08:20
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch 2 times, most recently from 3824e2c to 3580456 Compare April 21, 2025 07:04
@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as ready for review April 21, 2025 07:05
Copy link

@kanda999 kanda999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 3580456 to 8988b91 Compare April 21, 2025 10:16
Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review on the revaluation feature.

all_candidates = self._sort_by_all_candidates(all_candidates, sort_by)
return all_candidates

# Depends on https://github.com/odoo/odoo/pull/180245
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this comment.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 629e739 to 19bd99b Compare April 24, 2025 07:22
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 19bd99b to 2cc88f1 Compare April 24, 2025 08:23
Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module now handles revaluation for specific lots.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-stock_valuation_fifo_lot branch from 25b2dd7 to 203e476 Compare July 9, 2025 09:50
Copy link

@kanda999 kanda999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review: it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.