Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] shopflor/mobile/_packing: Allows to select package types for packing #25

Draft
wants to merge 4 commits into
base: 16.0-shopfloor_packing-sbj
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 256 additions & 0 deletions shopfloor_mobile_packing/static/src/js/cluster-picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,64 @@ ClusterPickingBase.component.template = template.replace(
v-if="state_is('pack_picking_put_in_pack')"
:record="state.data"
/>
<div v-if="state_is('select_package')">
<v-alert type="info" tile v-if="state.data.packing_info" class="packing-info">
<p v-text="state.data.packing_info" />
</v-alert>
<item-detail-card
v-if="state.data.picking.carrier"
:key="make_state_component_key(['picking-carrier', state.data.picking.id])"
:record="state.data.picking.carrier"
:options="{main: true, key_title: 'name', title_icon: 'mdi-truck-outline'}"
/>
<detail-picking-select
:record="state.data.picking"
:select_records="state.data.selected_move_lines"
:select_options="select_package_manual_select_opts()"
:key="make_state_component_key(['detail-picking-select'])"
/>
<div class="button-list button-vertical-list full">
<!-- TODO:<v-row align="center" v-if="state.data.package_allowed">
<v-col class="text-center" cols="12">
<btn-action
@click="state.on_existing_pack"
:disabled="_.isEmpty(selected_lines())"
>Existing pack</btn-action>
</v-col>
</v-row>-->
<v-row align="center" v-if="state.data.package_allowed">
<v-col class="text-center" cols="12">
<btn-action
@click="state.on_new_pack"
:disabled="_.isEmpty(selected_lines())"
>New pack</btn-action>
</v-col>
</v-row>
<v-row align="center" v-if="state.data.no_package_enabled">
<v-col class="text-center" cols="12">
<btn-action
@click="state.on_without_pack"
:disabled="_.isEmpty(selected_lines())"
>Process w/o pack</btn-action>
</v-col>
</v-row>
</div>
</div>
<div v-if="state_is('select_delivery_packaging')">

<manual-select
:records="state.data.packaging"
:options="select_delivery_packaging_manual_select_options()"
:key="make_state_component_key(['cluster_picking', 'select-delivery-packaging'])"
/>
<div class="button-list button-vertical-list full">
<v-row align="center">
<v-col class="text-center" cols="12">
<btn-back />
</v-col>
</v-row>
</div>
</div>
</Screen>
`
);
Expand All @@ -34,6 +92,50 @@ ClusterPickingBase.component.computed.searchbar_input_type = function () {
return "text";
};

ClusterPickingBase.component.computed.existing_package_select_fields = function () {
return [
{path: "weight"},
{path: "move_line_count", label: "Line count"},
{path: "packaging.name"},
];
};

ClusterPickingBase.component.methods.select_package_manual_select_opts = function () {
return {
multiple: true,
initValue: this.selected_line_ids(),
card_klass: "loud-labels",
list_item_component: "picking-select-package-content",
list_item_options: {actions: ["action_qty_edit"]},
};
};

ClusterPickingBase.component.methods.select_delivery_packaging_manual_select_options =
function () {
return {
showActions: false,
};
};

ClusterPickingBase.component.methods.selected_line_ids = function () {
return this.selected_lines().map(_.property("id"));
};

ClusterPickingBase.component.methods.selectable_lines = function () {
const stored = this.state_get_data("select_package");
return _.result(stored, "selected_move_lines", []);
};

ClusterPickingBase.component.methods.selectable_line_ids = function () {
return this.selectable_lines().map(_.property("id"));
};

ClusterPickingBase.component.methods.selected_lines = function () {
return this.selectable_lines().filter(function (x) {
return x.qty_done > 0;
});
};

// Replace the data method with our new method to add
// our new state
let component = ClusterPickingBase.component;
Expand Down Expand Up @@ -80,6 +182,160 @@ let data = function () {
this.wait_call(this.odoo.call(endpoint, endpoint_data));
},
};
result.states.select_package = {
// TODO: /set_line_qty is not handled yet
// because is not clear how to handle line selection
// and qty set.
// ATM given that manual-select uses v-list-item-group
// when you touch a line you select/unselect it
// which means we cannot rely on this to go to edit.
// If we need it, we have to change manual-select
// to use pure list + checkboxes.
display_info: {
title: "Select package",
scan_placeholder: "Scan existing package / package type",
},
events: {
qty_edit: "on_qty_edit",
select: "on_select",
back: "on_back",
},
on_scan: (scanned) => {
this.wait_call(
this.odoo.call("scan_package_action", {
picking_id: this.state.data.picking.id,
selected_line_ids: this.selectable_line_ids(),
barcode: scanned.text,
})
);
},
on_select: (selected) => {
return;
// TODO:
// if (!selected) {
// return;
// }
// const orig_selected = $instance.selected_line_ids();
// const selected_ids = selected.map(_.property("id"));
// const to_select = _.head(
// $instance.selectable_lines().filter(function (x) {
// return selected_ids.includes(x.id) && !orig_selected.includes(x.id);
// })
// );
// const to_unselect = _.head(
// $instance.selectable_lines().filter(function (x) {
// return !selected_ids.includes(x.id) && orig_selected.includes(x.id);
// })
// );
// let endpoint, move_line;
// if (to_unselect) {
// endpoint = "reset_line_qty";
// move_line = to_unselect;
// } else if (to_select) {
// endpoint = "set_line_qty";
// move_line = to_select;
// }
// $instance.wait_call(
// $instance.odoo.call(endpoint, {
// picking_id: $instance.state.data.picking.id,
// selected_line_ids: $instance.selectable_line_ids(),
// move_line_id: move_line.id,
// })
// );
},
on_qty_edit: (record) => {
return;
// TODO:
// $instance.state_set_data(
// {
// picking: $instance.state.data.picking,
// line: record,
// selected_line_ids: $instance.selectable_line_ids(),
// },
// "change_quantity"
// );
// $instance.state_to("change_quantity");
},
on_new_pack: () => {
/**
* Trigger the call to list delivery packaging types
* as user wants to put porducts in a new pack.
*/
let endpoint, endpoint_data;
const data = this.state.data;
endpoint = "list_delivery_packaging";
endpoint_data = {
picking_batch_id: this.current_batch().id,
picking_id: data.picking.id,
selected_line_ids: this.selectable_line_ids(),
};
this.wait_call(this.odoo.call(endpoint, endpoint_data));
},
on_existing_pack: () => {
return;
// TODO:
// $instance.wait_call(
// $instance.odoo.call("list_dest_package", {
// picking_id: $instance.state.data.picking.id,
// selected_line_ids: $instance.selectable_line_ids(),
// })
// );
},
on_without_pack: () => {
return;
// TODO:
// $instance.wait_call(
// $instance.odoo.call("no_package", {
// picking_id: $instance.state.data.picking.id,
// selected_line_ids: $instance.selectable_line_ids(),
// })
// );
},
on_back: () => {
$instance.state_to("select_line");
$instance.reset_notification();
},
};
result.states.select_delivery_packaging = {
/**
* This will catch user events when selecting the delivery packaging type
* from:
* - the scanned barcode
* - the direct selection on screen
*/
display_info: {
title: "Select delivery packaging or scan it",
scan_placeholder: "Scan package type",
},
events: {
select: "on_select",
back: "on_back",
},
on_select: (selected) => {
const picking = this.current_doc().record;
const data = this.state.data.picking;
this.wait_call(
this.odoo.call("put_in_pack", {
picking_batch_id: this.current_batch().id,
picking_id: data.id,
selected_line_ids: this.selected_line_ids(),
package_type_id: selected.id,
})
);
},
on_scan: (scanned) => {
const picking = this.current_doc().record;
const data = this.state.data;
this.wait_call(
this.odoo.call("scan_package_action", {
picking_id: data.id,
selected_line_ids: this.selected_line_ids(),
barcode: scanned.text,
})
);
},
};

return result;
};

Expand Down
1 change: 1 addition & 0 deletions shopfloor_packing/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"shopfloor",
"internal_stock_quant_package",
"delivery_package_type_number_parcels",
"stock_picking_delivery_package_type_domain",
],
"data": ["views/shopfloor_menu.xml", "views/stock_picking.xml"],
"installable": True,
Expand Down
18 changes: 18 additions & 0 deletions shopfloor_packing/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ def _package_parser(self):
res = super()._package_parser
res.append("is_internal")
return res

def _data_for_packing_info(self, picking):
"""Return the packing information

Intended to be extended.
"""
# TODO: This could be avoided if included in the picking parser.
return ""

def select_package(self, picking, lines):
return {
"selected_move_lines": self.move_lines(lines.sorted()),
"picking": self.picking(picking),
"packing_info": self._data_for_packing_info(picking),
# "no_package_enabled": not self.options.get("checkout__disable_no_package"),
# Used by inheriting module
"package_allowed": True,
}
25 changes: 25 additions & 0 deletions shopfloor_packing/actions/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,28 @@ def package(self, with_packaging=False):
schema = super().package(with_packaging=with_packaging)
schema["is_internal"] = {"required": False, "type": "boolean"}
return schema

def select_package(self) -> dict:
"""
This will return the schema expected to display the action to select the
package to put in.
"""
schema = {
"selected_move_lines": {
"type": "list",
"schema": self._schema_dict_of(self.move_line()),
},
"picking": self._schema_dict_of(self.picking()),
"packing_info": {"type": "string", "nullable": True},
"no_package_enabled": {
"type": "boolean",
"nullable": True,
"required": False,
},
"package_allowed": {
"type": "boolean",
"nullable": True,
"required": False,
},
}
return schema
8 changes: 8 additions & 0 deletions shopfloor_packing/models/shopfloor_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ class ShopfloorMenu(models.Model):
help="If you tick this box, all the picked item will be put in pack"
" before the transfer.",
)

default_pack_pickings_action = fields.Selection(
[
("nbr_packages", "Enter the number of packages"),
("package_type", "Scan the package type"),
],
default="nbr_packages",
)
2 changes: 1 addition & 1 deletion shopfloor_packing/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import cluster_picking
from . import cluster_picking, packaging
Loading
Loading