Skip to content

Commit

Permalink
Merge branch 'inventory-wizard-sort' into opw-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jan 3, 2025
2 parents e7f5db0 + 1edb41d commit 513c4b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
25 changes: 14 additions & 11 deletions product_connect/views/product_inventory_wizard_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@
<sheet>
<group>
<group>
<field name="scan_box" placeholder="Scan or type SKU"/>
<field name="bin" readonly="1" force_save="1"/>
<field name="scan_box" string="Scan Here:" placeholder="Scan or type SKU"/>
<field name="current_bin" string="Current Bin" readonly="1" force_save="1"/>
<field name="bin_needs_update" invisible="1"/>
<field name="count_of_products_not_selected" string="Missing Products"/>
<field name="hide_last_scanned_product" widget="boolean_toggle" class="large-toggle"
string="Hide Last Scanned?"/>
string="Hide Last Scanned Product?"/>
</group>
<group>
<field name="use_available_quantity" widget="boolean_toggle" class="large-toggle"/>
<field name="product_labels_to_print" invisible="use_available_quantity"/>
<field name="use_available_quantity_for_labels" widget="boolean_toggle"
class="large-toggle"/>
<field name="product_labels_to_print" invisible="use_available_quantity_for_labels"/>
<field name="total_product_labels_to_print"/>

</group>
Expand All @@ -56,16 +57,18 @@
<field name="last_scanned_product_name" readonly="1"/>
<field name="last_scanned_product_default_code" readonly="1"/>
<field name="last_scanned_product_bin" readonly="1"
decoration-danger="last_scanned_product_bin != bin"/>
<label for="last_scanned_product_qty"/>
decoration-danger="last_scanned_product_bin != current_bin"/>
<label for="last_scanned_product_qty_available"/>
<div style="display: inline-flex; align-items: center;">
<field name="last_scanned_product_qty" widget="float" options="{'digits': [3,0]}"
<field name="last_scanned_product_qty_available" widget="float"
options="{'digits': [3,0]}"
readonly="1" nolabel="1" style="margin-right: 8px;"/>
<span title="Warning" class="fa fa-exclamation-triangle text-warning"
invisible="last_scanned_product_qty &lt; 2"
invisible="last_scanned_product_qty_available &lt; 2"
style="display: inline-block; position: relative;top: -3px"/>
</div>
<field name="last_scanned_product_scanned_quantity" string="Quantity Scanned" readonly="1"/>
<field name="last_scanned_product_scanned_quantity" string="Quantity Scanned" readonly="1"
decoration-danger="last_scanned_product_qty_available != last_scanned_product_scanned_quantity"/>
<field name="last_scanned_product_template" readonly="1" widget="many2one"
options="{'open_record': true, 'view_type': 'form', 'force_form_view': true}"
context="{'form_view_ref': 'product.product_template_only_form_view'}"/>
Expand All @@ -76,7 +79,7 @@
<field name="is_selected" widget="boolean_toggle" width="50px" class="large-toggle"/>
<field name="default_code"/>
<field name="name"/>
<field name="bin" decoration-danger="bin != parent.bin"/>
<field name="original_bin" decoration-danger="original_bin != parent.current_bin"/>
<field name="qty_available" string="On Hand" widget="float" options="{'digits': [3,0]}"/>
<field name="quantity_scanned" string="Scanned"
decoration-danger="quantity_scanned != qty_available"/>
Expand Down
46 changes: 25 additions & 21 deletions product_connect/wizards/product_inventory_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProductInventoryWizardLine(models.TransientModel):
product = fields.Many2one("product.template")
default_code = fields.Char(related="product.default_code", readonly=True)
name = fields.Char(related="product.name", readonly=True)
bin = fields.Char(related="product.bin", readonly=True)
original_bin = fields.Char(related="product.bin", string="Original Bin", readonly=True)
qty_available = fields.Float(related="product.qty_available", readonly=True)
quantity_scanned = fields.Integer()

Expand All @@ -28,8 +28,8 @@ class ProductInventoryWizard(models.TransientModel):

scan_box = fields.Char(string="Scan", help="Scan or type the SKU/Bin here.")
products = fields.One2many("product.inventory.wizard.line", "wizard")
bin = fields.Char()
use_available_quantity = fields.Boolean(default=True)
current_bin = fields.Char()
use_available_quantity_for_labels = fields.Boolean(default=True, string="Use On Hand Quantity for Labels")

