Skip to content

Commit 512af42

Browse files
authored
Merge pull request #2378 from ForgeFlow/13.0-mig-stock_landed_costs-script
[13.0][MIG] stock_landed_costs
2 parents 3941bd1 + e382ed6 commit 512af42

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---Models in module 'stock_landed_costs'---
2+
---Fields in module 'stock_landed_costs'---
3+
stock_landed_costs / account.move.line / is_landed_costs_line (boolean): NEW
4+
# DONE: post-migration: filled it when corresponding
5+
6+
stock_landed_costs / product.template / split_method (selection) : DEL selection_keys: ['by_current_cost_price', 'by_quantity', 'by_volume', 'by_weight', 'equal']
7+
# NOTHING TO DO: it's used instead the split_method of stock.landed.cost.lines
8+
9+
stock_landed_costs / res.company / lc_journal_id (many2one) : NEW relation: account.journal
10+
stock_landed_costs / stock.landed.cost / activity_ids (one2many) : NEW relation: mail.activity
11+
stock_landed_costs / stock.landed.cost / vendor_bill_id (many2one) : NEW relation: account.move
12+
stock_landed_costs / account.move / landed_costs_ids (one2many) : NEW relation: stock.landed.cost
13+
# NOTHING TO DO: new feature
14+
15+
stock_landed_costs / stock.valuation.adjustment.lines / former_cost_per_unit (float) : DEL
16+
# NOTHING TO DO: it was a stored compute but not used anymore
17+
18+
stock_landed_costs / stock.move / landed_cost_value (float) : DEL
19+
stock_landed_costs / stock.valuation.layer / stock_landed_cost_id (many2one): NEW relation: stock.landed.cost
20+
stock_landed_costs / stock.landed.cost / stock_valuation_layer_ids (one2many): NEW relation: stock.valuation.layer
21+
# TODO: to check if we could use the landed_cost_value in the new layer implementation
22+
23+
---XML records in module 'stock_landed_costs'---
24+
DEL ir.actions.act_window: stock_landed_costs.stock_landed_cost_type_action
25+
DEL ir.actions.act_window.view: stock_landed_costs.stock_landed_cost_type_action1
26+
DEL ir.actions.act_window.view: stock_landed_costs.stock_landed_cost_type_action2
27+
DEL ir.ui.menu: stock_landed_costs.menu_stock_landed_cost_type
28+
NEW ir.ui.view: stock_landed_costs.account_view_move_form_inherited
29+
NEW ir.ui.view: stock_landed_costs.stock_valuation_layer_form_inherited
30+
NEW ir.ui.view: stock_landed_costs.view_stock_landed_cost_tree2
31+
DEL ir.ui.view: stock_landed_costs.stock_landed_cost_tree_view
32+
DEL ir.ui.view: stock_landed_costs.view_stock_landed_cost_type_form
33+
# NOTHING TO DO
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
2+
# Copyright 2021 Andrii Skrypka
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
from openupgradelib import openupgrade
5+
6+
7+
def fill_account_move_line_is_landed_costs_line(env):
8+
openupgrade.logged_query(
9+
env.cr, """
10+
UPDATE account_move_line aml
11+
SET is_landed_costs_line = TRUE
12+
FROM product_product pp
13+
JOIN product_template pt ON pp.product_tmpl_id = pt.id
14+
WHERE aml.product_id = pp.id
15+
AND pt.landed_cost_ok AND pt.type = 'service'""",
16+
)
17+
18+
19+
def _generate_stock_valuation_layer(env):
20+
"""Insert a svl record per landed cost line, indicating the cost."""
21+
openupgrade.logged_query(
22+
env.cr, """
23+
INSERT INTO stock_valuation_layer (value, unit_cost, quantity, remaining_qty,
24+
stock_valuation_layer_id, description, stock_move_id, product_id,
25+
stock_landed_cost_id, company_id, account_move_id, create_date, create_uid,
26+
write_date, write_uid)
27+
SELECT sval.additional_landed_cost, 0.0, 0.0, 0.0,
28+
svl.id, slc.name, sm.id, sm.product_id,
29+
slc.id, am.company_id, am.id, am.create_date, am.create_uid,
30+
am.write_date, am.write_uid
31+
FROM stock_landed_cost slc
32+
JOIN account_move am ON am.id = slc.account_move_id
33+
JOIN stock_valuation_adjustment_lines sval ON sval.cost_id = slc.id
34+
JOIN stock_move sm ON sm.id = sval.move_id
35+
LEFT JOIN (
36+
SELECT MIN(id) as id, stock_move_id
37+
FROM stock_valuation_layer
38+
GROUP BY stock_move_id
39+
) svl ON svl.stock_move_id = sval.move_id
40+
WHERE slc.state = 'done'
41+
""",
42+
)
43+
44+
45+
def _fix_value_for_svl(env):
46+
"""As previous stock move price unit contains the landed cost price, the
47+
svl were created counting with this price, so we have to substract it now.
48+
"""
49+
openupgrade.logged_query(
50+
env.cr, """
51+
UPDATE stock_valuation_layer svl
52+
SET value = svl.value - svl_value.diff
53+
FROM (
54+
SELECT stock_valuation_layer_id as id, SUM(value) as diff
55+
FROM stock_valuation_layer
56+
WHERE stock_valuation_layer_id IS NOT NULL
57+
GROUP BY stock_valuation_layer_id
58+
) svl_value
59+
WHERE svl_value.id = svl.id
60+
""",
61+
)
62+
63+
64+
@openupgrade.migrate()
65+
def migrate(env, version):
66+
fill_account_move_line_is_landed_costs_line(env)
67+
openupgrade.load_data(
68+
env.cr, "stock_landed_costs",
69+
"migrations/13.0.1.1/noupdate_changes.xml")
70+
_generate_stock_valuation_layer(env)
71+
_fix_value_for_svl(env)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from openupgradelib import openupgrade
4+
5+
6+
def fix_price_unit_of_stock_move(env):
7+
# in v13 price_unit of stock.move exclude landed_cost_value
8+
openupgrade.logged_query(
9+
env.cr, """
10+
UPDATE stock_move
11+
SET price_unit = (value - landed_cost_value) / product_qty
12+
WHERE landed_cost_value != 0.0
13+
""",
14+
)
15+
16+
17+
@openupgrade.migrate()
18+
def migrate(env, version):
19+
fix_price_unit_of_stock_move(env)

odoo/openupgrade/doc/source/modules120-130.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ missing in the new release are marked with |del|.
601601
+----------------------------------------------+-------------------------------------------------+
602602
|stock_dropshipping | Done |
603603
+----------------------------------------------+-------------------------------------------------+
604-
|stock_landed_costs | |
604+
|stock_landed_costs | Done |
605605
+----------------------------------------------+-------------------------------------------------+
606606
|stock_picking_batch | Done |
607607
+----------------------------------------------+-------------------------------------------------+

0 commit comments

Comments
 (0)