diff --git a/shopfloor/actions/data_detail.py b/shopfloor/actions/data_detail.py index 2f3bc13bc7..ab1f23d3fc 100644 --- a/shopfloor/actions/data_detail.py +++ b/shopfloor/actions/data_detail.py @@ -66,6 +66,7 @@ def _location_lot_detail_parser(self): return self._lot_parser + [ "removal_date", "expiration_date:expire_date", + ("product_id:product_name", lambda rec, fname: rec.product_id.display_name), ] @ensure_model("stock.picking") @@ -169,6 +170,10 @@ def _product_reserved_qty_subparser(self, rec, field_name): def _product_detail_parser(self): return self._product_parser + [ ("image_128:image", self._product_image_url), + ( + "stock_quant_ids:locations", + lambda record, fname: self._locations_for_product(record), + ), ( "product_tmpl_id:manufacturer", lambda rec, fname: self._jsonify( @@ -177,6 +182,22 @@ def _product_detail_parser(self): ), ] + def _get_product_locations(self, record): + # Retrieve all products -- maybe more than one location + product_template = record.product_tmpl_id + products = product_template.product_variant_ids + quants = self.env["stock.quant"].search( + [("product_id", "in", products.ids), ("location_id.usage", "=", "internal")] + ) + return quants.location_id + + def _locations_for_product(self, record): + res = [] + for location in self._get_product_locations(record): + loc = self.location_detail(location) + res.append(loc) + return res + def _product_image_url(self, record, field_name): if not record[field_name]: return None diff --git a/shopfloor/actions/schema_detail.py b/shopfloor/actions/schema_detail.py index 2d0f812ab1..687ee60f5d 100644 --- a/shopfloor/actions/schema_detail.py +++ b/shopfloor/actions/schema_detail.py @@ -38,6 +38,7 @@ def location_lot(self): "removal_date": {"type": "string", "nullable": True, "required": False}, "expire_date": {"type": "string", "nullable": True, "required": False}, "quantity": {"type": "float", "required": True}, + "product_name": {"type": "string", "required": True}, } ) return schema @@ -98,6 +99,7 @@ def product_detail(self): "image": {"type": "string", "nullable": True, "required": False}, "manufacturer": self._schema_dict_of(self._simple_record()), "suppliers": self._schema_list_of(self.product_supplierinfo()), + "locations": self._schema_list_of(self.location_detail()), } ) return schema