Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][15.0] account: migration script #3284

Closed
wants to merge 1 commit into from

Conversation

sang250399
Copy link

This PR

Migration done

@legalsylvain

This comment was marked as duplicate.

@OCA-git-bot OCA-git-bot added this to the 15.0 milestone Jun 15, 2022
@OCA-git-bot

This comment was marked as duplicate.

@legalsylvain
Copy link
Contributor

Test.
/ocabot migration account

Comment on lines +39 to +52
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (SELECT COUNT(aml.currency_id)
FROM account_move_line aml
WHERE aml.move_id = am.id) > 1
THEN true
ELSE false
END
WHERE am.always_tax_exigible IS NULL""",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (SELECT COUNT(aml.currency_id)
FROM account_move_line aml
WHERE aml.move_id = am.id) > 1
THEN true
ELSE false
END
WHERE am.always_tax_exigible IS NULL""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (SELECT COUNT(aml.currency_id)
FROM account_move_line aml
WHERE aml.move_id = am.id) > 1
THEN true
ELSE NULL
END
WHERE am.always_tax_exigible IS NULL""",
)

Otherwise, the below queries will be useless

Comment on lines +58 to +75
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_account aa ON aa.id = aml.account_id
JOIN account_account_type aat ON aat.id = aa.user_type_id
WHERE aml.move_id = am.id
AND aat.type IN ('receivable', 'payable')) > 0
THEN false
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_account aa ON aa.id = aml.account_id
JOIN account_account_type aat ON aat.id = aa.user_type_id
WHERE aml.move_id = am.id
AND aat.type IN ('receivable', 'payable')) > 0
THEN false
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_account aa ON aa.id = aml.account_id
JOIN account_account_type aat ON aat.id = aa.user_type_id
WHERE aml.move_id = am.id
AND aat.type IN ('receivable', 'payable')) > 0
THEN NULL
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)

Comment on lines +81 to +97
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_tax tax ON tax.tax_exigibility = 'on_payment'
AND aml.tax_line_id = tax.id
WHERE aml.move_id = am.id) > 0
THEN false
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_tax tax ON tax.tax_exigibility = 'on_payment'
AND aml.tax_line_id = tax.id
WHERE aml.move_id = am.id) > 0
THEN false
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (
SELECT COUNT(*)
FROM account_move_line aml
JOIN account_tax tax ON tax.tax_exigibility = 'on_payment'
AND aml.tax_line_id = tax.id
WHERE aml.move_id = am.id) > 0
THEN NULL
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)

Comment on lines +103 to +119
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move am
SET always_tax_exigible =
CASE WHEN (
SELECT COUNT(aml_tax_rel.account_tax_id)
FROM account_move_line_account_tax_rel aml_tax_rel
JOIN account_move_line aml ON aml.id = aml_tax_rel.account_move_line_id
AND aml.move_id = am.id
JOIN account_tax tax ON tax.tax_exigibility = 'on_payment'
AND tax.id = aml_tax_rel.account_tax_id) > 0
THEN false
ELSE true
END
WHERE am.always_tax_exigible IS NULL""",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query does not handle the case when the child taxes of taxes on the line have always_tax_exigible is on_payment
https://github.com/odoo/odoo/blob/15.0/addons/account/models/account_move.py#L2470:L2472

Comment on lines +42 to +51
UPDATE account_move am
SET always_tax_exigible =
CASE
WHEN (SELECT COUNT(aml.currency_id)
FROM account_move_line aml
WHERE aml.move_id = am.id) > 1
THEN true
ELSE false
END
WHERE am.always_tax_exigible IS NULL""",
Copy link

@phamgiang2510 phamgiang2510 Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one has better performance?

        WITH move_currency_count AS (
            SELECT COUNT(aml.currency_id) AS currency_count, move_id
            FROM account_move_line
            GROUP BY move_id
            HAVING COUNT(aml.currency_id) > 1
        )
        UPDATE account_move am
        SET always_tax_exigible = TRUE
        FROM move_currency_count mcc
        WHERE mcc.move_id = am.id AND am.always_tax_exigible IS NULL

)


def _fast_fill_account_move_line_tax_tag_invert(env):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queries in this function are using too much subqueries and should be improved.

