-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Conversation
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Test. |
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""", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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""", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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""", | |
) |
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""", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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""", | |
) |
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""", | ||
) |
There was a problem hiding this comment.
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
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""", |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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 |
There was a problem hiding this comment.
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
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): |
There was a problem hiding this comment.
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.
Superseded by #3505. |
This PR
Migration done