Hello mates!
I've got a question related to computed fields on Odoo 12.
My code is something like this:
compute_blue_field1 = fields.Float('Value for BLUE', compute='_compute_method_1')
compute_red_field2 = fields.Float('Value for RED', compute='_compute_method_2')
...
def _compute_method_2(self):
list = self.env['other.model'].search([('product_id', '=, self.id),('color', '=', 'blue')]).mapped('other_id')
self.compute_field1 =calculate_avg(list)
def _compute_method_2(self):
list = self.env['other.model'].search([('product_id', '=, self.id),('color', '=', 'red')]).mapped('other_id')
self.compute_field1 =calculate_avg(list)
The compute method is almost the same, only differs in the bold part, which is a selection of colors ('color', '=', whathever color in the selection field)
So, is there any other way to pass the parameter 'red', 'blue' on the compute field in order to simplify my code? Because i have to do the same for a bunch of different colors. Something like this (but it is not possible):
compute_blue_field1 = fields.Float('Value for BLUE', compute='_compute_method('blue')')
compute_red_field2 = fields.Float('Value for RED', compute='_compute_method('red')')
def _compute_method_2(self, color):
Thank you