diff --git a/lims_management/models/__pycache__/__init__.cpython-312.pyc b/lims_management/models/__pycache__/__init__.cpython-312.pyc index 03e4810..c0fed3a 100644 Binary files a/lims_management/models/__pycache__/__init__.cpython-312.pyc and b/lims_management/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/lims_management/models/__pycache__/product.cpython-312.pyc b/lims_management/models/__pycache__/product.cpython-312.pyc index 15c2049..945c75b 100644 Binary files a/lims_management/models/__pycache__/product.cpython-312.pyc and b/lims_management/models/__pycache__/product.cpython-312.pyc differ diff --git a/lims_management/models/__pycache__/sale_order.cpython-312.pyc b/lims_management/models/__pycache__/sale_order.cpython-312.pyc index 82b79cf..deaa781 100644 Binary files a/lims_management/models/__pycache__/sale_order.cpython-312.pyc and b/lims_management/models/__pycache__/sale_order.cpython-312.pyc differ diff --git a/lims_management/models/__pycache__/stock_lot.cpython-312.pyc b/lims_management/models/__pycache__/stock_lot.cpython-312.pyc index 3c5a0bb..35ea7ee 100644 Binary files a/lims_management/models/__pycache__/stock_lot.cpython-312.pyc and b/lims_management/models/__pycache__/stock_lot.cpython-312.pyc differ diff --git a/lims_management/models/stock_lot.py b/lims_management/models/stock_lot.py index 5bbc29d..e24cbf6 100644 --- a/lims_management/models/stock_lot.py +++ b/lims_management/models/stock_lot.py @@ -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'