When and why would I use `@api.returns` in my code? Trying to understand its purpose better. Thanks!
Welcome!
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
This question has been flagged
Here's how you can use the `@api.returns` decorator to handle different output styles for your methods. This example demonstrates its use with a custom model's `copy` method. The '@api.returns' decorator for methods that return instances of a specified model. It takes three parameters: 'model', which is the name of the model or 'self' for the current model; 'downgrade', a function that converts record-style output to traditional output; and 'upgrade', a function that converts traditional output to record-style output. The decorator adjusts the method output based on the call style, allowing it to return an ID, a list of IDs, or a recordset. class CustomModel(models.Model): _name = 'custom.model' @api.returns('self') def copy(self, default=None): # Custom logic for copying a record return super(CustomModel, self).copy(default)