Invoking functions from XML files
You can create all types of records from XML files, but sometimes, it is difficult to generate data that includes some business logic. You might want to modify records when a user installs a dependent module in production. In this case, you can invoke the model
method through the <
function>
tag.
How to do it...
For this tutorial, we will use the code from the previous tutorial. As an example, we will increase the existing room price by $10 USD. Note that you might use another currency based on company configurations.
Follow these steps to invoke the Python method from the XML file:
- Add the
_update_room_price()
method to thehostel.room
model:@api.model def _update_room_price(self): Â Â Â Â all_rooms = self.search([]) Â Â Â Â for room in all_rooms: Â Â Â Â Â Â Â Â room.cost_price += 10
- Add
<function>
to the data XML file:<function model="hostel.room...