Skip to content

Commit

Permalink
[IMP] stock_barcodes: Performance and extra checks from 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden committed Nov 25, 2024
1 parent 1da71e4 commit 306a399
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
28 changes: 15 additions & 13 deletions stock_barcodes/hooks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Copyright 2021 Tecnativa - Sergio Teruel
# Copyright 2024 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import tools


def pre_init_hook(cr):
if not tools.column_exists(cr, "stock_move_line", "barcode_scan_state"):
cr.execute(
"""
ALTER TABLE stock_move_line
ADD COLUMN barcode_scan_state varchar"""
)
cr.execute(
"""
UPDATE stock_move_line sml
SET barcode_scan_state = 'pending'
"""
)
cr.execute(
"""
ALTER TABLE stock_move_line
ADD COLUMN IF NOT EXISTS barcode_scan_state VARCHAR DEFAULT 'pending';
ALTER TABLE stock_move_line ALTER COLUMN barcode_scan_state DROP DEFAULT;
"""
)
cr.execute(
"""
ALTER TABLE stock_move
ADD COLUMN IF NOT EXISTS barcode_backorder_action VARCHAR DEFAULT 'pending';
ALTER TABLE stock_move ALTER COLUMN barcode_backorder_action DROP DEFAULT;
"""
)
2 changes: 1 addition & 1 deletion stock_barcodes/models/stock_barcodes_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def open_inventory_action(self, ctx):
}
if option_group.get_option_value("location_id", "filled_default"):
vals["location_id"] = (
self.env["stock.warehouse"].search([])[:1].lot_stock_id.id
self.env["stock.warehouse"].search([], limit=1).lot_stock_id.id
)
wiz = self.env["wiz.stock.barcodes.read.inventory"].create(vals)
action = self.env["ir.actions.actions"]._for_xml_id(
Expand Down
3 changes: 1 addition & 2 deletions stock_barcodes/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _prepare_barcode_wiz_vals(self, option_group):
}
if self.picking_type_id.code == "outgoing":
vals["location_dest_id"] = self.location_dest_id.id
if self.picking_type_id.code == "incoming":
elif self.picking_type_id.code == "incoming":
vals["location_id"] = self.location_id.id

if option_group.get_option_value("location_id", "filled_default"):
Expand Down Expand Up @@ -47,7 +47,6 @@ def button_validate(self):
)
if put_in_pack_picks:
put_in_pack_picks.action_put_in_pack()
# Variable initialized as True to optimize break loop
if self.env.context.get("stock_barcodes_validate_picking", False):
res = super(
StockPicking, self.with_context(skip_backorder=True)
Expand Down
9 changes: 4 additions & 5 deletions stock_barcodes/models/stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ def action_barcode_scan(self):
"picking_mode": "picking",
}
if self.code == "outgoing":
location_dest_id = (
vals["location_dest_id"] = (
self.default_location_dest_id.id
or self.env.ref("stock.stock_location_customers").id
)
vals["location_dest_id"] = location_dest_id
if self.code == "incoming":
location_src_id = (
elif self.code == "incoming":
vals["location_id"] = (
self.default_location_src_id.id
or self.env.ref("stock.stock_location_suppliers").id
)
vals["location_id"] = location_src_id
if self.barcode_option_group_id.get_option_value(
"location_id", "filled_default"
):
Expand All @@ -55,6 +53,7 @@ def action_barcode_scan(self):
return action

def action_barcode_new_picking(self):
self.ensure_one()
picking = (
self.env["stock.picking"]
.with_context(default_immediate_transfer=True)
Expand Down

0 comments on commit 306a399

Please sign in to comment.