-
Couldn't load subscription status.
- Fork 30.2k
[FIX] stock,mrp: scrap kit #176186
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
[FIX] stock,mrp: scrap kit #176186
Conversation
|
robodoo r+ |
|
@Whenrow you may want to rebuild or fix this PR as it has failed CI. |
e5ede0e to
ecb468c
Compare
|
robodoo r+ |
|
@adwid you can't review+. Skill issue. |
|
robodoo r+ |
|
Trop aimable |
When scrapping a kit, it leads to incorrect behaviours **Case 01:** 1. Create a storable kit with one storable component 2. Validate a scrap order with that kit 3. Open the product moves Error: we moved the kit instead of its component We first create a draft SM with its SML: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L145 https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L112 During the SML creation, we check if we should recompute the state of the SM: https://github.com/odoo/odoo/blob/dc0917d2a55a12e5c30d413a46e2c16190fd8a08/addons/stock/models/stock_move_line.py#L344-L355 `reservation` is `True`, the SML has a quantity -> we recompute the state of the SM -> it is now assigned Back to the scrap, we now `_action_done` the kit SM https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L147 which leads to https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1827-L1830 Here is the problem: the SM has a demand, its state is not draft -> we don't confirm it -> we don't explode it Hence the error. This is the reason why the commit stops providing the scrap SM with an initial demand. That way, we will explode the SM and everything will work as expected **Case 02:** 1. Create a consumable kit with one storable component 2. Validate a scrap order with that kit Error: a server error is raised "Missing record [...]" This time, `reservation` is `False` (the diff comes from the kit type, consu vs stor, c.f. `_should_bypass_reservation`). Therefore, we explode it. Since we are in scrap mode, we generate SM with a zero demand: https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L464-L466 https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L527 Back to `_action_done`, we create the extra moves if needed: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1847-L1853 Here, our component SM has a done qty greater than its demand (reminder: it demand is zero), so we will create the extra move, confirm it and merge it with the initial one: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1799-L1802 Buuuuut... Step 2 in the use case, we validate the scrap order. Since we don't have such product on hand, we trigger a wizard with some default values: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L204-L219 And... Now you see where I'm going: when we create the extra move, we still have these default values in the context -> the extra move has a demand and(!) a done qty to 1. We merge it with the initial move: we are now scrapping a component with a demand equal to one and a done qty equal to 2. It will later lead to other inconsistencies (among them, the server error raised) opw-4090951
ecb468c to
573680b
Compare
|
robodoo override=ci/style |
|
@adwid you are not allowed to override 'ci/style'. |
|
We will never be friends, damn bot |
|
@Whenrow you are not allowed to override 'ci/style'. |
|
let's roll |
|
@agr-odoo you are not allowed to override 'ci/style'. |
|
robodoo override=ci/style |
|
robodoo r+ |
|
Odoo 18 will shine thanks to you both |
When scrapping a kit, it leads to incorrect behaviours **Case 01:** 1. Create a storable kit with one storable component 2. Validate a scrap order with that kit 3. Open the product moves Error: we moved the kit instead of its component We first create a draft SM with its SML: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L145 https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L112 During the SML creation, we check if we should recompute the state of the SM: https://github.com/odoo/odoo/blob/dc0917d2a55a12e5c30d413a46e2c16190fd8a08/addons/stock/models/stock_move_line.py#L344-L355 `reservation` is `True`, the SML has a quantity -> we recompute the state of the SM -> it is now assigned Back to the scrap, we now `_action_done` the kit SM https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L147 which leads to https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1827-L1830 Here is the problem: the SM has a demand, its state is not draft -> we don't confirm it -> we don't explode it Hence the error. This is the reason why the commit stops providing the scrap SM with an initial demand. That way, we will explode the SM and everything will work as expected **Case 02:** 1. Create a consumable kit with one storable component 2. Validate a scrap order with that kit Error: a server error is raised "Missing record [...]" This time, `reservation` is `False` (the diff comes from the kit type, consu vs stor, c.f. `_should_bypass_reservation`). Therefore, we explode it. Since we are in scrap mode, we generate SM with a zero demand: https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L464-L466 https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L527 Back to `_action_done`, we create the extra moves if needed: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1847-L1853 Here, our component SM has a done qty greater than its demand (reminder: it demand is zero), so we will create the extra move, confirm it and merge it with the initial one: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1799-L1802 Buuuuut... Step 2 in the use case, we validate the scrap order. Since we don't have such product on hand, we trigger a wizard with some default values: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L204-L219 And... Now you see where I'm going: when we create the extra move, we still have these default values in the context -> the extra move has a demand and(!) a done qty to 1. We merge it with the initial move: we are now scrapping a component with a demand equal to one and a done qty equal to 2. It will later lead to other inconsistencies (among them, the server error raised) opw-4090951 closes odoo#176186 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
When scrapping a kit, it leads to incorrect behaviours **Case 01:** 1. Create a storable kit with one storable component 2. Validate a scrap order with that kit 3. Open the product moves Error: we moved the kit instead of its component We first create a draft SM with its SML: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L145 https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L112 During the SML creation, we check if we should recompute the state of the SM: https://github.com/odoo/odoo/blob/dc0917d2a55a12e5c30d413a46e2c16190fd8a08/addons/stock/models/stock_move_line.py#L344-L355 `reservation` is `True`, the SML has a quantity -> we recompute the state of the SM -> it is now assigned Back to the scrap, we now `_action_done` the kit SM https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L147 which leads to https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1827-L1830 Here is the problem: the SM has a demand, its state is not draft -> we don't confirm it -> we don't explode it Hence the error. This is the reason why the commit stops providing the scrap SM with an initial demand. That way, we will explode the SM and everything will work as expected **Case 02:** 1. Create a consumable kit with one storable component 2. Validate a scrap order with that kit Error: a server error is raised "Missing record [...]" This time, `reservation` is `False` (the diff comes from the kit type, consu vs stor, c.f. `_should_bypass_reservation`). Therefore, we explode it. Since we are in scrap mode, we generate SM with a zero demand: https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L464-L466 https://github.com/odoo/odoo/blob/68f981d2a690addf0b70ddab498b556986752e49/addons/mrp/models/stock_move.py#L527 Back to `_action_done`, we create the extra moves if needed: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1847-L1853 Here, our component SM has a done qty greater than its demand (reminder: it demand is zero), so we will create the extra move, confirm it and merge it with the initial one: https://github.com/odoo/odoo/blob/6ed0d0ca2f90fef8cd020380b194498a9363267c/addons/stock/models/stock_move.py#L1799-L1802 Buuuuut... Step 2 in the use case, we validate the scrap order. Since we don't have such product on hand, we trigger a wizard with some default values: https://github.com/odoo/odoo/blob/72c4a2352c1184f5e8c1f238d29eb94e37d01115/addons/stock/models/stock_scrap.py#L204-L219 And... Now you see where I'm going: when we create the extra move, we still have these default values in the context -> the extra move has a demand and(!) a done qty to 1. We merge it with the initial move: we are now scrapping a component with a demand equal to one and a done qty equal to 2. It will later lead to other inconsistencies (among them, the server error raised) opw-4090951 closes odoo#176186 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Issue:
In 17.0 and saas-17.2, The Cost of Scrap section does not appear
in the the Cost Analysis Report despite having scrapped some components
during manufacturing.
Steps to reproduce:
1. Create a product with a BoM
2. Manufacture the product
3. Scrap some components during manufacturing
4. print the Cost Analysis Report
5. Notice the cost of scrap section does not appear in the report.
Solution:
- In v17.0, the Cost Analysis Report fails to include scrap costs
because `production_id` is not assigned to scrap stock moves.
-This issue was introduced by changes in PR odoo#176186,
which cleared the context, preventing production_id from being set.
-This commit sets the production_id on scrap stock moves
opw-4183097


