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

[ADD] sale_order_price_recalculation: Module to allow to recalculate on demand sale order line prices #54

Merged
merged 1 commit into from
Sep 1, 2015

Conversation

pedrobaeza
Copy link
Member

Recalculation of sale order lines prices on demand

This module adds a button on sale orders below pricelist that recalculates the
prices of the order lines that contain a product in them.

It is launched manually as a button to get the user decide if he/she wants to
recalculate prices when pricelist is changed.

Usage

Inside a sale order, you can click in any moment a button called
"(Recalculate prices)", that is next to the pricelist selection, to launch
a recalculation of all the prices of the lines, losing previous custom prices.

Known issues / Roadmap

  • In a sale order with lot of lines, the recalculation may slow down, because
    sale general data (amount untaxed, amount taxed...) are recalculated for
    each line.

@sbidoul
Copy link
Member

sbidoul commented Oct 31, 2014

Thanks @pedrobaeza!

I see this module calls product_id_change while the other that was mentioned on the mailing list calss price_get. Therefore this one does a bit more than updating the price.

I'm not sure which of the two approaches is better, although I would lend towards a change of the price only, which better correspond to the button name.

What do people think?

@pedrobaeza
Copy link
Member Author

Well, in fact, call product_id_change is the same as get the price, but avoiding possible side effects if the way the price is calculated changes. The same method is called when you change quantity, so you are not going to find things in the line that you don't want to get.

I do it this way because you can have other fields like discount modified (with module product_visible_discount), and the other method doesn't change that.

@clonedagain
Copy link

Code LGTM at first glance. I'll try to test on Monday

@rvalyi
Copy link
Member

rvalyi commented Nov 2, 2014

I just want to add that such code will be extremely slow on large orders line with 50+ lines because of the write on every line that will trigger a recomputation of order fields for each line.

This is okay as a 1st approach but would probably be better refactored later to collect the prices and then call a single write at the order level (with nested lines values) while disabling field recomputation and enabling them back after. We did that kind of trick for a customer in 6.1 for purchase and typically went from 15+ minutes to 20 secs on 70+ order lines (disclaimer: our localization adds a few computed fields; but still...)

@pedrobaeza
Copy link
Member Author

Hi, @rvalyi. Thanks for the suggestion. I will implement your approach, because indeed it scalates better. I let you know when I have it ready.

@vrenaville
Copy link
Contributor

This module is very similar as our module, so I approve this 👍

@pedrobaeza
Copy link
Member Author

@rvalyi Can you point me to which context key defers the computation of fields?, because I can't remember it.

@clonedagain
Copy link

@vrenaville do you think you could backport this to v7 so that we have a smooth migration path please?

@adrienpeiffer
Copy link

👍
Code review and tests with more than 200 lines in the same sale order.

True, record.date_order, False,
record.fiscal_position.id, False,
context=self.env.context)
line.write(res['value'])
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the names of the keyword arguments in this call to product_id_change, in order to preserve compatibility with overrides that change the order of the keyword arguments?
Doesn't the API compatibility layer take care of the context argument?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

For information, we encountered some issues with the same kind of code.. odoo/odoo#4698

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@StefanRijnhart
Copy link
Member

Is this still work in progress, as the tag implies?

@pedrobaeza
Copy link
Member Author

@StefanRijnhart, do you have any clue about what @rvalyi mentions?

@max3903 max3903 added this to the 8.0 milestone Feb 27, 2015
@@ -0,0 +1,8 @@
Recalculation of sale order lines prices on demand
Copy link
Member

Choose a reason for hiding this comment

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

Can we prettify this using OCA template ?

@StefanRijnhart
Copy link
Member

@pedrobaeza: looks like you could look at setting 'recompute' to False in the context, if you think that is safe.

@pedrobaeza
Copy link
Member Author

This one was one of my old pendings. @StefanRijnhart, I have tried the context argument, but it seems it's not working. Anyway, I prefer not to put it, because it can have side effects on other added computed fields on sale order lines. I have put a note on known issues.

I have also added some tests. Please review.

@pedrobaeza pedrobaeza force-pushed the 8.0-sale_order_recalculate_prices branch from 1ad0c1e to c801f40 Compare August 28, 2015 06:52
{
"name": "Price recalculation in sales orders",
"version": "8.0.1.0.0",
"depends": [
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

the licence miss

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

(fixed below)

@lmignon
Copy link
Sponsor Contributor

lmignon commented Aug 28, 2015

+1 with @gurneyalex concern

@pedrobaeza pedrobaeza changed the title [ADD] sale_order_recalculate_prices: Module to allow to recalculate on demand sale order line prices [ADD] sale_order_price_recalculation: Module to allow to recalculate on demand sale order line prices Aug 28, 2015
@pedrobaeza pedrobaeza force-pushed the 8.0-sale_order_recalculate_prices branch from c801f40 to 8046370 Compare August 28, 2015 10:38
@pedrobaeza
Copy link
Member Author

Changes done!

@pedrobaeza
Copy link
Member Author

All changes done!

@gurneyalex
Copy link
Member

👍

@gurneyalex
Copy link
Member

@lmignon if it's ok with you I'll merge.

qty=line.product_uom_qty, uom=line.product_uom.id,
qty_uos=line.product_uos_qty, uos=line.product_uos.id,
name=line.name, partner_id=order.partner_id.id, lang=False,
update_tax=True, date_order=order.date_order, packaging=False,
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

IMO, you should also provide the packaging from the line even if it's not used by default but if the method is redefined by others modules, the params is part of the api..

Copy link
Member Author

Choose a reason for hiding this comment

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

But this will add an unneeded dependency to sale_stock module. Are you sure this is needed?

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@pedrobaeza sorry for the noise. You are right. The filed packaging is not defined on the sale.order.line in this module. Strange to see a parameter for a field defined in an optional module...

@pedrobaeza pedrobaeza force-pushed the 8.0-sale_order_recalculate_prices branch from 8046370 to 03dbbd4 Compare August 28, 2015 16:37
…n demand sale order line prices

==================================================
Recalculation of sale order lines prices on demand
==================================================

This module adds a button on sale orders below pricelist that recalculates the
prices of the order lines that contain a product in them.

It is launched manually as a button to get the user decide if he/she wants to
recalculate prices when pricelist is changed.

Usage
=====

Inside a sale order, you can click in any moment a button called
"(Recalculate prices)", that is next to the pricelist selection, to launch
a recalculation of all the prices of the lines, losing previous custom prices.

Known issues / Roadmap
======================

* In a sale order with lot of lines, the recalculation may slow down, because
  sale general data (amount untaxed, amount taxed...) are recalculated for
  each line.
@lmignon
Copy link
Sponsor Contributor

lmignon commented Aug 29, 2015

👍

@pedrobaeza
Copy link
Member Author

Please merge this old one that it's already completed.

gurneyalex added a commit that referenced this pull request Sep 1, 2015
[ADD] sale_order_price_recalculation: Module to allow to recalculate on demand sale order line prices
@gurneyalex gurneyalex merged commit 14a70cd into OCA:8.0 Sep 1, 2015
@pedrobaeza pedrobaeza deleted the 8.0-sale_order_recalculate_prices branch September 15, 2015 15:02
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.

None yet