I have a function that looks for an id & compares it to another, once this is done it looks for that id in a list, however, I want to get the penultimate record of that list as a result & store it in the objectid_ultimo_costo
Here is the function:
@api.one
@api.depends('seller_ids')
def _costo_anterior(self):
_logger = logging.getLogger(__name__)
if self.default_code or self.default_code !='':
product_search = self.env['product.product'].search([('default_code', '=',self.default_code)],limit = 1)
all_seller_ids = product_search.seller_ids.ids
_logger.info('seller_ids: %s', all_seller_ids)
if all_seller_ids:
id_ultimo_costo = all_seller_ids[1]
supplier = self.env['product.supplierinfo'].search([('id', '=', id_ultimo_costo)])
self.costo_anterior = supplier.price
_logger.info('Costo anterior: %s', self.costo_anterior)
else:
self.costo_anterior = 0.0
Use relative indices: -1 is the last element, -2 is the penultimate, etc.