When scrapping a kit, it leads to incorrect behaviours
Case 01:
Error: we moved the kit instead of its component
We first create a draft SM with its SML:
odoo/addons/stock/models/stock_scrap.py
Line 145 in 72c4a23
odoo/addons/stock/models/stock_scrap.py
Line 112 in 72c4a23
During the SML creation, we check if we should recompute the state
of the SM:
odoo/addons/stock/models/stock_move_line.py
Lines 344 to 355 in dc0917d
reservationisTrue, the SML has a quantity -> we recompute thestate of the SM -> it is now assigned
Back to the scrap, we now
_action_donethe kit SModoo/addons/stock/models/stock_scrap.py
Line 147 in 72c4a23
which leads to
odoo/addons/stock/models/stock_move.py
Lines 1827 to 1830 in 6ed0d0c
Here is the problem: the SM has a demand, its state is not draft
-> we don't confirm it
-> we don't explode it
Hence the error. This is the reason why the commit stops providing
the scrap SM with an initial demand. That way, we will explode the
SM and everything will work as expected
Case 02:
Error: a server error is raised "Missing record [...]"
This time,
reservationisFalse(the diff comes from the kittype, consu vs stor, c.f.
_should_bypass_reservation). Therefore,we explode it. Since we are in scrap mode, we generate SM with a
zero demand:
odoo/addons/mrp/models/stock_move.py
Lines 464 to 466 in 68f981d
odoo/addons/mrp/models/stock_move.py
Line 527 in 68f981d
Back to
_action_done, we create the extra moves if needed:odoo/addons/stock/models/stock_move.py
Lines 1847 to 1853 in 6ed0d0c
Here, our component SM has a done qty greater than its demand
(reminder: it demand is zero), so we will create the extra move,
confirm it and merge it with the initial one:
odoo/addons/stock/models/stock_move.py
Lines 1799 to 1802 in 6ed0d0c
Buuuuut... Step 2 in the use case, we validate the scrap order.
Since we don't have such product on hand, we trigger a wizard with
some default values:
odoo/addons/stock/models/stock_scrap.py
Lines 204 to 219 in 72c4a23
And... Now you see where I'm going: when we create the extra move,
we still have these default values in the context -> the extra move
has a demand and(!) a done qty to 1. We merge it with the initial
move: we are now scrapping a component with a demand equal to one
and a done qty equal to 2. It will later lead to other
inconsistencies (among them, the server error raised)
opw-4090951