Skip to content

Commit

Permalink
[OU-IMP] sale: review followup
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Dec 9, 2024
1 parent 75d98a3 commit 7fb8642
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
19 changes: 19 additions & 0 deletions openupgrade_scripts/scripts/sale/17.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
from openupgradelib import openupgrade


def _sale_order_populate_locked_field(env):
"""
Set state of sale orders in state 'done' to 'sale'
Lock them if the the group sale.group_auto_done_setting
is inherited by the user group
"""
auto_done_group = env.ref("sale.group_auto_done_setting")
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order
SET locked = locked or create_uid = ANY (%s), state = 'sale'
WHERE state = 'done'
""",
(auto_done_group.users.ids,),
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "sale", "17.0.1.2/noupdate_changes.xml")
_sale_order_populate_locked_field(env)
37 changes: 0 additions & 37 deletions openupgrade_scripts/scripts/sale/17.0.1.2/pre-migration.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DEL ir.model.access: sale.access_account_invoice_send_salesman

ir.model.constraint: sale.constraint_res_company_check_quotation_validity_days (changed definition: is now 'check(quotation_validity_days >= 0)' ('check(quotation_validity_days > 0)'))
ir.model.constraint: sale.constraint_sale_order_date_order_conditional_required (changed definition: is now 'check((state = 'sale' and date_order is not null) or state != 'sale')' ('check((state in('sale','done') and date_order is not null) or state not in('sale','done'))'))
# DONE pre-migration: safely delete constraint to recreate it
# NOTHING TO DO

NEW ir.rule: sale.mail_plan_rule_group_sale_manager (noupdate)
NEW ir.rule: sale.mail_plan_template_rule_group_sale_manager (noupdate)
Expand Down
5 changes: 5 additions & 0 deletions openupgrade_scripts/scripts/sale/tests/data_sale_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
env = locals().get("env")
# set sale order to done to be sure we migrate
# the done state correctly
env.ref("sale.sale_order_18").action_done()
env.cr.commit()
10 changes: 10 additions & 0 deletions openupgrade_scripts/scripts/sale/tests/test_sale_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo.tests import TransactionCase

from odoo.addons.openupgrade_framework import openupgrade_test


@openupgrade_test
class TestSaleMigration(TransactionCase):
def test_sale_order_state(self):
self.assertEqual(self.env.ref("sale.sale_order_18").state, "sale")
self.assertFalse(self.env.ref("sale.sale_order_18").locked)

0 comments on commit 7fb8642

Please sign in to comment.