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)
def open_wizard(self):
return {
res = {
"name": _("Measurement Wizard"),
"res_model": "measuring.wizard",
"type": "ir.actions.act_window",
@@ -54,6 +54,12 @@ class MeasuringDevice(models.Model):
"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):
self.ensure_one()

View File

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