Skip to content

Commit

Permalink
[OU-ADD] repair
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Feb 21, 2025
1 parent 7b94bad commit e4560fa
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules160-170.rst
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| rating | Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| repair | | |
| repair | Done (WIP) | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| resource | Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
1 change: 1 addition & 0 deletions openupgrade_scripts/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@
# only used here for upgrade_analysis
merged_models = {
# odoo
"repair.line": "stock.move",
# OCA/...
}
51 changes: 51 additions & 0 deletions openupgrade_scripts/scripts/repair/17.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade


def fill_product_template_create_repair(env):
# If fees where created for some service,
# they should create repair orders automatically
openupgrade.logged_query(
env.cr,
"""
UPDATE product_template pt
SET create_repair = TRUE
FROM repair_fee rf
JOIN product_product pp ON rf.product_id = pp.id
WHERE pp.product_tmpl_id = pt.id""",
)


def fill_stock_move_repair_lines(env):
# Insert moves for repairs lines not done yet
openupgrade.logged_query(
env.cr,
"""
INSERT INTO stock_move (old_repair_line_id,
create_uid, create_date, write_uid, write_date,
repair_id, repair_line_type, ...
)
SELECT id, create_uid, create_date, write_uid, write_date,
repair_id, type as repair_line_type, ...
FROM repair_line rl
WHERE rl.move_id IS NULL AND rl.type IS NOT NULL
""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "repair", "17.0.1.0/noupdate_changes.xml")
# fill_stock_move_repair_lines_and_fees(env)
fill_product_template_create_repair(env)
openupgrade.delete_records_safely_by_xml_id(
env,
[
"repair.repair_fee_rule",
"repair.repair_line_rule",
"repair.seq_repair",
"repair.mail_template_repair_quotation",
],
)
32 changes: 32 additions & 0 deletions openupgrade_scripts/scripts/repair/17.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

from odoo.tools import sql


def add_helper_repair_move_rel(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE stock_move
ADD COLUMN old_repair_line_id integer""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_move sm
SET old_repair_line_id = rl.id
FROM repair_line rl
WHERE sm.id = rl.move_id
""",
)
# Create index for these columns, as they are going to be accessed frequently
index_name = "stock_move_old_repair_line_id_index"
sql.create_index(env.cr, index_name, "stock_move", ['"old_repair_line_id"'])


@openupgrade.migrate()
def migrate(env, version=None):
openupgrade.remove_tables_fks(env.cr, ["repair_line", "repair_fee"])
add_helper_repair_move_rel(env)
126 changes: 126 additions & 0 deletions openupgrade_scripts/scripts/repair/17.0.1.0/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---Models in module 'repair'---
obsolete model repair.fee
obsolete model repair.line
obsolete model repair.order.make_invoice [transient]
new model repair.warn.uncomplete.move [transient]
# NOTHING TO DO

---Fields in module 'repair'---
repair / product.template / create_repair (boolean) : NEW
# DONE: post-migration: new feature. We can assure at least that this field is TRUE if repair fee were created for this product

repair / account.move / repair_ids (one2many) : DEL relation: repair.order
repair / account.move.line / repair_fee_ids (one2many) : DEL relation: repair.fee
repair / account.move.line / repair_line_ids (one2many) : DEL relation: repair.line
repair / repair.fee / company_id (many2one) : DEL relation: res.company
repair / repair.fee / invoice_line_id (many2one) : DEL relation: account.move.line
repair / repair.fee / invoiced (boolean) : DEL
repair / repair.fee / name (text) : DEL required
repair / repair.fee / price_subtotal (float) : DEL
repair / repair.fee / price_total (float) : DEL
repair / repair.fee / price_unit (float) : DEL required
repair / repair.fee / product_id (many2one) : DEL relation: product.product
repair / repair.fee / product_uom (many2one) : DEL relation: uom.uom, required
repair / repair.fee / product_uom_qty (float) : DEL required
repair / repair.fee / repair_id (many2one) : DEL relation: repair.order, required
repair / repair.fee / tax_id (many2many) : DEL relation: account.tax
repair / repair.order / fees_lines (one2many) : DEL relation: repair.fee
# NOTHING TO DO: model removed

repair / repair.line / company_id (many2one) : DEL relation: res.company
repair / repair.line / invoice_line_id (many2one) : DEL relation: account.move.line
repair / repair.line / invoiced (boolean) : DEL
repair / repair.line / location_dest_id (many2one) : DEL relation: stock.location, required
repair / repair.line / location_id (many2one) : DEL relation: stock.location, required
repair / repair.line / lot_id (many2one) : DEL relation: stock.lot
repair / repair.line / move_id (many2one) : DEL relation: stock.move
repair / repair.line / name (text) : DEL required
repair / repair.line / price_subtotal (float) : DEL
repair / repair.line / price_total (float) : DEL
repair / repair.line / price_unit (float) : DEL required
repair / repair.line / product_id (many2one) : DEL relation: product.product, required
repair / repair.line / product_uom (many2one) : DEL relation: uom.uom, required
repair / repair.line / product_uom_qty (float) : DEL required
repair / repair.line / repair_id (many2one) : DEL relation: repair.order, required
repair / repair.line / state (selection) : DEL required, selection_keys: ['cancel', 'confirmed', 'done', 'draft']
repair / repair.line / tax_id (many2many) : DEL relation: account.tax
repair / repair.line / type (selection) : DEL required, selection_keys: ['add', 'remove']
repair / stock.move / repair_line_type (selection) : NEW selection_keys: ['add', 'recycle', 'remove']
repair / repair.order / move_ids (one2many) : NEW relation: stock.move
repair / repair.order / operations (one2many) : DEL relation: repair.line
# DONE: post-migration: merged into stock.move using repair_line_type

