Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
8 Views

Hey Cyllo users, what's the best way to automatically update fields based on changes in other fields? Any tips or tricks?

Avatar
Discard

Here's how you can achieve that using the '@api.onchange' decorator. Onchange fields dynamically update values in the form view when a specified field changes, without needing to save the record. These changes affect the user interface but are not persisted to the database until the record is saved. class SaleOrderLine(models.Model): _inherit = 'sale.order.line' discount_reason = fields.Char(string='Discount Reason') @api.onchange('discount') def _onchange_discount(self): if self.discount > 20: self.discount_reason = "High discount – approval required" else: self.discount_reason = ""

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!