Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][REF] product_cost_price_avco_sync: Refactoring for handling all the changes at once #1697

Open
wants to merge 2 commits into
base: 15.0
Choose a base branch
from

Conversation

pedrobaeza
Copy link
Member

The current problem is that when there are crossed changes between products (like in MRP, having changes in components that affect manufactured products), a lot of writes are done, as each product is processed separately, and thus, there can be continuous resync between them.

With this new method, we can process the whole sync in one step, blocking it till pending data is processed, avoiding continuos sync triggerings.

Main changes:

  • Extract the processing code corresponding to one SVL to the method _process_avco_sync_one.

  • Include all the state variables - previous_unit_cost, previous_qty, inventory_processed and unit_cost_processed - into a super-structure (called svls_dic, which previously holds the SVL values for the product being synchronized). This super-structure is a dictionary having as keys the pair (product, company), and the value another dictionary with such state variables and storing the SVL values in "svls" key.

  • 2 main loops for iterating in the elements to sync, one for the pair (product, company), and other inside for the SVLs to sync. First while loop is driven by these control variables:

    • index: which position - pair (product, company) - to process
    • reloop: activated when something is blocking
    • any_processed: to control if there's no progress in a whole loop

    The second one uses the value inside "to_sync" key of the super-structure to know which is the SVL to sync currently, and when processed, we dynamically look for the next one.

  • _preprocess_main_svl_line and _preprocess_rest_svl_to_sync dissapears in favor of one control method: _is_avco_sync_processable, which can return a falsy value if we can't sync that SVL.

  • We add extra things to sync modifying the super-structure in _process_avco_sync_one - add new (product, company) keys or change "to_sync" value -.

  • All the AVCO sync methods have been converted to private.

  • The processing of the SVLs previous to the one to sync is done in a light way, but using the same code of _process_avco_sync_one. After obtaining the state variables, the SVLs dict is discarded for saving memory.

@Tecnativa TT50028

@pedrobaeza pedrobaeza added this to the 15.0 milestone Sep 9, 2024
@OCA-git-bot
Copy link
Contributor

Hi @sergio-teruel, @carlosdauden,
some modules you are maintaining are being modified, check this out!

@pedrobaeza pedrobaeza force-pushed the 15.0-ref-product_cost_price_avco_sync branch 2 times, most recently from 3d9caef to 24e4267 Compare September 24, 2024 18:12
…changes at once

The current problem is that when there are crossed changes between
products (like in MRP, having changes in components that affect
manufactured products), a lot of writes are done, as each product is
processed separately, and thus, there can be continuous resync between
them.

With this new method, we can process the whole sync in one step,
blocking it till pending data is processed, avoiding continuos sync
triggerings.

Main changes:

- Extract the processing code corresponding to one SVL to the method
  `_process_avco_sync_one`.
- Include all the state variables - previous_unit_cost,
  previous_qty, inventory_processed and unit_cost_processed - into a
  super-structure (called `svls_dic`, which previously holds the SVL
  values for the product being synchronized).
  This super-structure is a dictionary having as keys the pair
  (product, company), and the value another dictionary with such state
  variables and storing the SVL values in "svls" key.
- 2 main loops for iterating in the elements to sync, one for the
  pair (product, company), and other inside for the SVLs to sync.
  First `while` loop is driven by these control variables:

  * index: which position - pair (product, company) - to process
  * reloop: activated when something is blocking
  * any_processed: to control if there's no progress in a whole loop

  The second one uses the value inside "to_sync" key of the
  super-structure to know which is the SVL to sync currently, and when
  processed, we dynamically look for the next one.
- `_preprocess_main_svl_line` and `_preprocess_rest_svl_to_sync`
  dissapears in favor of one control method: `_is_avco_sync_processable`,
  which can return a falsy value if we can't sync that SVL.
- We add extra things to sync modifying the super-structure in
  `_process_avco_sync_one` - add new (product, company) keys or change
  "to_sync" value -.
- All the AVCO sync methods have been converted to private.
- The processing of the SVLs previous to the one to sync is done in a
  light way, but using the same code of `_process_avco_sync_one`.
  After obtaining the state variables, the SVLs dict is discarded for
  saving memory.

TT50028
@pedrobaeza pedrobaeza force-pushed the 15.0-ref-product_cost_price_avco_sync branch 2 times, most recently from 1aec223 to 405c4fa Compare October 10, 2024 09:59
@pedrobaeza pedrobaeza force-pushed the 15.0-ref-product_cost_price_avco_sync branch from 405c4fa to ee9258d Compare October 18, 2024 15:29
For performance reasons, remove all the remaining values stuff, which
is only valid for FIFO.
@pedrobaeza pedrobaeza force-pushed the 15.0-ref-product_cost_price_avco_sync branch from ee9258d to 64b0a54 Compare October 18, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants