stock_measuring_device: Retrieve product when device is already assigned

This commit is contained in:
Matthieu Méquignon
2021-04-28 14:34:27 +02:00
committed by Hai Lang
parent 1e1236776e
commit a0ffc17f18
4 changed files with 24 additions and 1 deletions

View File

@@ -40,7 +40,7 @@ class MeasuringDevice(models.Model):
return work_ctx.component(usage=self.device_type) return work_ctx.component(usage=self.device_type)
def open_wizard(self): def open_wizard(self):
return { res = {
"name": _("Measurement Wizard"), "name": _("Measurement Wizard"),
"res_model": "measuring.wizard", "res_model": "measuring.wizard",
"type": "ir.actions.act_window", "type": "ir.actions.act_window",
@@ -54,6 +54,12 @@ class MeasuringDevice(models.Model):
"no_breadcrumbs": True, "no_breadcrumbs": True,
}, },
} }
if self._is_being_used():
pack = self.env["product.packaging"].search(
[("measuring_device_id", "=", self.id)], limit=1
)
res["context"]["default_product_id"] = pack.product_id.id
return res
def _is_being_used(self): def _is_being_used(self):
self.ensure_one() self.ensure_one()

View File

@@ -16,6 +16,7 @@ class ProductPackaging(models.Model):
string="Measuring device which will scan the package", string="Measuring device which will scan the package",
help="Technical field set when an operator uses the device " help="Technical field set when an operator uses the device "
"to scan this package", "to scan this package",
index=True,
) )
def _measuring_device_assign(self, device): def _measuring_device_assign(self, device):

View File

@@ -89,6 +89,7 @@ class MeasuringWizard(models.TransientModel):
"barcode": pack.barcode, "barcode": pack.barcode,
"packaging_id": pack.id, "packaging_id": pack.id,
"packaging_type_id": pack_type.id, "packaging_type_id": pack_type.id,
"scan_requested": bool(pack.measuring_device_id),
} }
) )
vals_list.append(vals) vals_list.append(vals)
@@ -160,6 +161,15 @@ class MeasuringWizard(models.TransientModel):
"flags": {"headless": False, "clear_breadcrumbs": True}, "flags": {"headless": False, "clear_breadcrumbs": True},
} }
def retrieve_product(self):
"""Assigns product that locks the device if a scan is already requested."""
if self.device_id._is_being_used():
pack = self.env["product.packaging"]._measuring_device_find_assigned(
self.device_id
)
self.product_id = pack.product_id
self.onchange_product_id()
def reload(self): def reload(self):
return { return {
"type": "ir.actions.act_view_reload", "type": "ir.actions.act_view_reload",

View File

@@ -37,6 +37,12 @@
string="Refresh" string="Refresh"
icon="fa-refresh" icon="fa-refresh"
/> />
<button
name="retrieve_product"
type="object"
string="Retrieve Product"
icon="fa-search"
/>
</group> </group>
<group name="col2" /> <group name="col2" />
</group> </group>