[FIX] stock: PopoverWidgetField json parsing error without value

Steps to reproduce
==================

- Access a company with no records in transfer model (IT Company, SE Company, etc.)
- Go to transfers menu
- Click Studio
- Click form view button
- Click view tab on the left
- Click Show invisible elements
- Error "The requested change caused an error in the view. It could be because a field was deleted, but still used somewhere else"

Cause of the issue
==================

Since we are not editing an existing record, the PopoverWidgetField
component is loaded without a field value (it is an empty string).

This means that JSON.parse will fail

opw-3249161

closes odoo/odoo#117148

X-original-commit: ddb36467b401ec401b813182d172f5aab329baa7
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
Hubert Van de Walle (huvw)
2023-03-30 15:09:50 +02:00
parent 6718f001b9
commit 15a202c976
@@ -29,7 +29,7 @@ export class PopoverWidgetField extends Component {
this.popover = usePopover();
this.closePopover = null;
let fieldValue = this.props.record.data[this.props.name];
this.jsonValue = JSON.parse(fieldValue);
this.jsonValue = JSON.parse(fieldValue || "{}");
this.color = this.jsonValue.color || 'text-primary';
this.icon = this.jsonValue.icon || 'fa-info-circle';
}