Skip to content

Commit

Permalink
[OU-IMP] more review followups
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Feb 3, 2025
1 parent bef73ac commit 215de3b
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 28 deletions.
19 changes: 0 additions & 19 deletions openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,40 @@
<record id="account_move_line_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<!-- don't delete lines from payment terms, we migrate them /-->
<record id="account_payment_term_15days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 15})]"/>
-->
</record>
<record id="account_payment_term_21days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 21})]"/>
-->
</record>
<record id="account_payment_term_30_days_end_month_the_10" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'delay_type':'days_after_end_of_next_month', 'nb_days': 10})]"/>
-->
<field name="name">10 Days after End of Next Month</field>
<field name="note">Payment terms: 10 Days after End of Next Month</field>
</record>
<record id="account_payment_term_30days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 30})]"/>
-->
</record>
<record id="account_payment_term_30days_early_discount" model="account.payment.term">
<!--
<field name="line_ids" eval="[ Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 30})]"/>
-->
<field name="discount_days">7</field>
<field name="discount_percentage">2</field>
<field name="early_discount">True</field>
</record>
<record id="account_payment_term_45days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 45})]"/>
-->
</record>
<record id="account_payment_term_advance_60days" model="account.payment.term">
<!--
<field name="line_ids" eval="[ Command.clear(), Command.create({'value': 'percent', 'value_amount': 30.0, 'nb_days': 0}), Command.create({'value': 'percent', 'value_amount': 70.0, 'nb_days': 60})]"/>
-->
</record>
<record id="account_payment_term_comp_rule" model="ir.rule">
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_payment_term_end_following_month" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'delay_type':'days_after_end_of_next_month', 'nb_days': 0})]"/>
-->
</record>
<record id="account_payment_term_immediate" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 0})]"/>
-->
</record>
<record id="account_reconcile_model_line_template_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
Expand Down
157 changes: 157 additions & 0 deletions openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="account_bank_statement_line_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record id="account_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_fiscal_position_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_group_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_move_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record id="account_move_line_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<!-- don't delete lines from payment terms, we migrate them /-->
<record id="account_payment_term_15days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 15})]"/>
-->
</record>
<record id="account_payment_term_21days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 21})]"/>
-->
</record>
<record id="account_payment_term_30_days_end_month_the_10" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'delay_type':'days_after_end_of_next_month', 'nb_days': 10})]"/>
-->
<field name="name">10 Days after End of Next Month</field>
<field name="note">Payment terms: 10 Days after End of Next Month</field>
</record>
<record id="account_payment_term_30days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 30})]"/>
-->
</record>
<record id="account_payment_term_30days_early_discount" model="account.payment.term">
<!--
<field name="line_ids" eval="[ Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 30})]"/>
-->
<field name="discount_days">7</field>
<field name="discount_percentage">2</field>
<field name="early_discount">True</field>
</record>
<record id="account_payment_term_45days" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 45})]"/>
-->
</record>
<record id="account_payment_term_advance_60days" model="account.payment.term">
<!--
<field name="line_ids" eval="[ Command.clear(), Command.create({'value': 'percent', 'value_amount': 30.0, 'nb_days': 0}), Command.create({'value': 'percent', 'value_amount': 70.0, 'nb_days': 60})]"/>
-->
</record>
<record id="account_payment_term_comp_rule" model="ir.rule">
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_payment_term_end_following_month" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'delay_type':'days_after_end_of_next_month', 'nb_days': 0})]"/>
-->
</record>
<record id="account_payment_term_immediate" model="account.payment.term">
<!--
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'percent', 'value_amount': 100.0, 'nb_days': 0})]"/>
-->
</record>
<record id="account_reconcile_model_line_template_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_reconcile_model_template_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_root_comp_rule" model="ir.rule">
<field name="domain_force">['|',('company_id','=',False), ('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="account_send_payment_receipt_by_email_action" model="ir.actions.act_window">
<field name="context" eval="{ 'mail_post_autofollow': True, 'default_composition_mode': 'comment', 'default_template_id': ref('account.mail_template_data_payment_receipt'), 'default_email_layout_xmlid': 'mail.mail_notification_light', }"/>
</record>
<record id="account_send_payment_receipt_by_email_action_multi" model="ir.actions.act_window">
<field name="context" eval="{ 'mailing_document_based': True, 'mail_post_autofollow': True, 'default_composition_mode': 'mass_mail', 'default_template_id': ref('account.mail_template_data_payment_receipt'), 'default_email_layout_xmlid': 'mail.mail_notification_light', }"/>
</record>
<record id="email_template_edi_credit_note" model="mail.template">
<field name="report_template_ids" eval="[(4, ref('account.account_invoices'))]"/>
</record>
<record id="email_template_edi_invoice" model="mail.template">
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Dear
<t t-if="object.partner_id.parent_id"><t t-out="object.partner_id.name or ''">Brandon Freeman</t> (<t t-out="object.partner_id.parent_id.name or ''">Azure Interior</t>),
</t>
<t t-else=""><t t-out="object.partner_id.name or ''">Brandon Freeman</t>,
</t>
<br/><br/>
Here is your
<t t-if="object.name">
invoice <span style="font-weight:bold;" t-out="object.name or ''">INV/2021/05/0005</span>
</t>
<t t-else="">
invoice
</t>
<t t-if="object.invoice_origin">
(with reference: <t t-out="object.invoice_origin or ''">SUB003</t>)
</t>
amounting in <span style="font-weight:bold;" t-out="format_amount(object.amount_total, object.currency_id) or ''">$ 143,750.00</span>
from <t t-out="object.company_id.name or ''">YourCompany</t>.
<t t-if="object.payment_state in ('paid', 'in_payment')">
This invoice is already paid.
</t>
<t t-else="">
Please remit payment at your earliest convenience.
<t t-if="object.payment_reference"><br/><br/>
Please use the following communication for your payment: <strong t-out="object.payment_reference or ''">INV/2021/05/0005</strong>
<t t-if="object.partner_bank_id">
on the account <strong t-out="object.partner_bank_id.acc_number"/>
</t>
.
</t>
</t>
<t t-if="hasattr(object, 'timesheet_count') and object.timesheet_count"><br/><br/>
PS: you can review your timesheets <a t-att-href="'my/timesheets?search_in=invoice&amp;search=%s' % object.name">from the portal.</a>
</t>
<br/><br/>
Do not hesitate to contact us if you have any questions.
<t t-if="not is_html_empty(object.invoice_user_id.signature)"><br/><br/><t t-out="object.invoice_user_id.signature or ''">--<br/>Mitchell Admin</t></t>
</p>
</div>
</field>
<field name="report_template_ids" eval="[(4, ref('account.account_invoices'))]"/>
</record>
<record id="invoice_analysis_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record id="journal_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="journal_group_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="mail_template_data_payment_receipt" model="mail.template">
<field name="report_template_ids" eval="[(4, ref('account.action_report_payment_receipt'))]"/>
</record>
<record id="tax_comp_rule" model="ir.rule">
<field name="domain_force">[('company_id', 'parent_of', company_ids)]</field>
</record>
<record id="tax_rep_comp_rule" model="ir.rule">
<field name="domain_force">['|',('company_id','=',False), ('company_id', 'parent_of', company_ids)]</field>
</record>
</odoo>
17 changes: 13 additions & 4 deletions openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _onboarding_state_migration(env):
],
limit=1,
):
step.action_set_just_done()
step.with_company(company_id).action_set_just_done()
if account_onboarding_invoice_layout_state in ("just_done", "done"):
step = env.ref(
"account.onboarding_onboarding_step_base_document_layout",
Expand Down Expand Up @@ -373,7 +373,7 @@ def _account_tax_group_migration(env):
And then in each l10n module, only need to perform rename xml_id like
https://github.com/Viindoo/OpenUpgrade/pull/655
"""
origin_id_column = openupgrade.get_legacy_name("origin_id")
origin_id_column = "original_tax_group_id"
openupgrade.logged_query(
env.cr,
f"""
Expand Down Expand Up @@ -460,7 +460,7 @@ def _force_install_account_payment_term_module_module(env):
it has already merged in odoo master
"""
account_payment_term_module = env["ir.module.module"].search(
[("name", "=", "account_payment_term")]
[("name", "=", "account_payment_term")], limit=1
)
needs_account_payment_term = bool(
env["account.payment.term.line"].search(
Expand Down Expand Up @@ -523,7 +523,16 @@ def migrate(env, version):
_account_payment_term_migration(env)
_account_payment_term_early_payment_discount(env)
_force_install_account_payment_term_module_module(env)
openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes.xml")
openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes_work.xml")
openupgrade.delete_record_translations(
env.cr,
"account",
(
"email_template_edi_credit_note",
"email_template_edi_invoice",
"mail_template_data_payment_receipt",
),
)
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
Expand Down
72 changes: 69 additions & 3 deletions openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def _generic_coa_rename_xml_id(env):


def _convert_account_tax_description(env):
openupgrade.copy_columns(env.cr, {"account_tax": [("description", None, None)]})
openupgrade.rename_columns(
env.cr, {"account_tax": [("description", "invoice_label")]}
)
Expand All @@ -99,7 +98,7 @@ def _am_create_delivery_date_column(env):

def _am_create_incoterm_location_column(env):
"""
Create column then in sale_stock, purchase_stock will fill it in pre,
Create column then in sale_stock and purchase_stock will fill it in pre,
pr: https://github.com/odoo/odoo/pull/118954
"""
openupgrade.logged_query(
Expand All @@ -120,7 +119,7 @@ def _am_uniquify_name(env):
"""
UPDATE account_move SET name=name || ' [' || id || ']'
FROM (
SElECT array_agg(id) ids FROM account_move
SELECT array_agg(id) ids FROM account_move
GROUP BY journal_id, name HAVING COUNT(id)>1
) duplicate_names
WHERE account_move.id=ANY(duplicate_names.ids);
Expand Down Expand Up @@ -199,10 +198,74 @@ def _pre_create_early_pay_discount_computation(env):
FROM res_company rc
WHERE apt.company_id = rc.id
AND apt.early_pay_discount_computation IS NULL
AND rc.early_pay_discount_computation IS NOT NULL
""",
)


def _decouple_obsolete_tables(env):
"""
Remove all foreign keys held by and pointed to template tables
"""
obsolete_tables = [
"account_account_template",
"account_fiscal_position_account_template",
"account_fiscal_position_tax_template",
"account_fiscal_position_template",
"account_group_template",
"account_reconcile_model_line_template",
"account_reconcile_model_template",
"account_tax_repartition_line_template",
"account_tax_template",
]
openupgrade.remove_tables_fks(env.cr, obsolete_tables)
env.cr.execute(
"""
SELECT tc.table_name, tc.constraint_name
FROM information_schema.table_constraints tc
JOIN information_schema.constraint_table_usage ctu
ON tc.constraint_name=ctu.constraint_name
WHERE ctu.table_name in %s
AND tc.constraint_type='FOREIGN KEY'
""",
(tuple(obsolete_tables),),
)
for table, constraint in env.cr.fetchall():
openupgrade.logged_query(
env.cr, f"ALTER TABLE {table} DROP CONSTRAINT {constraint}"
)


def _pre_create_account_report_active(env):
"""
Precreate column with default value true, then switch back to false
"""
env.cr.execute(
"""
ALTER TABLE account_report ADD COLUMN active boolean DEFAULT true
"""
)
env.cr.execute(
"""
ALTER TABLE account_report ALTER COLUMN active SET DEFAULT false
"""
)


def _remove_obsolete_constraints(env):
"""
Remove constraints that will be deleted at the end of the migration
"""
table2constraints = {
"account_account": ["code_company_uniq"],
"account_fiscal_position_account": ["account_src_dest_uniq"],
"account_tax": ["name_company_uniq", "template_name_company_uniq"],
}
for table, constraints in table2constraints.items():
for constraint in constraints:
openupgrade.delete_sql_constraint_safely(env, "account", table, constraint)


@openupgrade.migrate()
def migrate(env, version):
_map_account_report_filter_account_type(env)
Expand All @@ -223,3 +286,6 @@ def migrate(env, version):
_account_report_update_figure_type(env)
_account_tax_repartition_line_merge_repartition_lines_m2o(env)
_pre_create_early_pay_discount_computation(env)
_decouple_obsolete_tables(env)
_pre_create_account_report_active(env)
_remove_obsolete_constraints(env)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ obsolete model account.reconcile.model.line.template
obsolete model account.reconcile.model.template
obsolete model account.tax.repartition.line.template
obsolete model account.tax.template
# NOTHING TO DO: these models has been converted to CSV definition and existing company records XML-ID follow the same logic
# DONE: these models has been converted to CSV definition and existing company records XML-ID follow the same logic. Removed all constraints from tables

obsolete model account.invoice.send [transient]
new model account.move.send [transient]
Expand Down Expand Up @@ -247,8 +247,9 @@ account / account.reconcile.model.template / rule_type (selection)
account / account.reconcile.model.template / sequence (integer) : DEL required
account / account.reconcile.model.template / to_check (boolean) : DEL
account / account.report / _order : _order is now 'sequence, id' ('id')
account / account.report / active (boolean) : NEW hasdefault: default
# NOTHING TO DO
account / account.report / active (boolean) : NEW hasdefault: default
# DONE: precreated with value True

account / account.report / chart_template (selection) : NEW selection_keys: function
account / account.report / chart_template_id (many2one) : DEL relation: account.chart.template
Expand Down

0 comments on commit 215de3b

Please sign in to comment.