Skip to content

Commit

Permalink
[IMP] shopfloor: product locations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Aug 22, 2023
1 parent 8e6e86c commit 0d339e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions shopfloor/actions/data_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions shopfloor/actions/schema_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d339e8

Please sign in to comment.