Djamel Touati ad253ef4c2 [FIX] purchase: set the correct price in alternative PO
Steps to reproduce the bug:
- Create a storable product “P1”:
    - Price at “Wood corner”:
        - $5, min qty =1
    - Price at “Open wood:
        - $6, min qty = 1
        - $4, min qty = 10

- Create a purchase order at wood corner:
    - 100 units
> the price is automatically computed at $500

- Go to Alternative tab in the PO:
   - Create a one for “Openwood” and copy lines

Problem:
The price for 100 units is computed as $600 instead of $400.

When we create the alternative purchase order, in the "create" function
of “purchase.order.line,” we receive only the quantity as "qty=100" in
the values. Therefore, the missing fields should be prepared.

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1102

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1102

First, the line is created with the received values (“qty=100”), and
the price_unit is computed correctly as $4.

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1400

So, the price_unit is computed correctly at $4

However, the “onchange_product_id” function is then called, resetting
the price_unit and product_qty to 0.

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1401

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1176

Afterward, the “_suggest_quantity()” function is called

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1180

suggesting a minimal quantity based on the seller (so=1).

https://github.com/odoo/odoo/blob/a9cbd2a2ae2e21f1ba14379aecd908c44497b8ab/addons/purchase/models/purchase.py#L1363

Therefore, the price_unit is computed based on qty=1, resulting in $6.

Finally, the price is returned because it is the only missing field.

opw-3497825

closes odoo/odoo#137774

X-original-commit: 0781198f1b5e5d6a4e2722ea3c663b74fb131bc3
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
2023-10-06 07:12:13 +00:00
…
…
…
…
…

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials

S
Description
No description provided
Readme LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%