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

[IMP] stock_quant_merge: Merge quant at install + hook for inherit merge #119

Closed
wants to merge 3 commits into from

Conversation

pedrobaeza
Copy link
Member

This PR improves 2 things:

  • It provides an installation hook to clean up existing split quants.
  • It provides a hook for inheriting the values that are written in the merged quant.

@pedrobaeza
Copy link
Member Author

cc @oihane @clonedagain

@@ -19,14 +19,20 @@ def _mergeable_domain(self):
('lot_id', '=', self.lot_id.id),
('package_id', '=', self.package_id.id),
('location_id', '=', self.location_id.id),
('reservation_id', '=', False),
('reservation_id', '=', self.reservation_id.id),

Choose a reason for hiding this comment

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

is this change related to the new features or is it a bug fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to allow a merging from the init hook of any of possible quants. Imagine that you have reserved 2 quants for the same move. This one allows to merge then in only one.

Choose a reason for hiding this comment

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

I think if we merge quants with different "in date" values, we'll be introducing wrong results in the FIFO/LIFO removal strategy.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, we can add that condition on the mergeable domain.

@clonedagain
Copy link

That looks sane, but the tests are not passing anymore. Maybe you need to update them since you use another product?

@pedrobaeza
Copy link
Member Author

Sorry about the test. I try only with the second test (the one that I have added), and forget the first one. I'll change it.

@clonedagain
Copy link

@pedrobaeza hehe so it does happen even to the best of us :)
No problem, just ping me when it's fixed.

@pedrobaeza
Copy link
Member Author

Done

@clonedagain
Copy link

Looks fine from reading the code. I'll try to test it on our big DB (~3M quants) but I fear the install may be too long for default CPU limits. If such is the case, maybe a warning should be added to the README.

@pedrobaeza
Copy link
Member Author

@clonedagain
Copy link

I was specifically thinking of a warning in the line of "this may fail to install on big databases if the CPU limit is too low"

@pedrobaeza
Copy link
Member Author

Warning added on the README

@pedrobaeza
Copy link
Member Author

Can you please review this again?

@@ -7,13 +7,21 @@ Quant merge
===========

Odoo splits quants each time a reservation is done: this module makes Odoo
merge them back if they still meet the following requirements:
merge them back when you unserve them if they still meet the following
Copy link
Member

Choose a reason for hiding this comment

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

s/unserve/unreserve/

@gurneyalex
Copy link
Member

this looks quite nice. 👍 once small typo is fixed.

I'm wondering: why should I install this? Is there a perf gain on a db with a large number of quants? Something else? If so, I think it deserves mentioning in the README.

And if there is a huge perf gain, maybe we could make a PR on odoo master?

@pedrobaeza
Copy link
Member Author

@gurneyalex, this is more or less like the Windows Disk Defragmenter, but with quants instead of sectors.

@clonedagain
Copy link

@pedrobaeza I was wondering if doing this would not introduce wrong results to the dated valuation?
In the view stock_history the standard joins the moves and the quants, wouldn't merging the quants make it count wrong quantities?

@pedrobaeza
Copy link
Member Author

Well, I don't know, because I haven't digged in that view. It depends on what quantity field takes. Can you check it?

@clonedagain
Copy link

My understanding is that the stock_history counts the quantity of the moved quants, so I think that if we merge all the possible quants we'll be counting some quantities double.

So I think we should only merge quants which are used in the same moves.

@@ -34,7 +40,8 @@ def merge_stock_quants(self):
for quant in quants:
if (self._get_latest_move(quant2merge) ==
self._get_latest_move(quant)):
quant2merge.sudo().qty += quant.qty
quant2merge.sudo().write(
self._get_merged_vals(quant2merge, quant))
cost += quant.cost
cont += 1

Choose a reason for hiding this comment

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

If you're going to merge all the possible quants, some will have different costs, so you should be doing a weighted average like the standard does in the dated valuation (it's changed recently: odoo/odoo@1d7c120)

@gurneyalex
Copy link
Member

setting needs fixing following @clonedagain's remark

@pedrobaeza
Copy link
Member Author

cc @Tecnativa

@rafaelbn
Copy link
Member

@pedrobaeza could you please review comments of this PR? Thanks

@gurneyalex
Copy link
Member

needs rebasing

@yajo
Copy link
Member

yajo commented Aug 26, 2016

Code seems alright, glitches have already been commented. Waiting for fixes and rebase to do functional review (note to self: uninstall module, unreserve quant, install module, only 1 quant should be there).

@pedrobaeza
Copy link
Member Author

We have lost interest in this after handling this with the customer in another way. If someone wants to take over the work, please make another PR. I close meanwhile.

@pedrobaeza pedrobaeza closed this Apr 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants