| 1 |
import { patch } from "@web/core/utils/patch"; |
| 2 |
import { SaleOrderLineProductField } from "@sale/js/sale_product_field"; |
| 3 |
import { useService } from "@web/core/utils/hooks"; |
| 4 |
|
| 5 |
patch(SaleOrderLineProductField.prototype, { |
| 6 |
setup() { |
| 7 |
super.setup(); |
| 8 |
this.action = useService("action"); |
| 9 |
}, |
| 10 |
get isEvent() { |
| 11 |
return this.props.record.data.service_tracking === "event"; |
| 12 |
}, |
| 13 |
get hasConfigurationButton() { |
| 14 |
return super.hasConfigurationButton || this.isEvent; |
| 15 |
}, |
| 16 |
onEditConfiguration() { |
| 17 |
if (this.isEvent) { |
| 18 |
this._openEventConfigurator(); |
| 19 |
} else { |
| 20 |
super.onEditConfiguration(); |
| 21 |
} |
| 22 |
}, |
| 23 |
_onProductUpdate() { |
| 24 |
if (this.isEvent) { |
| 25 |
this._openEventConfigurator(); |
| 26 |
} else { |
| 27 |
super._onProductUpdate(); |
| 28 |
} |
| 29 |
}, |
| 30 |
async _openEventConfigurator() { |
| 31 |
const actionContext = { |
| 32 |
default_product_id: this.props.record.data.product_id.id, |
| 33 |
}; |
| 34 |
if (this.props.record.data.event_id) { |
| 35 |
actionContext.default_event_id = this.props.record.data.event_id.id; |
| 36 |
} |
| 37 |
if (this.props.record.data.event_slot_id) { |
| 38 |
actionContext.default_event_slot_id = this.props.record.data.event_slot_id[0]; |
| 39 |
} |
| 40 |
if (this.props.record.data.event_ticket_id) { |
| 41 |
actionContext.default_event_ticket_id = this.props.record.data.event_ticket_id.id; |
| 42 |
} |
| 43 |
this.action.doAction( |
| 44 |
'event_sale.event_configurator_action', |
| 45 |
{ |
| 46 |
additionalContext: actionContext, |
| 47 |
onClose: async (closeInfo) => { |
| 48 |
if (!closeInfo?.eventConfiguration || closeInfo.special || closeInfo.dismiss) { |
| 49 |
|
| 50 |
if (!this.props.record.data.event_ticket_id) { |
| 51 |
|
| 52 |
this.props.record.update({ |
| 53 |
[this.props.name]: undefined, |
| 54 |
}); |
| 55 |
} |
| 56 |
} else { |
| 57 |
const eventConfiguration = closeInfo.eventConfiguration; |
| 58 |
this.props.record.update(eventConfiguration); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
); |
| 63 |
}, |
| 64 |
}); |