[IMP] *: views: deprecate active_* keys from evalContext

This commit aims to simplify the evaluation context used to
evaluate expressions used in views (invisible, required, readonly,
domain and context attributes). For now, the evaluation context is
typically the current record (there's a key for each field in the
view). In addition to that, there're static keys (that may conflict
with field names): uid, allowed_company_ids, current_company_id,
active_id, active_ids and active_model.

The motivation of this commit is at some point to get rid of the
3 active_* keys, because they are misleading and basically useless.

The notion of active_* exists, but it is something else: when you
are in a form view (let's say the form of a partner) and you open
its opportunities (by clicking on the stat button), the list view
of opportunies shows up and in the context, there're 3 keys
active_*, referring to the record from which we came. One can
easily access those information with context.get("active_*"), in
python or in view archs.

However, almost all `active_id` found in archs were actually used
to refer to the id of the current record. Indeed, for now, in the
evaluation context of a record, the value of the `active_id` key is
always the id of the record. So this commit adapts them to
directly use `id` instead. There was no use of active_ids, and
a single use of active_model which was removed (active_model is
the res_model of the view, so it isn't really necessary).

This commit doesn't drop the support of those keys, it deprecates
them. They will be removed for v18. A warning will be displayed if
they are used.

closes odoo/odoo#136665

Related: odoo/enterprise#47917
Signed-off-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
Aaron Bohy
2023-10-10 00:54:04 +00:00
parent 25d5b98832
commit daf05d48ac
52 changed files with 101 additions and 107 deletions
@@ -107,7 +107,7 @@
<span role="separator">Reconciliation</span>
</div>
<div>
<a role="menuitem" type="object" name="open_action_with_context" context="{'action_name': 'action_account_reconcile_model', 'use_domain': ['|', ('match_journal_ids', '=', False), ('match_journal_ids', 'in', active_id)]}" groups="account.group_account_manager">Reconciliation Models</a>
<a role="menuitem" type="object" name="open_action_with_context" context="{'action_name': 'action_account_reconcile_model', 'use_domain': ['|', ('match_journal_ids', '=', False), ('match_journal_ids', 'in', [id])]}" groups="account.group_account_manager">Reconciliation Models</a>
</div>
</div>
</div>
@@ -34,7 +34,7 @@
<div name="button_box" class="oe_button_box">
<button class="oe_stat_button" type="action"
name="%(action_account_moves_all_a)d" icon="fa-book"
context="{'search_default_journal_id':active_id}">
context="{'search_default_journal_id':id}">
<div class="o_stat_info">
<span class="o_stat_text">Journal Entries</span>
</div>
+2 -2
View File
@@ -135,7 +135,7 @@
<div name="button_box" position="inside">
<button type="object" class="oe_stat_button" icon="fa-pencil-square-o" name="action_view_partner_invoices"
groups="account.group_account_invoice,account.group_account_readonly"
context="{'default_partner_id': active_id}">
context="{'default_partner_id': id}">
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
<field name="currency_id" invisible="1"/>
@@ -197,7 +197,7 @@
<field name="show_credit_limit" invisible="1"/>
<group>
<group string="Bank Accounts" name="banks" groups="account.group_account_invoice,account.group_account_readonly">
<field name="bank_ids" nolabel="1" colspan="2" context="{'default_partner_id': active_id}" widget="auto_save_res_partner">
<field name="bank_ids" nolabel="1" colspan="2" context="{'default_partner_id': id}" widget="auto_save_res_partner">
<tree>
<field name="sequence" widget="handle"/>
<field name="acc_number"/>
@@ -10,7 +10,7 @@
class="oe_stat_button"
icon="fa-globe"
type="action"
context="{'default_country_id': active_id, 'search_default_country_id': active_id}">
context="{'default_country_id': id, 'search_default_country_id': id}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Cities</span>
</div>
+1 -1
View File
@@ -35,7 +35,7 @@
<button class="oe_stat_button" type="object"
name="schedule_meeting"
icon="fa-calendar"
context="{'partner_id': active_id, 'partner_name': name}">
context="{'partner_id': id, 'partner_name': name}">
<field string="Meetings" name="meeting_count" widget="statinfo"/>
</button>
</div>
+1 -1
View File
@@ -39,7 +39,7 @@
name="action_view_opportunity"
icon="fa-star"
groups="sales_team.group_sale_salesman"
context="{'default_partner_id': active_id, 'default_type':'opportunity'}">
context="{'default_partner_id': id, 'default_type':'opportunity'}">
<field string="Opportunities" name="opportunity_count" widget="statinfo"/>
</button>
</div>
+2 -2
View File
@@ -14,7 +14,7 @@
<header>
<button name="%(event_barcode_action_main_view)d"
type="action"
context="{'default_event_id': active_id}">
context="{'default_event_id': id}">
Registration Desk
</button>
<field name="stage_id" widget="statusbar" options="{'clickable': '1'}"/>
@@ -42,7 +42,7 @@
type="action"
class="oe_stat_button"
icon="fa-mobile"
context="{'default_event_id': active_id}">
context="{'default_event_id': id}">
<div class="o_stat_info">
<span class="o_stat_text">Registration Desk</span>
</div>
+1 -1
View File
@@ -24,7 +24,7 @@
<h1><field nolabel="1" name="name" placeholder='e.g. "Age Category"'/></h1>
</div>
<group>
<field name="tag_ids" context="{'default_category_id': active_id}">
<field name="tag_ids" context="{'default_category_id': id}">
<tree string="Tags" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name" placeholder='e.g. "12-16 years old"'/>
@@ -89,7 +89,7 @@
</group>
</group>
<group string="Rewards for challenges">
<field name="challenge_ids" mode="kanban" widget="many2many" nolabel="1" context="{'default_reward_id': active_id}" colspan="2"/>
<field name="challenge_ids" mode="kanban" widget="many2many" nolabel="1" context="{'default_reward_id': id}" colspan="2"/>
<field name="level" colspan="2"/>
</group>
<group id="badge_statistics" string="Statistics">
+1 -1
View File
@@ -198,7 +198,7 @@
<group>
<group string='Status' name="active_group">
<field name="employee_type"/>
<field name="user_id" string="Related User" domain="[('share', '=', False)]" context="{'default_create_employee_id': active_id}" widget="many2one_avatar_user"/>
<field name="user_id" string="Related User" domain="[('share', '=', False)]" context="{'default_create_employee_id': id}" widget="many2one_avatar_user"/>
</group>
<group string="Attendance/Point of Sale" name="identification_group">
<field name="pin" string="PIN Code"/>
@@ -31,7 +31,7 @@
icon="fa-history"
type="action"
invisible="total_overtime == 0.0"
context="{'search_default_employee_id': active_id}"
context="{'search_default_employee_id': id}"
groups="hr_attendance.group_hr_attendance_user">
<div class="o_stat_info">
<span class="o_stat_value text-success" invisible="total_overtime &lt; 0">
+2 -2
View File
@@ -173,7 +173,7 @@
<button name="action_time_off_dashboard"
type="object"
class="oe_stat_button"
context="{'search_default_employee_ids': active_id}"
context="{'search_default_employee_ids': id}"
invisible="not is_absent">
<div invisible="hr_icon_display != 'presence_holiday_present'"
role="img" class="fa fa-fw fa-plane o_button_icon text-success" aria-label="Off Till" title="Off Till"/>
@@ -193,7 +193,7 @@
class="oe_stat_button"
icon="fa-calendar"
invisible="not show_leaves"
context="{'search_default_employee_ids': active_id}"
context="{'search_default_employee_ids': id}"
groups="base.group_user"
help="Remaining leaves">
<div class="o_field_widget o_stat_info" invisible="allocation_display == '0'">
+2 -2
View File
@@ -40,7 +40,7 @@
<a name="action_open_activities" type="object">Activities</a>
</div>
<div role="menuitem">
<a name="%(action_hr_job_sources)d" type="action" context="{'default_job_id': active_id}">Trackers</a>
<a name="%(action_hr_job_sources)d" type="action" context="{'default_job_id': id}">Trackers</a>
</div>
</div>
<div class="col-6 o_kanban_card_manage_section">
@@ -215,7 +215,7 @@
</button>
<button class="oe_stat_button" type="action"
name="%(action_hr_job_sources)d" icon="fa-bar-chart-o"
context="{'default_job_id': active_id}">
context="{'default_job_id': id}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Trackers</span>
</div>
@@ -9,7 +9,7 @@
<xpath expr="//div[hasclass('o_kanban_manage_reports')]" position="inside">
<a name="%(act_hr_timesheet_report)d" type="action"
groups="hr_timesheet.group_timesheet_manager" class="dropdown-item"
context="{ 'search_default_department_id': [active_id], 'default_department_id': active_id}">
context="{ 'search_default_department_id': [id], 'default_department_id': id}">
Timesheets
</a>
</xpath>
@@ -47,7 +47,7 @@
<xpath expr="//div[hasclass('o_kanban_manage_reports')]" position="inside">
<a name="%(act_hr_timesheet_report)d" type="action"
groups="hr_timesheet.group_timesheet_manager" class="dropdown-item"
context="{ 'search_default_department_id': [active_id], 'default_department_id': active_id}">
context="{ 'search_default_department_id': [id], 'default_department_id': id}">
Timesheets
</a>
</xpath>
+1 -2
View File
@@ -274,8 +274,7 @@
</div>
</div>
<footer>
<button string="Save" special="save" data-hotkey="q" class="oe_highlight" invisible="not context.get('active_id', False)"/>
<button string="Add To Cart" name="add_to_cart" type="object" class="oe_highlight" invisible="context.get('active_id', False) or order_deadline_passed" data-hotkey="w"/>
<button string="Add To Cart" name="add_to_cart" type="object" class="oe_highlight" invisible="order_deadline_passed" data-hotkey="w"/>
<button string="Discard" special="cancel" data-hotkey="x"/>
</footer>
</form>
+2 -2
View File
@@ -226,7 +226,7 @@
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="action" name="%(lunch.lunch_product_action_statbutton)d"
context="{'search_default_category_id': active_id,'default_category_id': active_id}"
context="{'search_default_category_id': id,'default_category_id': id}"
invisible="product_count == 0"
icon="fa-cutlery">
<field string="Products" name="product_count" widget="statinfo"/>
@@ -264,7 +264,7 @@
<div class="float-end">
<button class="badge text-bg-primary" type="action"
name="%(lunch.lunch_product_action_statbutton)d"
context="{'search_default_category_id': active_id,'default_category_id': active_id}"
context="{'search_default_category_id': id,'default_category_id': id}"
invisible="product_count == 0">
<field string="Products" name="product_count" widget="statinfo"/>
</button>
+4 -4
View File
@@ -64,7 +64,7 @@
<div class="oe_button_box" name="button_box" groups="base.group_user" invisible="not can_manage_group">
<button name="%(mail_group.mail_group_member_action)d"
type="action"
context="{'search_default_mail_group_id': active_id}"
context="{'search_default_mail_group_id': id}"
class="oe_stat_button"
icon="fa-users"
help="Members of this group">
@@ -72,7 +72,7 @@
</button>
<button name="%(mail_group.mail_group_message_action)d"
type="action"
context="{'search_default_mail_group_id': active_id}"
context="{'search_default_mail_group_id': id}"
class="oe_stat_button"
icon="fa-envelope"
help="All messages of this group">
@@ -80,7 +80,7 @@
</button>
<button name="%(mail_group.mail_group_message_action)d"
type="action"
context="{'search_default_mail_group_id': active_id, 'search_default_moderation_status': 'pending_moderation'}"
context="{'search_default_mail_group_id': id, 'search_default_moderation_status': 'pending_moderation'}"
class="oe_stat_button"
icon="fa-commenting-o"
help="Emails waiting an action for this group"
@@ -89,7 +89,7 @@
</button>
<button name="%(mail_group.mail_group_moderation_action)d"
type="action"
context="{'search_default_mail_group_id': active_id}"
context="{'search_default_mail_group_id': id}"
invisible="not moderation"
class="oe_stat_button"
icon="fa-gavel"
@@ -846,7 +846,7 @@
<span>Reporting</span>
</div>
<div role="menuitem">
<a name="%(maintenance_request_action_reports)d" type="action" context="{'search_default_maintenance_team_id': active_id}">
<a name="%(maintenance_request_action_reports)d" type="action" context="{'search_default_maintenance_team_id': id}">
Maintenance Requests
</a>
</div>
+1 -1
View File
@@ -302,7 +302,7 @@
<button type="object"
name="action_show_operations"
invisible="not has_routing_lines"
context="{'default_workcenter_id': active_id}"
context="{'default_workcenter_id': id}"
class="oe_stat_button" icon="fa-cog">
<div class="o_stat_info">
<span class="o_stat_text">Operations</span>
+3 -3
View File
@@ -33,7 +33,7 @@
<span>New</span>
</div>
<div role="menuitem">
<a name="%(action_mrp_production_form)d" context="{'default_picking_type_id': active_id}" type="action">Manufacturing Order</a>
<a name="%(action_mrp_production_form)d" context="{'default_picking_type_id': id}" type="action">Manufacturing Order</a>
</div>
</div>
</div>
@@ -65,7 +65,7 @@
<div class="container o_kanban_card_content" t-if="!selection_mode">
<div class="row">
<div class="col-6 o_kanban_primary_left">
<button class="btn btn-primary" name="%(mrp_production_action_picking_deshboard)d" type="action" context="{'search_default_todo': 1, 'default_picking_type_id': active_id}">
<button class="btn btn-primary" name="%(mrp_production_action_picking_deshboard)d" type="action" context="{'search_default_todo': 1, 'default_picking_type_id': id}">
<span t-if="record.code.raw_value =='mrp_operation'"><t t-esc="record.count_mo_todo.value"/> To Process</span>
</button>
</div>
@@ -82,7 +82,7 @@
</div>
<div t-if="record.count_mo_late.raw_value > 0" class="row">
<div class="col-9">
<a class="oe_kanban_stock_picking_type_list" name="%(mrp_production_action_picking_deshboard)d" type="action" context="{'search_default_planning_issues': 1, 'default_picking_type_id': active_id}">
<a class="oe_kanban_stock_picking_type_list" name="%(mrp_production_action_picking_deshboard)d" type="action" context="{'search_default_planning_issues': 1, 'default_picking_type_id': id}">
Late
</a>
</div>
+1 -1
View File
@@ -12,7 +12,7 @@
<button type="action" class="oe_stat_button"
icon="fa-credit-card-alt"
name="%(payment.action_payment_token)d"
context="{'search_default_partner_id': active_id, 'create': False, 'edit': False}"
context="{'search_default_partner_id': id, 'create': False, 'edit': False}"
invisible="payment_token_count == 0">
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
@@ -9,7 +9,7 @@
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="action_view_pos_order"
groups="point_of_sale.group_pos_user"
context="{'default_partner_id': active_id}"
context="{'default_partner_id': id}"
invisible="pos_order_count == 0"
icon="fa-shopping-bag">
<field string="PoS Orders" name="pos_order_count" widget="statinfo"/>
@@ -12,7 +12,7 @@
name="%(product_template_action_all)d"
icon="fa-th-list"
type="action"
context="{'search_default_categ_id': active_id, 'default_categ_id': active_id, 'group_expand': True}">
context="{'search_default_categ_id': id, 'default_categ_id': id, 'group_expand': True}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value"><field name="product_count"/></span>
<span class="o_stat_text"> Products</span>
@@ -7,7 +7,7 @@
<tree string="Project Collaborators" create="0">
<header>
<button name="%(project_share_wizard_action)d" class="btn-primary" type="action" string="Invite Collaborators"
context="{'default_access_mode': 'edit', 'default_project_id': active_id}" display="always"/>
context="{'default_access_mode': 'edit', 'default_project_id': context.get('active_id')}" display="always"/>
</header>
<field name="partner_id" options="{'no_create': True}"/>
<field name="partner_email"/>
@@ -204,7 +204,7 @@
<field name="stage_id" optional="show"/>
<button name="action_open_task" type="object" title="View Task" string="View Task" class="btn btn-link float-end"
context="{'form_view_ref': 'project.project_sharing_project_task_view_form', 'search_view_ref': 'project.project_sharing_project_task_view_search'}"
invisible="project_id or project_id != active_id"/>
invisible="project_id or project_id != id"/>
</tree>
</field>
</page>
+1 -1
View File
@@ -9,7 +9,7 @@
<div name="button_box" position="inside">
<button class="oe_stat_button" type="action" name="%(project_task_action_from_partner)d"
groups="project.group_project_user"
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}" invisible="task_count == 0"
context="{'search_default_partner_id': id, 'default_partner_id': id}" invisible="task_count == 0"
icon="fa-tasks">
<field string="Tasks" name="task_count" widget="statinfo"/>
</button>
+4 -1
View File
@@ -43,7 +43,7 @@
</xpath>
<group name="purchase" position="before">
<field name="seller_ids" context="{'default_product_tmpl_id': id, 'product_template_invisible_variant': True, 'tree_view_ref':'purchase.product_supplierinfo_tree_view2'}" nolabel="1" invisible="product_variant_count &gt; 1" readonly="product_variant_count &gt; 1"/>
<field name="variant_seller_ids" context="{'model': active_model, 'active_id': active_id, 'tree_view_ref':'purchase.product_supplierinfo_tree_view2'}" nolabel="1" invisible="product_variant_count &lt;= 1" readonly="product_variant_count &lt;= 1"/>
<field name="variant_seller_ids" context="{'model': 'product.template', 'active_id': id, 'tree_view_ref':'purchase.product_supplierinfo_tree_view2'}" nolabel="1" invisible="product_variant_count &lt;= 1" readonly="product_variant_count &lt;= 1"/>
</group>
<group name="bill" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
@@ -77,6 +77,9 @@
<field name="seller_ids" position="attributes">
<attribute name="context">{'default_product_tmpl_id': product_tmpl_id, 'product_template_invisible_variant': True, 'tree_view_ref':'purchase.product_supplierinfo_tree_view2'}</attribute>
</field>
<field name="variant_seller_ids" position="attributes">
<attribute name="context">{'model': 'product.product', 'active_id': id, 'tree_view_ref':'purchase.product_supplierinfo_tree_view2'}</attribute>
</field>
</field>
</record>
@@ -13,7 +13,7 @@
<field name="optional_product_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"
domain="[('id', '!=', active_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
domain="[('id', '!=', id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
placeholder="Recommend when 'Adding to Cart' or quotation"/>
</group>
</field>
@@ -59,8 +59,8 @@
invisible="not display_sales_stat_buttons or sale_order_count == 0"
groups="sales_team.group_sale_salesman_all_leads"
context="{
'create_for_project_id': active_id,
'default_project_id': active_id,
'create_for_project_id': id,
'default_project_id': id,
'default_partner_id': partner_id
}">
<div class="o_field_widget o_stat_info">
@@ -80,8 +80,8 @@
invisible="not display_sales_stat_buttons or sale_order_count != 0"
groups="sales_team.group_sale_salesman_all_leads"
context="{
'create_for_project_id': active_id,
'default_project_id': active_id,
'create_for_project_id': id,
'default_project_id': id,
'default_partner_id': partner_id
}">
<div class="o_field_widget o_stat_info">
@@ -7,10 +7,10 @@
<field name="inherit_id" ref="hr_timesheet.project_invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_view_sos'][1]" position="attributes">
<attribute name="context">{'create_for_project_id': active_id, 'default_project_id': active_id, 'default_partner_id': partner_id, 'default_analytic_account_id': analytic_account_id}</attribute>
<attribute name="context">{'create_for_project_id': id, 'default_project_id': id, 'default_partner_id': partner_id, 'default_analytic_account_id': analytic_account_id}</attribute>
</xpath>
<xpath expr="//button[@name='action_view_sos'][2]" position="attributes">
<attribute name="context">{'create_for_project_id': active_id, 'default_project_id': active_id, 'default_partner_id': partner_id, 'default_analytic_account_id': analytic_account_id}</attribute>
<attribute name="context">{'create_for_project_id': id, 'default_project_id': id, 'default_partner_id': partner_id, 'default_analytic_account_id': analytic_account_id}</attribute>
</xpath>
<xpath expr="//page[@name='settings']" position="after">
<page name="billing_employee_rate" string="Invoicing" invisible="not allow_billable or not partner_id">
+1 -1
View File
@@ -86,7 +86,7 @@
'kanban_view_ref': 'sales_team.crm_team_member_view_kanban_from_team',
'form_view_ref': 'sales_team.crm_team_member_view_form_from_team',
'tree_view_ref': 'sales_team.crm_team_member_view_tree_from_team',
'default_crm_team_id': active_id,
'default_crm_team_id': id,
}"/>
</page>
</notebook>
@@ -140,7 +140,7 @@
</div>
</group>
</group>
<field name="suggested_answer_ids" context="{'default_question_id': active_id}" invisible="question_type not in ['simple_choice', 'multiple_choice', 'matrix']">
<field name="suggested_answer_ids" context="{'default_question_id': id}" invisible="question_type not in ['simple_choice', 'multiple_choice', 'matrix']">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="value" string="Choices"/>
@@ -154,7 +154,7 @@
</tree>
</field>
<field name="matrix_row_ids" context="{'default_matrix_question_id': active_id}"
<field name="matrix_row_ids" context="{'default_matrix_question_id': id}"
invisible="question_type != 'matrix'">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
+2 -2
View File
@@ -64,7 +64,7 @@
</group>
<notebook>
<page string="Questions" name="questions">
<field name="question_and_page_ids" nolabel="1" widget="question_page_one2many" mode="tree,kanban" context="{'default_survey_id': active_id}">
<field name="question_and_page_ids" nolabel="1" widget="question_page_one2many" mode="tree,kanban" context="{'default_survey_id': id}">
<tree decoration-bf="is_page">
<field name="sequence" widget="handle"/>
<field name="title" widget="survey_description_page"/>
@@ -154,7 +154,7 @@
placeholder="Pick a Badge..."
invisible="not certification_give_badge or certification_badge_id"
required="certification_give_badge"
domain="[('survey_id', '=', active_id), ('survey_id', '!=', False)]"
domain="[('survey_id', '=', id), ('survey_id', '!=', False)]"
context="{'default_name': title,
'default_description': 'Congratulations, you have succeeded this certification',
'default_rule_auth': 'nobody',
@@ -999,7 +999,11 @@ export class Record extends DataPoint {
this._isEvalContextReady = true;
if (!this._parentRecord || this._parentRecord._isEvalContextReady) {
this._updateChildrenContext();
for (const [fieldName, value] of Object.entries(toRaw(this.data))) {
if (["one2many", "many2many"].includes(this.fields[fieldName].type)) {
value._updateContext(getFieldContext(this, fieldName));
}
}
}
}
@@ -1117,12 +1121,4 @@ export class Record extends DataPoint {
await this.model.hooks.onRecordChanged(this, this._getChanges());
}
}
_updateChildrenContext() {
for (const [fieldName, value] of Object.entries(toRaw(this.data))) {
if (["one2many", "many2many"].includes(this.fields[fieldName].type)) {
value._updateContext(getFieldContext(this, fieldName));
}
}
}
}
@@ -90,6 +90,7 @@ export class StaticList extends DataPoint {
context,
uid: context.uid,
allowed_company_ids: context.allowed_company_ids,
current_company_id: this.config.currentCompanyId,
parent: this._parent.evalContext,
};
}
@@ -955,7 +956,7 @@ export class StaticList extends DataPoint {
_updateContext(context) {
Object.assign(this.context, context);
for (const record of Object.values(this._cache)) {
record._updateChildrenContext();
record._setEvalContext();
}
}
}
@@ -343,9 +343,9 @@ export function getBasicEvalContext(config) {
context: config.context,
uid,
allowed_company_ids,
active_id: config.resId || false,
active_ids: config.resId ? [config.resId] : [],
active_model: config.resModel,
active_id: config.resId || false, // deprecated, will be removed in v18
active_ids: config.resId ? [config.resId] : [], // deprecated, will be removed in v18
active_model: config.resModel, // deprecated, will be removed in v18
current_company_id: config.currentCompanyId,
};
}
@@ -1991,12 +1991,13 @@ QUnit.module("Fields", (hooks) => {
});
QUnit.test("many2many basic keys in field evalcontext -- in list", async (assert) => {
assert.expect(6);
assert.expect(5);
serverData.models.partner_type.fields.partner_id = {
string: "Partners",
type: "many2one",
relation: "partner",
};
serverData.models.partner.records.push({ id: 7, display_name: "default partner" });
serverData.views = {
"partner_type,false,form": `<form><field name="partner_id" /></form>`,
};
@@ -2024,13 +2025,12 @@ QUnit.module("Fields", (hooks) => {
serverData,
arch: `
<tree editable="top">
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': active_id, 'ids': active_ids, 'model': active_model, 'company_id': current_company_id}"/>
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/>
</tree>`,
mockRPC(route, args) {
if (args.method === "onchange") {
assert.strictEqual(args.kwargs.context.default_partner_id, 1);
assert.strictEqual(args.kwargs.context.model, "partner");
assert.deepEqual(args.kwargs.context.ids, [1]);
assert.strictEqual(args.kwargs.context.uid, 7);
assert.deepEqual(args.kwargs.context.allowed_company_ids, [3]);
assert.strictEqual(args.kwargs.context.company_id, 3);
}
},
@@ -2042,17 +2042,18 @@ QUnit.module("Fields", (hooks) => {
assert.containsOnce(target, ".modal .o_field_many2one");
assert.strictEqual(
target.querySelector(".modal .o_field_many2one input").value,
"first record"
"default partner"
);
});
QUnit.test("many2many basic keys in field evalcontext -- in form", async (assert) => {
assert.expect(6);
assert.expect(5);
serverData.models.partner_type.fields.partner_id = {
string: "Partners",
type: "many2one",
relation: "partner",
};
serverData.models.partner.records.push({ id: 7, display_name: "default partner" });
serverData.views = {
"partner_type,false,form": `<form><field name="partner_id" /></form>`,
};
@@ -2081,13 +2082,12 @@ QUnit.module("Fields", (hooks) => {
serverData,
arch: `
<form>
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': active_id, 'ids': active_ids, 'model': active_model, 'company_id': current_company_id}"/>
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/>
</form>`,
mockRPC(route, args) {
if (args.method === "onchange") {
assert.strictEqual(args.kwargs.context.default_partner_id, 1);
assert.strictEqual(args.kwargs.context.model, "partner");
assert.deepEqual(args.kwargs.context.ids, [1]);
assert.strictEqual(args.kwargs.context.default_partner_id, 7);
assert.deepEqual(args.kwargs.context.allowed_company_ids, [3]);
assert.strictEqual(args.kwargs.context.company_id, 3);
}
},
@@ -2099,19 +2099,20 @@ QUnit.module("Fields", (hooks) => {
assert.containsOnce(target, ".modal .o_field_many2one");
assert.strictEqual(
target.querySelector(".modal .o_field_many2one input").value,
"first record"
"default partner"
);
});
QUnit.test(
"many2many basic keys in field evalcontext -- in a x2many in form",
async (assert) => {
assert.expect(6);
assert.expect(5);
serverData.models.partner_type.fields.partner_id = {
string: "Partners",
type: "many2one",
relation: "partner",
};
serverData.models.partner.records.push({ id: 7, display_name: "default partner" });
serverData.views = {
"partner_type,false,form": `<form><field name="partner_id" /></form>`,
};
@@ -2144,15 +2145,14 @@ QUnit.module("Fields", (hooks) => {
<form>
<field name="p">
<tree editable="top">
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': active_id, 'ids': active_ids, 'model': active_model, 'company_id': current_company_id}"/>
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/>
</tree>
</field>
</form>`,
mockRPC(route, args) {
if (args.method === "onchange") {
assert.strictEqual(args.kwargs.context.default_partner_id, 1);
assert.strictEqual(args.kwargs.context.model, "partner");
assert.deepEqual(args.kwargs.context.ids, [1]);
assert.strictEqual(args.kwargs.context.default_partner_id, 7);
assert.deepEqual(args.kwargs.context.allowed_company_ids, [3]);
assert.strictEqual(args.kwargs.context.company_id, 3);
}
},
@@ -2164,7 +2164,7 @@ QUnit.module("Fields", (hooks) => {
assert.containsOnce(target, ".modal .o_field_many2one");
assert.strictEqual(
target.querySelector(".modal .o_field_many2one input").value,
"first record"
"default partner"
);
}
);
@@ -1118,7 +1118,7 @@ QUnit.module("Views", (hooks) => {
arch: `
<form>
<field string="Partner Types" name="timmy" widget="one2many" context="{
'default_partner_id': active_id,
'default_partner_id': id,
'form_view_ref': 'foo_partner_type_form_view'
}"/>
</form>`,
@@ -7340,7 +7340,7 @@ QUnit.module("Views", (hooks) => {
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="action" name="1" context="{'test': active_id}">
<button class="oe_stat_button" type="action" name="1" context="{'test': id}">
<field name="qux" widget="statinfo"/>
</button>
</div>
@@ -7879,8 +7879,8 @@ QUnit.module("Views", (hooks) => {
assert.containsOnce(target, ".o_field_widget[name=timmy] .o_tag");
});
QUnit.test("check if id and active_id are defined", async function (assert) {
assert.expect(2);
QUnit.test("check if id is available in evaluation context", async function (assert) {
assert.expect(1);
let checkOnchange = false;
await makeView({
@@ -7889,7 +7889,7 @@ QUnit.module("Views", (hooks) => {
serverData,
arch: `
<form>
<field name="p" context="{'default_trululu': active_id, 'current_id': id}">
<field name="p" context="{'current_id': id}">
<tree><field name="trululu"/></tree>
<form><field name="trululu"/></form>
</field>
@@ -7901,11 +7901,6 @@ QUnit.module("Views", (hooks) => {
false,
"current_id should be false"
);
assert.strictEqual(
args.kwargs.context.default_trululu,
false,
"default_trululu should be false"
);
}
},
});
+1 -1
View File
@@ -344,7 +344,7 @@ export function getActionManagerServerData() {
<header></header>
<sheet>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" type="action" name="1" icon="fa-star" context="{'default_partner': active_id}">
<button class="oe_stat_button" type="action" name="1" icon="fa-star" context="{'default_partner': id}">
<field string="Partners" name="o2m" widget="statinfo"/>
</button>
</div>
@@ -8,7 +8,7 @@
<field name="priority" eval="10"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_published']" position="before">
<button class="oe_stat_button" context="{'default_event_id': active_id, 'search_default_event_id': active_id}" icon="fa-comments-o" name="%(event_meeting_room_action)d" type="action">
<button class="oe_stat_button" context="{'default_event_id': id, 'search_default_event_id': id}" icon="fa-comments-o" name="%(event_meeting_room_action)d" type="action">
<field name="meeting_room_count" string="Rooms" widget="statinfo"/>
</button>
</xpath>
@@ -8,7 +8,7 @@
<sheet>
<group>
<field name="name"/>
<field name="tag_ids" context="{'default_category_id': active_id}">
<field name="tag_ids" context="{'default_category_id': id}">
<tree string="Tags" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
+1 -1
View File
@@ -153,7 +153,7 @@
<field name="accessory_product_ids" widget="many2many_tags" invisible="not sale_ok"
placeholder="Suggested accessories in the eCommerce cart"/>
<field name="alternative_product_ids" widget="many2many_tags"
domain="[('id', '!=', active_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
domain="[('id', '!=', id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
invisible="not sale_ok"
placeholder="Displayed in bottom of product pages"/>
</group>
+1 -1
View File
@@ -8,7 +8,7 @@
<field name="arch" type="xml">
<notebook position="inside">
<page string="Product Page Extra Fields" groups="base.group_no_one">
<field name="shop_extra_field_ids" context="{'default_website_id': active_id}">
<field name="shop_extra_field_ids" context="{'default_website_id': id}">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="field_id" required="1" options="{'no_create': True}"/>
@@ -73,7 +73,7 @@
</div>
<notebook colspan="4">
<page name="content" string="Content">
<field name="slide_ids" string="Content" colspan="4" nolabel="1" widget="slide_category_one2many" mode="tree,kanban" context="{'default_channel_id': active_id, 'form_view_ref' : 'website_slides.view_slide_slide_form_wo_channel_id'}">
<field name="slide_ids" string="Content" colspan="4" nolabel="1" widget="slide_category_one2many" mode="tree,kanban" context="{'default_channel_id': id, 'form_view_ref' : 'website_slides.view_slide_slide_form_wo_channel_id'}">
<tree decoration-bf="is_category" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
@@ -128,7 +128,7 @@
invisible="channel_type == 'training' or promote_strategy != 'specific'"
required="channel_type != 'training' and promote_strategy == 'specific'"
string="Content"
domain="[('channel_id', '=', active_id), ('is_category', '=', False)]"/>
domain="[('channel_id', '=', id), ('is_category', '=', False)]"/>
</group>
</group>
</page>
@@ -15,7 +15,7 @@
</button>
</xpath>
<xpath expr="//field[@name='allow_comment']" position="after">
<field string="Forum" name="forum_id" domain="[('slide_channel_id', 'in', [active_id, False])]"/>
<field string="Forum" name="forum_id" domain="[('slide_channel_id', 'in', [id, False])]"/>
</xpath>
</field>
</record>
+3
View File
@@ -2875,6 +2875,9 @@ class NameManager:
view._raise_view_error(msg)
info = self.available_fields[name].get('info')
if info is None:
if name in ['active_id', 'active_ids', 'active_model']:
_logger.warning("Using active_id, active_ids and active_model in expressions is deprecated, found %s", name)
continue
msg = _(
"Field %(name)r used in %(use)s must be present in view but is missing.",
name=name, use=use,
+1 -1
View File
@@ -26,7 +26,7 @@
<page string="Submenus" name="submenus" groups="base.group_no_one">
<!-- Note: make sure you have 'ir.ui.menu.full_list'
in the context to see all submenus! -->
<field name="child_id" context="{'default_parent_id': active_id}">
<field name="child_id" context="{'default_parent_id': id}">
<tree string="Menu">
<field name="sequence"/>
<field icon="icon" name="name" string="Menu"/>
+1 -1
View File
@@ -35,7 +35,7 @@
<field name="groups_id"/>
</page>
<page name="inherit_children" string="Inherited Views">
<field name="inherit_children_ids" context="{'default_model':model,'default_type':type,'default_inherit_id':active_id,'default_mode':'extension', 'active_test': False}">
<field name="inherit_children_ids" context="{'default_model':model,'default_type':type,'default_inherit_id':id,'default_mode':'extension', 'active_test': False}">
<tree default_order="priority,id" decoration-muted="not active">
<field name="active" column_invisible="True"/>
<field name="id"/>
+1 -1
View File
@@ -46,7 +46,7 @@
</group>
</page>
<page string="Branches" name="branches">
<field name="child_ids" nolabel="1" context="{'default_parent_id': active_id}"/>
<field name="child_ids" nolabel="1" context="{'default_parent_id': id}"/>
</page>
</notebook>
</sheet>
+1 -1
View File
@@ -244,7 +244,7 @@
<notebook colspan="4">
<page string="Contacts &amp; Addresses" name="contact_addresses" autofocus="autofocus">
<field name="child_ids" mode="kanban" context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': 'other'}">
<field name="child_ids" mode="kanban" context="{'default_parent_id': id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': 'other'}">
<kanban>
<field name="id"/>
<field name="color"/>
-3
View File
@@ -25,11 +25,8 @@ IGNORED_IN_EXPRESSION = {
'uid',
'context',
'context_today',
'active_id',
'active_ids',
'allowed_company_ids',
'current_company_id',
'active_model',
'time',
'datetime',
'relativedelta',