Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions openupgrade_scripts/scripts/account/14.0.1.1/end-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,35 @@ def _make_correct_account_type(env):
env.cr,
query,
)

def _switch_default_account_and_outstanding_account(env):
openupgrade.logged_query(
env.cr,
"""
WITH subquery as (
SELECT aml.id as aml_id,
aj.payment_debit_account_id,
aj.payment_credit_account_id,
aml.debit, aml.credit
FROM account_move_line aml
JOIN account_journal aj on aml.journal_id = aj.id
WHERE legacy_statement_unreconcile = TRUE
AND aj.type IN ('bank', 'cash')
)
UPDATE account_move_line aml
SET account_id =
CASE
WHEN subquery.debit > 0 THEN subquery.payment_debit_account_id
WHEN subquery.credit > 0 THEN subquery.payment_credit_account_id
END
FROM subquery
WHERE aml.id = subquery.aml_id
AND (aml.display_type NOT IN ('line_section', 'line_note') OR aml.display_type IS NULL)
""",
)


@openupgrade.migrate()
def migrate(env, version):
_make_correct_account_type(env)
_switch_default_account_and_outstanding_account(env)
44 changes: 15 additions & 29 deletions openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ def fill_partial_reconcile_debit_and_credit_amounts(env):
OR r.debit_currency_id = c.currency_id)
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE account_partial_reconcile r
SET debit_amount_currency = r.amount_currency,
credit_amount_currency = r.amount_currency
FROM res_company c
WHERE r.company_id = c.id
AND r.debit_amount_currency IS NULL
AND r.credit_amount_currency is NULL
AND r.credit_currency_id = r.debit_currency_id
AND r.credit_currency_id != c.currency_id
""",
)
# compute debit and credit amount when currencies are different
partial_reconcile_lines = (
env["account.partial.reconcile"]
Expand Down Expand Up @@ -817,33 +831,6 @@ def _create_ir_config_parameter_constraint_start_date(env):
)


def _switch_default_account_and_outstanding_account(env):
openupgrade.logged_query(
env.cr,
"""
WITH subquery as (
SELECT aml.id as aml_id,
aj.payment_debit_account_id,
aj.payment_credit_account_id,
aml.debit, aml.credit
FROM account_move_line aml
JOIN account_journal aj on aml.journal_id = aj.id
WHERE legacy_statement_unreconcile = TRUE
AND aj.type IN ('bank', 'cash')
)
UPDATE account_move_line aml
SET account_id =
CASE
WHEN subquery.debit > 0 THEN subquery.payment_debit_account_id
WHEN subquery.credit > 0 THEN subquery.payment_credit_account_id
END
FROM subquery
WHERE aml.id = subquery.aml_id
AND aml.display_type NOT IN ('line_section', 'line_note')
""",
)


@openupgrade.migrate()
def migrate(env, version):
fill_account_journal_posted_before(env)
Expand Down Expand Up @@ -880,5 +867,4 @@ def migrate(env, version):
["email_template_edi_invoice", "mail_template_data_payment_receipt"],
)
_migrate_currency_exchange_account_company(env)
_create_ir_config_parameter_constraint_start_date(env)
_switch_default_account_and_outstanding_account(env)
_create_ir_config_parameter_constraint_start_date(env)
21 changes: 17 additions & 4 deletions openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,23 @@ def _mark_move_line_statement_unreconciled(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE account_move_line
SET legacy_statement_unreconcile = TRUE
WHERE account_internal_type = 'liquidity'
AND statement_line_id IS NULL
UPDATE account_move_line aml
SET legacy_statement_unreconcile = TRUE
WHERE id in
(select aml.id
from account_move_line aml
join account_journal aj on aml.journal_id = aj.id
join account_account aa on aml.account_id = aa.id
where aj.type in ('bank', 'cash') and aml.statement_line_id is NULL
and (aml.account_id = aj.default_debit_account_id or aml.account_id = aj.default_credit_account_id)
and (aml.display_type NOT IN ('line_section', 'line_note') OR aml.display_type is null)
and (
aj.is_advance_journal = false
or

aj.is_advance_journal is null -- Anh em xem lai cho nay vi co database ko co truong nay
)
and aml.parent_state = 'posted')
""",
)

Expand Down