Skip to content

Commit

Permalink
[MIG] account_check_printing: Migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
tranngocson1996 committed Jan 10, 2022
1 parent 57db16f commit 67e01a6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules130-140.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Module coverage 13.0 -> 14.0
+--------------------------------------------+-------------------------------------------------+
| |del| account_bank_statement_import | Adopted in OCA as account_statement_import |
+--------------------------------------------+-------------------------------------------------+
|account_check_printing | |
|account_check_printing | Done |
+--------------------------------------------+-------------------------------------------------+
|account_debit_note | |
+--------------------------------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(
env.cr, "account_check_printing", "14.0.1.0/noupdate_changes.xml"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from openupgradelib import openupgrade


def add_preferred_payment_method_id_field_account_move(env):
if not openupgrade.column_exists(
env.cr, "account_move", "preferred_payment_method_id"
):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE account_move
ADD COLUMN preferred_payment_method_id integer
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET preferred_payment_method_id = CAST(
SPLIT_PART(ip.value_reference, ',', 2) AS int)
FROM ir_property ip
WHERE ip.company_id = am.company_id AND
ip.res_id = CONCAT('res.partner,', am.partner_id) AND
ip.name = 'property_payment_method_id'
""",
)


def fill_res_company_account_check_printing_layout(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE res_company
SET account_check_printing_layout = 'disabled'
WHERE account_check_printing_layout != 'disabled' AND
account_check_printing_layout IS NOT NULL
""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.copy_columns(
env.cr,
{"res_company": [("account_check_printing_layout", None, None)]},
)
add_preferred_payment_method_id_field_account_move(env)
fill_res_company_account_check_printing_layout(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---Models in module 'account_check_printing'---
---Fields in module 'account_check_printing'---
account_check_printing / account.move / preferred_payment_method_id (many2one): NEW relation: account.payment.method, isfunction: function, stored
# DONE: pre-migration: created preferred_payment_method_id column and set the value

account_check_printing / account.payment / check_amount_in_words (char) : now a function
account_check_printing / account.payment / check_number (char) : now a function
# NOTHING TO DO: automated field filling

account_check_printing / res.company / account_check_printing_layout (selection): selection_keys is now '['disabled']' ('['action_print_check_bottom', 'action_print_check_middle', 'action_print_check_top', 'disabled']')
# DONE: pre-migration: ensuring records are filled with default value ('disabled')

account_check_printing / res.partner / property_payment_method_id (many2one): NEW relation: account.payment.method, hasdefault
# NOTHING TO DO

---XML records in module 'account_check_printing'---
NEW ir.model.access: account_check_printing.access_print_prenumbered_checks
NEW ir.ui.view: account_check_printing.view_account_invoice_filter
NEW ir.ui.view: account_check_printing.view_partner_property_form
# NOTHING TO DO: noupdate="0" records

0 comments on commit 67e01a6

Please sign in to comment.