Skip to Content
Menu
This question has been flagged
1 Reply
3857 Views

Due an elaboration reason, I should create a field that store values for each record compared with other values of the same kind (odoo v8).

So as result I should have something as a table:

The record are A1, A2, A3, ...


The values: 

           A1 A2 A3

 A1 1 5 9

A2 1/5 1 7

A3 1/9 1/7 1 


How should I structure the ORM to store this kind of data?


May be i could just create a function that reads all the values store in ORM (A1 A2 A3) and then allows the user to input the confrontation values (1, 5, 9,7, ....).

Avatar
Discard
Best Answer

you can use a Many2many field to create a relational table structure. Here's how you can structure the ORM to achieve this:

  1. Define a new model: Create a new model to represent your records. This model will have a Many2many field to store the comparison values.

class MyModel(models.Model):
_name = 'my.model'

name = fields.Char('Name')
comparison_values = fields.Many2many('my.model', 'comparison_table', 'record_id', 'compared_record_id', 'Comparison Values')

Create a relational table: Define a separate model to act as the relational table that will store the comparison values between records.

class ComparisonTable(models.Model):
_name = 'comparison.table'

record_id = fields.Many2one('my.model', 'Record')
compared_record_id = fields.Many2one('my.model', 'Compared Record')
value = fields.Float('Value')

n this example, comparison_values is a Many2many field in the my.model model, and it refers to the comparison.table model. This creates a separate table to store the comparison values between records.

  1. Usage and data entry: To store the comparison values, you can create a form view for the my.model model where users can input the comparison values for each record. You can use Odoo's form view and widgets to present and capture the data.

  2. Data retrieval: To retrieve the comparison values for a specific record, you can use Odoo's ORM methods to query the comparison.table model and retrieve the corresponding values.


record = self.env['my.model'].browse(record_id)
comparison_values = record.comparison_values

This will return the comparison values for the specified record.

Remember to update the module's XML files to include the necessary views and fields.

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 19
98
1
Jul 17
4178
4
Aug 16
8402
1
May 16
4985
1
Mar 16
5014