Skip to content

Commit 75f74f3

Browse files
[OU-ADD] repair
1 parent 1fad8be commit 75f74f3

4 files changed

Lines changed: 259 additions & 1 deletion

File tree

docsource/modules160-170.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ Module coverage 16.0 -> 17.0
876876
+---------------------------------------------------+----------------------+-------------------------------------------------+
877877
| rating | Nothing to do | |
878878
+---------------------------------------------------+----------------------+-------------------------------------------------+
879-
| repair | | |
879+
| repair | Done (WIP) | |
880880
+---------------------------------------------------+----------------------+-------------------------------------------------+
881881
| resource | Done | |
882882
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
def fill_product_template_create_repair(env):
8+
# If fees where created for some service,
9+
# they should create repair orders automatically
10+
openupgrade.logged_query(
11+
env.cr,
12+
"""
13+
UPDATE product_template pt
14+
SET create_repair = TRUE
15+
FROM repair_fee rf
16+
JOIN product_product pp ON rf.product_id = pp.id
17+
WHERE pp.product_tmpl_id = pt.id""",
18+
)
19+
20+
21+
def fill_stock_move_repair_lines(env):
22+
# Insert moves for repairs lines not done yet
23+
openupgrade.logged_query(
24+
env.cr,
25+
"""
26+
INSERT INTO stock_move (old_repair_line_id,
27+
create_uid, create_date, write_uid, write_date,
28+
repair_id, repair_line_type, ...
29+
)
30+
SELECT id, create_uid, create_date, write_uid, write_date,
31+
repair_id, type as repair_line_type, ...
32+
FROM repair_line rl
33+
WHERE rl.move_id IS NULL AND rl.type IS NOT NULL
34+
""",
35+
)
36+
37+
38+
def create_default_repair_type_for_all_warehouses(env):
39+
# method mainly based on _create_or_update_sequences_and_picking_types()
40+
all_warehouses = env["stock.warehouse"].with_context(active_test=False).search([])
41+
for wh in all_warehouses:
42+
# choose the next available color for the operation types of this warehouse
43+
all_used_colors = [
44+
res["color"]
45+
for res in env["stock.picking.type"]
46+
.with_context(active_test=False)
47+
.search_read(
48+
[("warehouse_id", "!=", False), ("color", "!=", False)],
49+
["color"],
50+
order="color",
51+
)
52+
]
53+
available_colors = [zef for zef in range(0, 12) if zef not in all_used_colors]
54+
color = available_colors[0] if available_colors else 0
55+
sequence_data = wh._get_sequence_values()
56+
# suit for each warehouse: reception, internal, pick, pack, ship
57+
max_sequence = (
58+
env["stock.picking.type"]
59+
.with_context(active_test=False)
60+
.search_read(
61+
[("sequence", "!=", False)],
62+
["sequence"],
63+
limit=1,
64+
order="sequence desc",
65+
)
66+
)
67+
max_sequence = max_sequence and max_sequence[0]["sequence"] or 0
68+
values = wh._get_picking_type_update_values()["repair_type_id"]
69+
create_data, _ = wh._get_picking_type_create_values(max_sequence)
70+
values.update(create_data["repair_type_id"])
71+
sequence = env["ir.sequence"].create(sequence_data["repair_type_id"])
72+
values.update(
73+
warehouse_id=wh.id,
74+
color=color,
75+
sequence_id=sequence.id,
76+
sequence=max_sequence + 1,
77+
company_id=wh.company_id.id,
78+
active=wh.active,
79+
)
80+
# create return picking type
81+
repair_type_id = env["stock.picking.type"].create(values).id
82+
# update return picking type for warehouse
83+
wh.write({"repair_type_id": repair_type_id})
84+
85+
86+
@openupgrade.migrate()
87+
def migrate(env, version):
88+
# fill_stock_move_repair_lines_and_fees(env)
89+
fill_product_template_create_repair(env)
90+
create_default_repair_type_for_all_warehouses(env)
91+
openupgrade.load_data(env, "repair", "17.0.1.0/noupdate_changes.xml")
92+
openupgrade.delete_records_safely_by_xml_id(
93+
env,
94+
[
95+
"repair.repair_fee_rule",
96+
"repair.repair_line_rule",
97+
"repair.seq_repair",
98+
"repair.mail_template_repair_quotation",
99+
],
100+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from openupgradelib import openupgrade
4+
5+
from odoo.tools import sql
6+
7+
8+
def add_helper_repair_move_rel(env):
9+
openupgrade.logged_query(
10+
env.cr,
11+
"""
12+
ALTER TABLE stock_move
13+
ADD COLUMN old_repair_line_id integer""",
14+
)
15+
openupgrade.logged_query(
16+
env.cr,
17+
"""
18+
UPDATE stock_move sm
19+
SET old_repair_line_id = rl.id
20+
FROM repair_line rl
21+
WHERE sm.id = rl.move_id
22+
""",
23+
)
24+
# Create index for these columns, as they are going to be accessed frequently
25+
index_name = "stock_move_old_repair_line_id_index"
26+
sql.create_index(env.cr, index_name, "stock_move", ['"old_repair_line_id"'])
27+
28+
29+
@openupgrade.migrate()
30+
def migrate(env, version=None):
31+
openupgrade.remove_tables_fks(env.cr, ["repair_line", "repair_fee"])
32+
add_helper_repair_move_rel(env)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---Models in module 'repair'---
2+
obsolete model repair.fee
3+
obsolete model repair.line
4+
obsolete model repair.order.make_invoice [transient]
5+
new model repair.warn.uncomplete.move [transient]
6+
# NOTHING TO DO
7+
8+
---Fields in module 'repair'---
9+
repair / product.template / create_repair (boolean) : NEW
10+
# DONE: post-migration: new feature. We can assure at least that this field is TRUE if repair fee were created for this product
11+
12+
repair / account.move / repair_ids (one2many) : DEL relation: repair.order
13+
repair / account.move.line / repair_fee_ids (one2many) : DEL relation: repair.fee
14+
repair / account.move.line / repair_line_ids (one2many) : DEL relation: repair.line
15+
repair / repair.fee / company_id (many2one) : DEL relation: res.company
16+
repair / repair.fee / invoice_line_id (many2one) : DEL relation: account.move.line
17+
repair / repair.fee / invoiced (boolean) : DEL
18+
repair / repair.fee / name (text) : DEL required
19+
repair / repair.fee / price_subtotal (float) : DEL
20+
repair / repair.fee / price_total (float) : DEL
21+
repair / repair.fee / price_unit (float) : DEL required
22+
repair / repair.fee / product_id (many2one) : DEL relation: product.product
23+
repair / repair.fee / product_uom (many2one) : DEL relation: uom.uom, required
24+
repair / repair.fee / product_uom_qty (float) : DEL required
25+
repair / repair.fee / repair_id (many2one) : DEL relation: repair.order, required
26+
repair / repair.fee / tax_id (many2many) : DEL relation: account.tax
27+
repair / repair.order / fees_lines (one2many) : DEL relation: repair.fee
28+
# NOTHING TO DO: model removed
29+
30+
repair / repair.line / company_id (many2one) : DEL relation: res.company
31+
repair / repair.line / invoice_line_id (many2one) : DEL relation: account.move.line
32+
repair / repair.line / invoiced (boolean) : DEL
33+
repair / repair.line / location_dest_id (many2one) : DEL relation: stock.location, required
34+
repair / repair.line / location_id (many2one) : DEL relation: stock.location, required
35+
repair / repair.line / lot_id (many2one) : DEL relation: stock.lot
36+
repair / repair.line / move_id (many2one) : DEL relation: stock.move
37+
repair / repair.line / name (text) : DEL required
38+
repair / repair.line / price_subtotal (float) : DEL
39+
repair / repair.line / price_total (float) : DEL
40+
repair / repair.line / price_unit (float) : DEL required
41+
repair / repair.line / product_id (many2one) : DEL relation: product.product, required
42+
repair / repair.line / product_uom (many2one) : DEL relation: uom.uom, required
43+
repair / repair.line / product_uom_qty (float) : DEL required
44+
repair / repair.line / repair_id (many2one) : DEL relation: repair.order, required
45+
repair / repair.line / state (selection) : DEL required, selection_keys: ['cancel', 'confirmed', 'done', 'draft']
46+
repair / repair.line / tax_id (many2many) : DEL relation: account.tax
47+
repair / repair.line / type (selection) : DEL required, selection_keys: ['add', 'remove']
48+
repair / stock.move / repair_line_type (selection) : NEW selection_keys: ['add', 'recycle', 'remove']
49+
repair / repair.order / move_ids (one2many) : NEW relation: stock.move
50+
repair / repair.order / operations (one2many) : DEL relation: repair.line
51+
# DONE: post-migration: merged into stock.move using repair_line_type
52+
53+
repair / repair.order / activity_user_id (many2one) : not related anymore
54+
repair / repair.order / activity_user_id (many2one) : now a function
55+
repair / repair.order / address_id (many2one) : DEL relation: res.partner
56+
repair / repair.order / amount_tax (float) : DEL
57+
repair / repair.order / amount_total (float) : DEL
58+
repair / repair.order / amount_untaxed (float) : DEL
59+
repair / repair.order / description (char) : DEL
60+
repair / repair.order / guarantee_limit (date) : DEL
61+
repair / repair.order / invoice_id (many2one) : DEL relation: account.move
62+
repair / repair.order / invoice_method (selection) : DEL required, selection_keys: ['after_repair', 'b4repair', 'none']
63+
repair / repair.order / invoiced (boolean) : DEL
64+
repair / repair.order / is_parts_available (boolean) : NEW isfunction: function, stored
65+
repair / repair.order / is_parts_late (boolean) : NEW isfunction: function, stored
66+
repair / repair.order / location_dest_id (many2one) : NEW relation: stock.location, required, isrelated: related, stored
67+
repair / repair.order / location_id (many2one) : not a function anymore
68+
repair / repair.order / lot_id (many2one) : now a function
69+
repair / repair.order / message_main_attachment_id (many2one): DEL relation: ir.attachment
70+
repair / repair.order / partner_invoice_id (many2one) : DEL relation: res.partner
71+
repair / repair.order / parts_location_id (many2one) : NEW relation: stock.location, required, isrelated: related, stored
72+
repair / repair.order / picking_type_id (many2one) : NEW relation: stock.picking.type, required, hasdefault: default
73+
repair / repair.order / pricelist_id (many2one) : DEL relation: product.pricelist
74+
repair / repair.order / procurement_group_id (many2one): NEW relation: procurement.group
75+
repair / repair.order / quotation_notes (html) : DEL
76+
repair / repair.order / rating_ids (one2many) : NEW relation: rating.rating
77+
repair / repair.order / recycle_location_id (many2one): NEW relation: stock.location, required, hasdefault: compute
78+
repair / repair.order / repaired (boolean) : DEL
79+
repair / repair.order / schedule_date (date) : now required
80+
repair / repair.order / schedule_date (date) : type is now 'datetime' ('date')
81+
repair / repair.order / state (selection) : selection_keys is now '['cancel', 'confirmed', 'done', 'draft', 'under_repair']' ('['2binvoiced', 'cancel', 'confirmed', 'done', 'draft', 'ready', 'under_repair']')
82+
repair / repair.order / under_warranty (boolean) : NEW
83+
repair / repair.order / sale_order_line_id (many2one) : NEW relation: sale.order.line
84+
repair / sale.order / repair_order_ids (one2many) : NEW relation: repair.order
85+
repair / stock.picking / is_repairable (boolean) : not related anymore
86+
repair / stock.picking / is_repairable (boolean) : now a function
87+
# TODO: post-migration: fill some new fields (to check which ones)
88+
# TODO: post-migration: create sale orders (and sale order lines) for invoiced repair orders that don't have sale orders
89+
# TODO: post-migration: link repair invoices with the sale orders (same for invoice lines and sale order lines)
90+
91+
repair / stock.picking.type / code (False) : NEW selection_keys: ['incoming', 'internal', 'mrp_operation', 'outgoing', 'repair_operation'], mode: modify
92+
repair / stock.picking.type / default_recycle_location_dest_id (many2one): NEW relation: stock.location, hasdefault: compute
93+
repair / stock.picking.type / default_remove_location_dest_id (many2one): NEW relation: stock.location, hasdefault: compute
94+
# NOTHING TO DO
95+
96+
repair / stock.warehouse / repair_type_id (many2one) : NEW relation: stock.picking.type
97+
# DONE: post-migration: assure every warehouse has new repair type
98+
99+
---XML records in module 'repair'---
100+
NEW ir.actions.act_window: repair.action_picking_repair
101+
NEW ir.actions.act_window: repair.action_repair_order_form
102+
DEL ir.actions.act_window: repair.act_repair_invoice
103+
NEW ir.model.access: repair.access_repair_warn_uncomplete_move
104+
DEL ir.model.access: repair.access_account_tax_user
105+
DEL ir.model.access: repair.access_repair_fee_user
106+
DEL ir.model.access: repair.access_repair_line_user
107+
DEL ir.model.access: repair.access_repair_order_make_invoice
108+
DEL ir.model.constraint: repair.constraint_repair_order_name
109+
# NOTHING TO DO
110+
111+
DEL ir.rule: repair.repair_fee_rule (noupdate)
112+
DEL ir.rule: repair.repair_line_rule (noupdate)
113+
DEL ir.sequence: repair.seq_repair (noupdate)
114+
DEL mail.template: repair.mail_template_repair_quotation (noupdate)
115+
# DONE: post-migration: safely remove
116+
117+
NEW ir.ui.menu: repair.repair_order_menu
118+
NEW ir.ui.view: repair.repair_order_view_activity
119+
NEW ir.ui.view: repair.stock_repair_type_kanban
120+
NEW ir.ui.view: repair.view_product_template_form_inherit_repair
121+
NEW ir.ui.view: repair.view_repair_warn_uncomplete_move
122+
NEW ir.ui.view: repair.view_sale_order_form_inherit_repair
123+
NEW ir.ui.view: repair.view_warehouse_inherit_repair
124+
DEL ir.ui.view: repair.view_make_invoice
125+
NEW stock.picking.type: repair.picking_type_warehouse0_repair (noupdate)
126+
# NOTHING TO DO

0 commit comments

Comments
 (0)