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

[16.0][MIG] sale order price recalculation #2334

Conversation

aliciagaarzo
Copy link
Contributor

@aliciagaarzo aliciagaarzo commented Jan 12, 2023

Migration v16- module sale_order_price_recalculation

pedrobaeza and others added 30 commits January 12, 2023 13:32
…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.
* add choice to recompute price only
  This commit add the capability to reset sale order line
  without renaming sale order lines
* upgrade translation
* Split functionnalities reset prices/reset desciptions
* Move button under sale order lines
On certain set of installed modules, standard demo pricelist can be altered for giving
something different than the list price, making these tests to fail. We avoid it
creating our own pricelist with the fixed data that we want.
This way, all tracking events can take place.

Closes OCA#848
Currently translated at 100.0% (3 of 3 strings)

Translation: sale-workflow-12.0/sale-workflow-12.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-sale_order_price_recalculation/de/
Currently translated at 100.0% (3 of 3 strings)

Translation: sale-workflow-12.0/sale-workflow-12.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-sale_order_price_recalculation/zh_CN/
Currently translated at 100.0% (3 of 3 strings)

Translation: sale-workflow-12.0/sale-workflow-12.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-sale_order_price_recalculation/pt_BR/
Currently translated at 100.0% (3 of 3 strings)

Translation: sale-workflow-12.0/sale-workflow-12.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-sale_order_price_recalculation/it/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: sale-workflow-13.0/sale-workflow-13.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_order_price_recalculation/
Currently translated at 100.0% (3 of 3 strings)

Translation: sale-workflow-13.0/sale-workflow-13.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_order_price_recalculation/es/
With current inheritance, the buttons are only visible if you have the
security group "Lock Confirmed Sales" in your user.

As we need to be seen in all cases, we modify the inheritance.

TT37124
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: sale-workflow-13.0/sale-workflow-13.0-sale_order_price_recalculation
Translate-URL: https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_order_price_recalculation/
@aliciagaarzo aliciagaarzo mentioned this pull request Jan 12, 2023
97 tasks
- The price field does not exist and has been replaced by list_price
- The functions used to perform the calculation have ceased to exist and have been replaced by all those that are currently being used.
- Now it is also necessary to calculate the price list by order lines.
@rousseldenis
Copy link
Sponsor Contributor

/ocabot migration sale_order_price_recalculation

@OCA-git-bot OCA-git-bot added this to the 16.0 milestone Jan 25, 2023
@aliciagaarzo aliciagaarzo changed the title 16.0 mig sale order price recalculation [16.0][MIG] sale order price recalculation Jan 25, 2023
@rousseldenis
Copy link
Sponsor Contributor

@aliciagaarzo In fact, this behavior is fully supported in core:

https:/odoo/odoo/blob/16.0/addons/sale/models/sale_order.py#L936

Could you close this ?

Comment on lines +14 to +38
def _recompute_form_line_vals(self, fields):
"""Helper method for writing in line certain recomputed by onchanges fields."""
for line in self.mapped("order_line"):
vals = line._convert_to_write(line.read()[0])
if "product_tmpl_id" in line._fields:
vals["product_tmpl_id"] = line.product_tmpl_id
# we make this to isolate changed values:
line2 = self.env["sale.order.line"].new(vals)
line2.env.add_to_compute(
line2.product_id._fields["list_price"], line2.product_id
)
line2._compute_name()
line2._compute_price_unit()
line2._compute_tax_id()
line2._compute_pricelist_item_id()
line2._compute_discount()
line.write({field: line2[field] for field in fields})

def recalculate_prices(self):
self._recompute_form_line_vals(["price_unit", "discount", "pricelist_item_id"])
return True

def recalculate_names(self):
self._recompute_form_line_vals(["name"])
return True
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@aliciagaarzo Thank you for this work. Unfortunately, this module should not be migrated since this functionality is now provided natively by odoo. You can check the method action_update_prices from the sale.order model.

@aliciagaarzo aliciagaarzo deleted the 16.0-mig-sale_order_price_recalculation branch January 26, 2023 14:45
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.