Skip to content

Commit

Permalink
[FIX] point_of_sale: finish migration
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Aug 5, 2022
1 parent 57c543d commit c6f9522
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from openupgradelib import openupgrade


def convert_field_m2o_to_o2m(env):
def convert_pos_order_pickings(env):
openupgrade.m2o_to_x2m(
env.cr, env["pos.order"], "pos_order", "picking_ids", "picking_id"
)
Expand All @@ -11,13 +11,11 @@ def fill_sesion_on_picking_by_pos_order(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_picking
SET pos_session_id = (SELECT session_id
FROM pos_order
WHERE pos_order.id = stock_picking.pos_order_id
LIMIT 1)
WHERE pos_session_id IS NULL AND pos_order_id IS NOT NULL;
""",
UPDATE stock_picking sp
SET pos_session_id = po.session_id
FROM pos_order po
WHERE po.id = sp.pos_order_id
AND sp.pos_session_id IS NULL""",
)


Expand All @@ -36,21 +34,32 @@ def transfer_new_session_state(env):
env.cr,
"""
UPDATE pos_session ps
SET state = CASE
WHEN pc.cash_control=True AND
COALESCE(ps.rescue,False)=False THEN 'opening_control'
ELSE 'opened'
END
SET state =
CASE
WHEN pc.cash_control AND NOT COALESCE(ps.rescue, FALSE)
THEN 'opening_control'
ELSE 'opened'
END
FROM pos_config pc
WHERE pc.id = ps.config_id AND ps.state = 'new_session';
""",
)


def activate_pos_config_manage_orders(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE pos_config
SET manage_orders = TRUE""",
)


@openupgrade.migrate()
def migrate(env, version):
convert_field_m2o_to_o2m(env)
convert_pos_order_pickings(env)
fill_sesion_on_picking_by_pos_order(env)
set_point_of_sale_update_stock_quantities_to_real(env)
transfer_new_session_state(env)
activate_pos_config_manage_orders(env)
openupgrade.load_data(env.cr, "point_of_sale", "14.0.1.0.1/noupdate_changes.xml")
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,24 @@ def fill_pos_config_default_picking_type_id(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE pos_config
SET picking_type_id = (SELECT pos_type_id
FROM stock_warehouse
WHERE stock_warehouse.company_id = pos_config.company_id
LIMIT 1)
WHERE picking_type_id IS NULL;
""",
UPDATE pos_config pc
SET picking_type_id = sw.pos_type_id
FROM stock_warehouse sw
WHERE sw.company_id = pc.company_id
AND pc.picking_type_id IS NULL""",
)


def delete_constraint(env):
# Disappeared constraint
openupgrade.logged_query(
env.cr,
"""ALTER TABLE res_partner
DROP CONSTRAINT IF EXISTS res_partner_unique_barcode""",
)
openupgrade.delete_records_safely_by_xml_id(
env, ["point_of_sale.constraint_res_partner_unique_barcode"]
openupgrade.delete_sql_constraint_safely(
env, "point_of_sale", "res_partner", "unique_barcode"
)


@openupgrade.migrate()
def migrate(env, version):
fill_pos_config_default_picking_type_id(env)

openupgrade.set_xml_ids_noupdate_value(
env,
"point_of_sale",
Expand All @@ -49,5 +41,4 @@ def migrate(env, version):
],
True,
)

delete_constraint(env)
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---Models in module 'point_of_sale'---
---Fields in module 'point_of_sale'---
point_of_sale / pos.config / iface_precompute_cash (boolean): DEL
point_of_sale / pos.config / manage_orders (boolean) : NEW
point_of_sale / pos.config / manual_discount (boolean) : NEW hasdefault
point_of_sale / pos.config / module_pos_reprint (boolean) : DEL
# NOTHING TO DO

point_of_sale / pos.config / manage_orders (boolean) : NEW
# DONE: post-migration: active by default

point_of_sale / pos.config / picking_type_id (many2one) : now required, req_default: function
# DONE: pre-migration fill record having empty field with default value

Expand Down

0 comments on commit c6f9522

Please sign in to comment.