product_labels_to_print = fields.Integer(default=1)
bin_needs_update = fields.Boolean(compute="_compute_bin_needs_update")
Expand All @@ -39,8 +39,8 @@ class ProductInventoryWizard(models.TransientModel):
hide_last_scanned_product = fields.Boolean()
last_scanned_product = fields.Many2one("product.inventory.wizard.line", readonly=True)
last_scanned_product_template = fields.Many2one(related="last_scanned_product.product", readonly=True)
last_scanned_product_qty = fields.Float(related="last_scanned_product.qty_available", readonly=True)
last_scanned_product_bin = fields.Char(related="last_scanned_product.bin", readonly=True)
last_scanned_product_qty_available = fields.Float(related="last_scanned_product.qty_available", readonly=True)
last_scanned_product_bin = fields.Char(related="last_scanned_product.original_bin", readonly=True)
last_scanned_product_name = fields.Char(related="last_scanned_product.name", readonly=True)
last_scanned_product_default_code = fields.Char(related="last_scanned_product.default_code", readonly=True)
last_scanned_product_image = fields.Binary(related="last_scanned_product.product.image_512", readonly=True)
Expand All @@ -53,22 +53,22 @@ def _compute_products_not_selected(self) -> None:
for wizard in self:
wizard.count_of_products_not_selected = len(wizard.products.filtered(lambda p: not p.is_selected))

@api.depends("products", "products.bin", "bin", "products.is_selected")
@api.depends("products", "products.original_bin", "current_bin", "products.is_selected")
def _compute_bin_needs_update(self) -> None:
for wizard in self:
wizard.bin_needs_update = any(p.bin != wizard.bin for p in wizard.products)
wizard.bin_needs_update = any(p.original_bin != wizard.current_bin for p in wizard.products)

@api.depends(
"products",
"products.qty_available",
"use_available_quantity",
"use_available_quantity_for_labels",
"product_labels_to_print",
"products.is_selected",
)
def _compute_total_product_labels_to_print(self) -> None:
for wizard in self:
wizard.total_product_labels_to_print = sum(
p.qty_available if wizard.use_available_quantity else wizard.product_labels_to_print
p.qty_available if wizard.use_available_quantity_for_labels else wizard.product_labels_to_print
for p in wizard.products.filtered("is_selected")
)

Expand Down Expand Up @@ -109,15 +109,15 @@ def _handle_product_scan(self) -> bool:
return True

def _handle_bin_scan(self) -> None:
if self.bin and self.products:
if self.current_bin and self.products:
self.action_apply_bin_changes()
self.bin = self.scan_box.strip().upper()
self.current_bin = self.scan_box.strip().upper()
self._load_bin_products()

def _load_bin_products(self) -> None:
self.products = [(5, 0, 0)]
products_with_bin_and_quantity = self.env["product.template"].search(
[("bin", "=", self.bin), ("qty_available", ">", 0)]
[("bin", "=", self.current_bin), ("qty_available", ">", 0)]
)
self.products = self.env["product.inventory.wizard.line"].create(
[
Expand Down Expand Up @@ -150,15 +150,17 @@ def _onchange_scan_box(self) -> None or "odoo.values.ir_actions_act_window":
self.scan_box = ""

def action_apply_bin_changes(self) -> None:
if not self.bin:
if not self.current_bin:
self.notify_user("No bin selected to apply.", "No bin to apply", "warning")
return

products_to_update = self.products.filtered(lambda p: p.bin != self.bin)
products_to_update = self.products.filtered(lambda p: p.original_bin != self.current_bin)
if products_to_update:
products_to_update.mapped("product").write({"bin": self.bin})
products_to_update.mapped("product").write({"bin": self.current_bin})
self.notify_user(
f"Updated bin location to {self.bin} for {len(products_to_update)} products", "Success", "success"
f"Updated bin location to {self.current_bin} for {len(products_to_update)} products",
"Success",
"success",
)
return
self.notify_user("No products needed bin update.", "No changes", "info")
Expand All @@ -179,7 +181,9 @@ def action_print_product_labels(
},
}
for product in products_to_print:
quantity_to_print = product.qty_available if self.use_available_quantity else self.product_labels_to_print
quantity_to_print = (
product.qty_available if self.use_available_quantity_for_labels else self.product_labels_to_print
)
if quantity_to_print:
product.print_product_labels(quantity_to_print=quantity_to_print)
return {
Expand All @@ -193,7 +197,7 @@ def action_print_product_labels(
}

def action_print_bin_label(self) -> "odoo.values.ir_actions_client":
if not self.bin:
if not self.current_bin:
return {
"type": "ir.actions.client",
"tag": "display_notification",
Expand All @@ -203,16 +207,16 @@ def action_print_bin_label(self) -> "odoo.values.ir_actions_client":
"type": "warning",
},
}
label_data = ["", "Bin: ", self.bin]
label = self.products.product.generate_label_base64(label_data, barcode=self.bin)
label_data = ["", "Bin: ", self.current_bin]
label = self.products.product.generate_label_base64(label_data, barcode=self.current_bin)
self.products.product._print_labels([label], odoo_job_type="product_label", job_name="Bin Label")

return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": "Success",
"message": f"Sent bin label for {self.bin} to printer.",
"message": f"Sent bin label for {self.current_bin} to printer.",
"type": "success",
},
}

0 comments on commit 513c4b3

Please sign in to comment.