feat(#44): Agregar relación entre análisis y tipos de muestra #45

Merged
luis_portillo merged 9 commits from feature/44-test-sample-relationship into dev 2025-07-15 04:16:03 +00:00
5 changed files with 34 additions and 2 deletions
Showing only changes of commit d240ba5de1 - Show all commits

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from odoo import models, fields
from odoo import models, fields, api
class StockLot(models.Model):
_inherit = 'stock.lot'
@ -26,7 +26,14 @@ class StockLot(models.Model):
('swab', 'Swab'),
('urine', 'Urine Container'),
('other', 'Other')
], string='Container Type')
], string='Container Type (Legacy)', help='Deprecated field, use sample_type_product_id instead')
sample_type_product_id = fields.Many2one(
'product.template',
string='Tipo de Muestra',
domain="[('is_sample_type', '=', True)]",
help="Producto que representa el tipo de contenedor/muestra"
)
collector_id = fields.Many2one(
'res.users',
@ -57,3 +64,28 @@ class StockLot(models.Model):
def action_dispose(self):
self.write({'state': 'disposed'})
@api.onchange('sample_type_product_id')
def _onchange_sample_type_product_id(self):
"""Synchronize container_type when sample_type_product_id changes"""
if self.sample_type_product_id:
# Try to map product name to legacy container type
product_name = self.sample_type_product_id.name.lower()
if 'suero' in product_name or 'serum' in product_name:
self.container_type = 'serum_tube'
elif 'edta' in product_name:
self.container_type = 'edta_tube'
elif 'hisopo' in product_name or 'swab' in product_name:
self.container_type = 'swab'
elif 'orina' in product_name or 'urine' in product_name:
self.container_type = 'urine'
else:
self.container_type = 'other'
def get_container_name(self):
"""Get container name from product or legacy field"""
if self.sample_type_product_id:
return self.sample_type_product_id.name
elif self.container_type:
return dict(self._fields['container_type'].selection).get(self.container_type)
return 'Unknown'