Skip to content

Commit

Permalink
[IMP] Custom main menu barcode
Browse files Browse the repository at this point in the history
[IMP] Remove button install the Main Menu barcode

[IMP] Add barcode demo files and barcode operations files

[ADD] Tests

[IMP] Tests

[FIX] Tests

[FIX] Tests

[ADD] Tests

[ADD] Tests

[ADD] Tests

[ADD] Tests

[ADD] Tests

[ADD] Tests

[IMP] Improving success, error and info notifications

[IMP] View inventory adjustment

[IMP] Validate where to direct the return from the Barcode main

[IMP] Validate where to direct the return from the Barcode main

[IMP] View operations adjustment

[IMP] Custom inventory and forms scan views

[IMP] Add barcode main view, improve inventory and forms scan views

[IMP] View inventory adjustment barcode and Operations Barcode

[IMP] View inventory adjustment barcode and Operations Barcode

[IMP] View inventory adjustment barcode and Operations Barcode

[IMP] Show or hide the edit form based on manual option value, scan screen.

[IMP] Display the number of elements according to the context and barcode action

[IMP] Do not allow trailing and leading spaces in the context field in barcode actions

[IMP] Enable validate inventory date

[IMP] Delete label list products scaned
  • Loading branch information
edescalona committed Jan 23, 2025
1 parent 9db3fee commit ddcf9f7
Show file tree
Hide file tree
Showing 35 changed files with 1,551 additions and 535 deletions.
3 changes: 2 additions & 1 deletion stock_barcodes/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"website": "https://github.com/OCA/stock-logistics-barcode",
"license": "AGPL-3",
"category": "Extra Tools",
"depends": ["barcodes", "stock", "web_widget_numeric_step", "web"],
"depends": ["barcodes", "stock", "web_widget_numeric_step", "web", "mail"],
"data": [
"security/ir.model.access.csv",
"views/stock_barcodes_action_view.xml",
Expand All @@ -35,6 +35,7 @@
),
"/stock_barcodes/static/src/views/kanban/stock_barcodes_kanban.xml",
"/stock_barcodes/static/src/widgets/view_button.xml",
"/stock_barcodes/static/src/views/actions/stock_barcode_main_menu.xml",
"/stock_barcodes/static/src/**/*.scss",
],
},
Expand Down
9 changes: 3 additions & 6 deletions stock_barcodes/data/stock_barcodes_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<field name="key_char_shortcut">1</field>
<field
name="context"
>{'search_default_code': 'incoming', 'search_default_barcode_options': 1}
</field>
>{'search_default_code': 'incoming', 'search_default_barcode_options': 1}</field>
</record>
<record id="stock_barcodes_action_picking_int" model="stock.barcodes.action">
<field name="name">Picking INTERNAL</field>
Expand All @@ -18,8 +17,7 @@
<field name="key_char_shortcut">3</field>
<field
name="context"
>{'search_default_code': 'internal', 'search_default_barcode_options': 1}
</field>
>{'search_default_code': 'internal', 'search_default_barcode_options': 1}</field>
</record>
<record id="stock_barcodes_action_picking_out" model="stock.barcodes.action">
<field name="name">Picking OUT</field>
Expand All @@ -28,8 +26,7 @@
<field name="key_char_shortcut">2</field>
<field
name="context"
>{'search_default_code': 'outgoing', 'search_default_barcode_options': 1}
</field>
>{'search_default_code': 'outgoing', 'search_default_barcode_options': 1}</field>
</record>
<!-- Action for inventory based on quants -->
<record id="stock_barcodes_action_inventory" model="stock.barcodes.action">
Expand Down
1 change: 1 addition & 0 deletions stock_barcodes/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import stock_picking
from . import stock_picking_type
from . import stock_quant
from . import barcode_events_mixin
11 changes: 11 additions & 0 deletions stock_barcodes/models/barcode_events_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2019 Sergio Teruel <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


class BarcodesEventsMixin(models.AbstractModel):
_inherit = "barcodes.barcode_events_mixin"

def send_bus_done(self, channel, type_channel, data=None):
self.env["bus.bus"]._sendone(channel, type_channel, data or {})
79 changes: 76 additions & 3 deletions stock_barcodes/models/stock_barcodes_action.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Copyright 2019 Sergio Teruel <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
import re

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.safe_eval import safe_eval

regex = r"^[^\s].*[^\s]$|^$"
FIELDS_NAME = {"barcode_options": "barcode_option_group_id"}