Comment on lines +293 to +297
UPDATE account_payment ap
SET payment_method_line_id = apml.id
FROM account_move am
JOIN account_payment_method_line apml ON apml.journal_id = am.journal_id
WHERE ap.move_id = am.id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UPDATE account_payment ap
SET payment_method_line_id = apml.id
FROM account_move am
JOIN account_payment_method_line apml ON apml.journal_id = am.journal_id
WHERE ap.move_id = am.id
UPDATE account_payment ap
SET payment_method_line_id = apml.id
FROM account_move am
JOIN account_payment_method_line apml ON apml.journal_id = am.journal_id
WHERE ap.move_id = am.id AND ap.payment_method_id = apml.payment_method_id

Assure that the payment method on payment are mapped with the payment method on the newly created payment method line. In other cases, if the payment method is check_printing, the line should be filled by migrating module account_check_printing, and if the payment method is electronic, should be filled by the payment_xxx modules.

Comment on lines +376 to +383
UPDATE account_payment ap
SET outstanding_account_id = CASE
WHEN apml.payment_account_id IS NOT NULL
THEN apml.payment_account_id
END
FROM account_payment_method_line apml
WHERE ap.payment_method_line_id IS NOT NULL
AND apml.id = ap.payment_method_line_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UPDATE account_payment ap
SET outstanding_account_id = CASE
WHEN apml.payment_account_id IS NOT NULL
THEN apml.payment_account_id
END
FROM account_payment_method_line apml
WHERE ap.payment_method_line_id IS NOT NULL
AND apml.id = ap.payment_method_line_id
UPDATE account_payment ap
SET outstanding_account_id = apml.payment_account_id
FROM account_payment_method_line apml
WHERE ap.payment_method_line_id IS NOT NULL
AND apml.id = ap.payment_method_line_id

Comment on lines +389 to +402
UPDATE account_payment ap
SET outstanding_account_id = CASE
WHEN ap.payment_type = 'inbound'
AND c.account_journal_payment_debit_account_id IS NOT NULL
THEN c.account_journal_payment_debit_account_id
WHEN ap.payment_type = 'outbound'
AND c.account_journal_payment_credit_account_id IS NOT NULL
THEN c.account_journal_payment_credit_account_id
ELSE null
END
FROM account_move am
JOIN account_journal aj ON am.journal_id = aj.id
JOIN res_company c ON c.id = aj.company_id
WHERE ap.move_id = am.id AND ap.payment_method_line_id IS NULL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query seems not correct on WHERE condition

Suggested change
UPDATE account_payment ap
SET outstanding_account_id = CASE
WHEN ap.payment_type = 'inbound'
AND c.account_journal_payment_debit_account_id IS NOT NULL
THEN c.account_journal_payment_debit_account_id
WHEN ap.payment_type = 'outbound'
AND c.account_journal_payment_credit_account_id IS NOT NULL
THEN c.account_journal_payment_credit_account_id
ELSE null
END
FROM account_move am
JOIN account_journal aj ON am.journal_id = aj.id
JOIN res_company c ON c.id = aj.company_id
WHERE ap.move_id = am.id AND ap.payment_method_line_id IS NULL
UPDATE account_payment ap
SET outstanding_account_id = CASE
WHEN ap.payment_type = 'inbound'
THEN c.account_journal_payment_debit_account_id
WHEN ap.payment_type = 'outbound'
THEN c.account_journal_payment_credit_account_id
END
FROM account_move am
JOIN account_journal aj ON am.journal_id = aj.id
JOIN res_company c ON c.id = aj.company_id
WHERE ap.move_id = am.id
AND ap.payment_type IN ('inbound', 'outbound')
AND ap.outstanding_account_id IS NULL

)


def _fast_fill_account_payment_outstanding_account_id(env):
Copy link

@phamgiang2510 phamgiang2510 Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think we should only create an empty outstanding_account_id column at this pre-migration, and then fill the values at end-migration, after all the payment method lines are created (from other modules like account_check_printing and payment_xxx) and assigned to the payment_method_line_id field on payments.

@MiquelRForgeFlow
Copy link
Contributor

Superseded by #3505.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants