How can I add custom fields that calculate a combination of other fields? Like Sales Margin as a percentage? Without a module.
I know I can write code and create a module to add custom fields to Odoo.
I also know that custom fields can be added via the User Interface easily. Is it possible to create a new field that gets it value automatically (by a calculation) from another set of fields?
1. Enable the option to show Margins on Sales Orders:
Sales --> Configuration --> Settings
2. Add the field via the User Interface:
Settings --> Technical --> Database Structure --> Fields
The code for the Compute section is:
for record in self: if record['amount_total'] > 0:
record['x_margin_percentage'] = record['margin'] / record['amount_total']
3. Add the field to the User Interface, by creating a view that inherits and overrides the Odoo Sales Order Form view that adds the margin field:
Settings --> Technical --> User Interface --> Views
The XML for the Architecture field is:
<field name="margin" position="after">
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!
About This Community
|Asked: 9/17/16, 8:04 PM|
|Seen: 499 times|
|Last updated: 10/10/16, 9:06 AM|