repair / repair.order / activity_user_id (many2one) : not related anymore
repair / repair.order / activity_user_id (many2one) : now a function
repair / repair.order / address_id (many2one) : DEL relation: res.partner
repair / repair.order / amount_tax (float) : DEL
repair / repair.order / amount_total (float) : DEL
repair / repair.order / amount_untaxed (float) : DEL
repair / repair.order / description (char) : DEL
repair / repair.order / guarantee_limit (date) : DEL
repair / repair.order / invoice_id (many2one) : DEL relation: account.move
repair / repair.order / invoice_method (selection) : DEL required, selection_keys: ['after_repair', 'b4repair', 'none']
repair / repair.order / invoiced (boolean) : DEL
repair / repair.order / is_parts_available (boolean) : NEW isfunction: function, stored
repair / repair.order / is_parts_late (boolean) : NEW isfunction: function, stored
repair / repair.order / location_dest_id (many2one) : NEW relation: stock.location, required, isrelated: related, stored
repair / repair.order / location_id (many2one) : not a function anymore
repair / repair.order / lot_id (many2one) : now a function
repair / repair.order / message_main_attachment_id (many2one): DEL relation: ir.attachment
repair / repair.order / partner_invoice_id (many2one) : DEL relation: res.partner
repair / repair.order / parts_location_id (many2one) : NEW relation: stock.location, required, isrelated: related, stored
repair / repair.order / picking_type_id (many2one) : NEW relation: stock.picking.type, required, hasdefault: default
repair / repair.order / pricelist_id (many2one) : DEL relation: product.pricelist
repair / repair.order / procurement_group_id (many2one): NEW relation: procurement.group
repair / repair.order / quotation_notes (html) : DEL
repair / repair.order / rating_ids (one2many) : NEW relation: rating.rating
repair / repair.order / recycle_location_id (many2one): NEW relation: stock.location, required, hasdefault: compute
repair / repair.order / repaired (boolean) : DEL
repair / repair.order / schedule_date (date) : now required
repair / repair.order / schedule_date (date) : type is now 'datetime' ('date')
repair / repair.order / state (selection) : selection_keys is now '['cancel', 'confirmed', 'done', 'draft', 'under_repair']' ('['2binvoiced', 'cancel', 'confirmed', 'done', 'draft', 'ready', 'under_repair']')
repair / repair.order / under_warranty (boolean) : NEW
repair / repair.order / sale_order_line_id (many2one) : NEW relation: sale.order.line
repair / sale.order / repair_order_ids (one2many) : NEW relation: repair.order
repair / stock.picking / is_repairable (boolean) : not related anymore
repair / stock.picking / is_repairable (boolean) : now a function
# TODO: post-migration: fill some new fields (to check which ones)
# TODO: post-migration: create sale orders (and sale order lines) for invoiced repair orders that don't have sale orders
# TODO: post-migration: link repair invoices with the sale orders (same for invoice lines and sale order lines)

repair / stock.picking.type / code (False) : NEW selection_keys: ['incoming', 'internal', 'mrp_operation', 'outgoing', 'repair_operation'], mode: modify
repair / stock.picking.type / default_recycle_location_dest_id (many2one): NEW relation: stock.location, hasdefault: compute
repair / stock.picking.type / default_remove_location_dest_id (many2one): NEW relation: stock.location, hasdefault: compute
# NOTHING TO DO

repair / stock.warehouse / repair_type_id (many2one) : NEW relation: stock.picking.type
# TODO: post-migration: assure every warehouse has new repair type

---XML records in module 'repair'---
NEW ir.actions.act_window: repair.action_picking_repair
NEW ir.actions.act_window: repair.action_repair_order_form
DEL ir.actions.act_window: repair.act_repair_invoice
NEW ir.model.access: repair.access_repair_warn_uncomplete_move
DEL ir.model.access: repair.access_account_tax_user
DEL ir.model.access: repair.access_repair_fee_user
DEL ir.model.access: repair.access_repair_line_user
DEL ir.model.access: repair.access_repair_order_make_invoice
DEL ir.model.constraint: repair.constraint_repair_order_name
# NOTHING TO DO

DEL ir.rule: repair.repair_fee_rule (noupdate)
DEL ir.rule: repair.repair_line_rule (noupdate)
DEL ir.sequence: repair.seq_repair (noupdate)
DEL mail.template: repair.mail_template_repair_quotation (noupdate)
# DONE: post-migration: safely remove

NEW ir.ui.menu: repair.repair_order_menu
NEW ir.ui.view: repair.repair_order_view_activity
NEW ir.ui.view: repair.stock_repair_type_kanban
NEW ir.ui.view: repair.view_product_template_form_inherit_repair
NEW ir.ui.view: repair.view_repair_warn_uncomplete_move
NEW ir.ui.view: repair.view_sale_order_form_inherit_repair
NEW ir.ui.view: repair.view_warehouse_inherit_repair
DEL ir.ui.view: repair.view_make_invoice
NEW stock.picking.type: repair.picking_type_warehouse0_repair (noupdate)
# NOTHING TO DO

0 comments on commit e4560fa

Please sign in to comment.