class StockBarcodesAction(models.Model):
_name = "stock.barcodes.action"
Expand All @@ -15,11 +21,76 @@ class StockBarcodesAction(models.Model):
action_window_id = fields.Many2one(
comodel_name="ir.actions.act_window", string="Action window"
)
xml_external_id = fields.Char(related="action_window_id.xml_id")
context = fields.Char()
key_shortcut = fields.Integer()
key_char_shortcut = fields.Char()
icon_class = fields.Char()

count_elements = fields.Integer(default=0, compute="_compute_count_elements")

@api.constrains("context")
def _constrains_context(self):
if self.context and not bool(re.match(regex, self.context)):
raise ValidationError(_("There can be no spaces at the beginning or end."))

def _count_elements(self):
domain = []
if self.context:
context_values = self.context.strip("{}").split(",")

def _map_context_values(x):
field_values = x.split(":")
field_name = field_values[0].split("search_default_")
if len(field_name) > 1:
field_name = field_name[1].strip("'")
field_value_format = field_values[1].replace("'", "").strip()
field_value = (
int(field_value_format)
if field_value_format.isdigit()
else field_value_format
)
if hasattr(
self.action_window_id.res_model,
FIELDS_NAME.get(field_name, field_name),
):
return (

Check warning on line 57 in stock_barcodes/models/stock_barcodes_action.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_barcodes_action.py#L57

Added line #L57 was not covered by tests
f"{FIELDS_NAME.get(field_name, field_name)}",
"=",
field_value,
)
else:
return False
else:
return ()

domain = [
val_domain
for val_domain in list(
map(lambda x: _map_context_values(x), context_values)
)
]
search_count = (
list(filter(lambda x: x, domain))
if all(val_d is True for val_d in domain)
else []
)
return (
self.env[self.action_window_id.res_model].search_count(search_count)
if self.action_window_id.res_model
else 0
)
return 0

@api.depends("context")
def _compute_count_elements(self):
for barcode_action in self:
barcode_action.count_elements = (
barcode_action._count_elements()
if "search_default_" in barcode_action.context
else 0
)

def open_action(self):
action = self.action_window_id.sudo().read()[0]
action_context = safe_eval(action["context"])
Expand All @@ -29,8 +100,10 @@ def open_action(self):
if self.context:
ctx.update(safe_eval(self.context))
if action_context.get("inventory_mode", False):
return self.open_inventory_action(ctx)
action["context"] = ctx
action = self.open_inventory_action(ctx)

Check warning on line 103 in stock_barcodes/models/stock_barcodes_action.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_barcodes_action.py#L103

Added line #L103 was not covered by tests
else:
action["context"] = ctx

Check warning on line 105 in stock_barcodes/models/stock_barcodes_action.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_barcodes_action.py#L105

Added line #L105 was not covered by tests

return action

def open_inventory_action(self, ctx):
Expand Down
13 changes: 12 additions & 1 deletion stock_barcodes/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ def button_validate(self):
StockPicking, self.with_context(skip_backorder=True)
).button_validate()
else:
pickings_to_backorder = self._check_backorder()

Check warning on line 55 in stock_barcodes/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_picking.py#L55

Added line #L55 was not covered by tests
if pickings_to_backorder:
return pickings_to_backorder._action_generate_backorder_wizard(

Check warning on line 57 in stock_barcodes/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_picking.py#L57

Added line #L57 was not covered by tests
show_transfers=self._should_show_transfers()
)
res = super().button_validate()
if res is True and self.env.context.get("show_picking_type_action_tree", False):
return self[:1].picking_type_id.get_action_picking_tree_ready()
res = self[:1].picking_type_id.get_action_picking_tree_ready()

if self.state == "done":
self.env["bus.bus"]._sendone(
"stock_barcodes_scan", "actions_barcode", {"valid_picking": True}
)

Check warning on line 67 in stock_barcodes/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_picking.py#L65-L67

Added lines #L65 - L67 were not covered by tests

return res
52 changes: 51 additions & 1 deletion stock_barcodes/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models

MODEL_UPDATE_INVENTORY = ["wiz.stock.barcodes.read.inventory"]


class StockQuant(models.Model):
_inherit = "stock.quant"
_name = "stock.quant"
_inherit = ["stock.quant", "barcodes.barcode_events_mixin"]

def action_barcode_inventory_quant_unlink(self):
self.with_context(inventory_mode=True).action_set_inventory_quantity_to_zero()
context = dict(self.env.context)
params = context.get("params", {})
res_model = params.get("model", False)
res_id = params.get("id", False)
if res_id and res_model in MODEL_UPDATE_INVENTORY:
wiz_id = self.env[params["model"]].browse(params["id"])
wiz_id._compute_count_inventory_quants()
wiz_id.send_bus_done(
"stock_barcodes_form_update",
"count_apply_inventory",
{"count": wiz_id.count_inventory_quants},
)

