[FIX] web,mrp,stock: don't call action buttons for virtual records in x2manys
Steps to reproduce
==================
- Make sure the "Work Orders" setting is enabled
- Manufacturing > Products > Bills of Materials > New
- Select a random product
- In the Operations tab, add a line
- Type something in the Operation field
- Set the workcenter to Assembly line 1
- Save and close
- Click on the "Show Instructions" action button
```
Traceback (most recent call last):
File "/home/hubert/src/16.0/odoo/odoo/models.py", line 5108, in ensure_one
_id, = self._ids
^^^^
ValueError: not enough values to unpack (expected 1, got 0)
```
Cause of the issue
==================
The action is called without in id because the record is not yet created
Solution
========
The button should display a warning in x2manys when the record is virtual.
This was actually the case before Odoo 16 but there was an option on the
button `options='{"warn": true}'`. With this commit, it will be the
default behavior.
We also remove this option from the xml since it isn't used.
sentry-3950549982
closes odoo/odoo#114505
X-original-commit: 9fc0424a4450923aa8582bdb6766e1b19cb68546
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
@@ -369,8 +369,8 @@
|
||||
domain="[('product_id','=',product_id)]"
|
||||
/>
|
||||
<field name="group_id" invisible="1"/>
|
||||
<button name="action_show_details" type="object" title="Show Details" icon="fa-list" context="{'default_product_uom_qty': 0}" attrs="{'invisible': ['|', ('show_details_visible', '=', False), ('has_tracking', '=','none')]}" options="{"warn": true}"/>
|
||||
<button class="o_optional_button btn btn-light" name="action_show_details" type="object" title="Show Details" icon="fa-list" context="{'default_product_uom_qty': 0}" attrs="{'invisible': ['|', ('has_tracking', '!=','none'), ('show_details_visible', '=', False)]}" options="{"warn": true}"/>
|
||||
<button name="action_show_details" type="object" title="Show Details" icon="fa-list" context="{'default_product_uom_qty': 0}" attrs="{'invisible': ['|', ('show_details_visible', '=', False), ('has_tracking', '=','none')]}"/>
|
||||
<button class="o_optional_button btn btn-light" name="action_show_details" type="object" title="Show Details" icon="fa-list" context="{'default_product_uom_qty': 0}" attrs="{'invisible': ['|', ('has_tracking', '!=','none'), ('show_details_visible', '=', False)]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
@@ -413,8 +413,8 @@
|
||||
context="{'default_company_id': company_id, 'default_product_id': product_id}"
|
||||
domain="[('product_id','=',product_id)]"
|
||||
/>
|
||||
<button name="action_show_details" type="object" title="Show Details" icon="fa-list" attrs="{'invisible': ['|', ('has_tracking', '=','none'), ('show_details_visible', '=', False)]}" options="{"warn": true}"/>
|
||||
<button class="o_optional_button btn btn-light" name="action_show_details" type="object" title="Show Details" icon="fa-list" attrs="{'invisible': ['|', ('has_tracking', '!=','none'), ('show_details_visible', '=', False)]}" options="{"warn": true}"/>
|
||||
<button name="action_show_details" type="object" title="Show Details" icon="fa-list" attrs="{'invisible': ['|', ('has_tracking', '=','none'), ('show_details_visible', '=', False)]}"/>
|
||||
<button class="o_optional_button btn btn-light" name="action_show_details" type="object" title="Show Details" icon="fa-list" attrs="{'invisible': ['|', ('has_tracking', '!=','none'), ('show_details_visible', '=', False)]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
</div>
|
||||
<button name="action_show_details" string="Register lots, packs, location"
|
||||
class="o_icon_button fa fa-list" type="object"
|
||||
attrs="{'invisible': [('show_details_visible', '=', False)]}" options='{"warn": true}'/>
|
||||
attrs="{'invisible': [('show_details_visible', '=', False)]}"/>
|
||||
</div>
|
||||
<div class="o_kanban_record_body">
|
||||
<div attrs="{'invisible': [('is_inventory', '=', False)]}">
|
||||
|
||||
@@ -304,7 +304,7 @@
|
||||
domain="[('product_id','=',product_id)]"
|
||||
/>
|
||||
<button name="action_show_details" type="object" icon="fa-list" title="Details"
|
||||
attrs="{'invisible': [('show_details_visible', '=', False)]}" options='{"warn": true}'/>
|
||||
attrs="{'invisible': [('show_details_visible', '=', False)]}"/>
|
||||
<button name="action_assign_serial" type="object"
|
||||
icon="fa-plus-square"
|
||||
role="img" title="Assign Serial Numbers"
|
||||
|
||||
@@ -62,6 +62,7 @@ export class ListRenderer extends Component {
|
||||
setup() {
|
||||
this.uiService = useService("ui");
|
||||
this.allColumns = this.processAllColumn(this.props.archInfo.columns, this.props.list);
|
||||
this.notificationService = useService("notification");
|
||||
this.keyOptionalFields = this.createKeyOptionalFields();
|
||||
this.getOptionalActiveFields();
|
||||
this.cellClassByColumn = {};
|
||||
@@ -208,6 +209,12 @@ export class ListRenderer extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
displaySaveNotification() {
|
||||
this.notificationService.add(this.env._t('Please click on the "save" button first'), {
|
||||
type: "danger",
|
||||
});
|
||||
}
|
||||
|
||||
getActiveColumns(list) {
|
||||
return this.allColumns.filter((col) => {
|
||||
if (list.isGrouped && col.widget === "handle") {
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
string="button.string"
|
||||
title="button.title"
|
||||
tabindex="props.list.editedRecord ? '-1' : '0'"
|
||||
onClick="isX2Many and record.isNew ? displaySaveNotification.bind(this) : ''"
|
||||
/>
|
||||
</t>
|
||||
</td>
|
||||
|
||||
@@ -83,6 +83,11 @@ export class ViewButton extends Component {
|
||||
if (this.props.tag === "a") {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
if (this.props.onClick) {
|
||||
return this.props.onClick();
|
||||
}
|
||||
|
||||
this.env.onClickViewButton({
|
||||
clickParams: this.clickParams,
|
||||
getResParams: () =>
|
||||
@@ -144,6 +149,7 @@ ViewButton.props = [
|
||||
"style?",
|
||||
"string?",
|
||||
"slots?",
|
||||
"onClick?",
|
||||
];
|
||||
ViewButton.defaultProps = {
|
||||
tag: "button",
|
||||
|
||||
@@ -13287,4 +13287,34 @@ QUnit.module("Views", (hooks) => {
|
||||
"this is full personalize setting"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"action button in x2many should display a notification if the record is virtual",
|
||||
async (assert) => {
|
||||
const notificationService = makeFakeNotificationService((msg, options) => {
|
||||
assert.step(`${options.type}:${msg}`);
|
||||
});
|
||||
registry.category("services").add("notification", notificationService, { force: true });
|
||||
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="p">
|
||||
<tree editable="bottom">
|
||||
<field name="foo"/>
|
||||
<button class="oe_stat_button" name="test_action" type="object" icon="fa-check">MyButton</button>
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
await click(target.querySelector(".o_field_one2many .o_field_x2many_list_row_add a"));
|
||||
await click(target.querySelector("button.oe_stat_button[name='test_action']"));
|
||||
assert.verifySteps(['danger:Please click on the "save" button first']);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user