Hi,
to add a compute field under a model, try this code, for your reference
from odoo import api, fields, models
class YourModel(models.Model):
_name = 'your.model'
field1 = fields.Float(string='Field 1')
field2 = fields.Float(string='Field 2')
computed_field = fields.Float(string='Computed Field', compute='_compute_computed_field', store=True)
@api.depends('field1', 'field2')
def _compute_computed_field(self):
for record in self:
# Your computation logic here
result = record.field1 + record.field2
# Set the value of the computed field
record.computed_field = result
when we apply the 'store=True', that value will be stored in the database, and add the field in the form view or list view of the model you can see the field value, If the field value is not displayed you can use the 'force_save="1"' attribute ude the xml code
xml code here:
<odoo>
<data>
<!-- Tree View -->
<record id="view_your_model_tree" model="ir.ui.view">
<field name="name">your.model.tree</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<tree>
<field name="field1"/>
<field name="field2"/>
<field name="computed_field" force_save="1"/>
</tree>
</field>
</record>
<!-- Form View -->
<record id="view_your_model_form" model="ir.ui.view">
<field name="name">your.model.form</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<form>
<group>
<field name="field1"/>
<field name="field2"/>
<field name="computed_field" readonly="1"/>
</group>
</form>
</field>
</record>
<!-- Menu Action -->
<record id="action_your_model" model="ir.actions.act_window">
<field name="name">Your Model</field>
<field name="res_model">your.model</field>
<field name="view_mode">tree,form</field>
</record>
<!-- Menu Item -->
<menuitem id="menu_your_model" name="Your Model" parent="base.menu_sales" action="action_your_model"/>
</data>
</odoo>
Regards
any hope???
any hope of an Answer?