def _get_fields_to_edit(self):
return [
Expand All @@ -28,3 +43,38 @@ def action_barcode_inventory_quant_edit(self):
for fname in self._get_fields_to_edit():
wiz_barcode[fname] = quant[fname]
wiz_barcode.product_qty = quant.inventory_quantity

wiz_barcode.manual_entry = True
self.send_bus_done(
"stock_barcodes_scan",
"stock_barcodes_edit_manual",
{
"manual_entry": True,
},
)

def enable_current_operations(self):
self.send_bus_done(
"stock_barcodes_kanban_update",
"enable_operations",
{
"id": self.id,
},
)

def operation_quantities_rest(self):
self.write({"inventory_quantity": self.inventory_quantity - 1})
self.enable_current_operations()

def operation_quantities(self):
self.write({"inventory_quantity": self.inventory_quantity + 1})
self.enable_current_operations()

Check warning on line 71 in stock_barcodes/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_quant.py#L70-L71

Added lines #L70 - L71 were not covered by tests

def action_apply_inventory(self):
res = super().action_apply_inventory()
self.send_bus_done(

Check warning on line 75 in stock_barcodes/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_quant.py#L74-L75

Added lines #L74 - L75 were not covered by tests
"stock_barcodes_scan",
"actions_barcode",
{"apply_inventory": True},
)
return res

Check warning on line 80 in stock_barcodes/models/stock_quant.py

View check run for this annotation

Codecov / codecov/patch

stock_barcodes/models/stock_quant.py#L80

Added line #L80 was not covered by tests
Binary file not shown.
Binary file added stock_barcodes/static/src/docs/barcodes_demo.pdf
Binary file not shown.
105 changes: 93 additions & 12 deletions stock_barcodes/static/src/scss/barcode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,109 @@ div.o_kanban_stock_barcodes {

div.alert.barcode-info {
background-color: $o-community-color !important;

span.fa-barcode {
margin: 0.5rem 1rem 0 1rem !important;

@include media-breakpoint-down(sm) {
margin: 0 0 0 5px !important;
font-size: 1em !important;
}
}
}

div[name="inventory_quant_ids"] {
div.o_kanban_record {
box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px !important;
.inventory_quant_ids_with_form {
height: 710px !important;
@include media-breakpoint-down(sm) {
height: 500px !important;
}
}

.inventory_quant_ids_without_form {
height: 822px !important;
@include media-breakpoint-down(sm) {
height: 648px !important;
}
}

div.oe_kanban_picking_done {
background-color: #353840 !important;
border: none !important;
box-shadow: none !important;
height: 230px !important;
}

div[name="inventory_quant_ids"],
div[name="pending_move_ids"],
div[name="move_line_ids"] {
div.o_kanban_renderer {
padding: 0 !important;

&:has(div.oe_kanban_picking_done) {
height: 50% !important;
}

div.o_kanban_record {
box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px !important;

i.fa-pencil,
i.fa-trash {
font-size: 3.5em !important;
}

img,
span.text-end.fw-bold {
margin-right: 5% !important;
}

i.fa-pencil,
i.fa-recycle {
font-size: 2.5em !important;
div.indent {
text-indent: 5px !important;
}
}

img,
span.text-end.fw-bold {
margin-right: 5% !important;
button.btn-op-rest,
button.btn-op-sum {
background-color: $o-community-color !important;
min-width: 55px !important;
height: 60px !important;
padding: 12px 8px !important;
border-radius: 8px !important;
line-height: 16px !important;
font-size: 16px !important;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-transform: none;
}
}
}

button[name="action_clean_product"] {
button[name="action_clean_product"],
button[name="action_clean_lot"],
button#btn_create_lot {
width: 5% !important;
padding: 0.9rem !important;
@include media-breakpoint-down(sm) {
width: 50% !important;
margin: 5px !important;
width: 95% !important;
margin-top: 0.5em !important;
padding: 0.3rem !important;
i.o_button_icon {
font-size: 1.5em !important;
}
}
}

div.stock_barcodes_action_kanban {
div.o_kanban_record {
div.oe_kanban_content {
padding: 1.5rem 1.5rem 1.5rem 0.5rem !important;

div.count-elements {
border: 1px solid;
padding: 1px 4px 1px 4px !important;
border-radius: 40% !important;
background-color: lightgray !important;
}
}
}
}
Loading

0 comments on commit ddcf9f7

Please sign in to comment.