Commit e42f5e6f by François C.

Modifications (see PR 175 comments)

parent e501da63
Pipeline #2195 passed with stage
in 1 minute 30 seconds
......@@ -47,6 +47,7 @@ def custom_list_inventory(request, id):
context = {'title': 'Inventaire',
'products' : json.dumps(products['data']),
'ahead_shelfs_ids': json.dumps(getattr(settings, 'SHELFS_TO_BE_AHEAD_IN_SELECT_LIST', []))
}
# Reuse shelf inventory template: same process
......
......@@ -377,6 +377,12 @@
- MEALS_PICKING_TYPE_ID = 10
### Inventory
- SHELFS_TO_BE_AHEAD_IN_SELECT_LIST = [90,74]
These shelfs (odoo ids) will be shown first in select list
### New members space
- USE_NEW_MEMBERS_SPACE = True
......
......@@ -540,10 +540,19 @@ class Shelfs(models.Model):
try:
api = OdooAPI()
res['done'] = []
# First of all, group product by shelf_id to save api server calls
products_shelf = {}
for elt in data:
f = {'shelf_id': elt['shelf_id']}
if api.update('product.product', [elt['product_id']], f):
res['done'].append(elt['product_id'])
if elt['shelf_id'] not in products_shelf:
products_shelf[elt['shelf_id']] = []
products_shelf[elt['shelf_id']].append(int(elt['product_id']))
# iterate on each shelf element to record changes
for shelf_id, product_ids in products_shelf.items():
f = {'shelf_id': shelf_id}
if api.update('product.product', product_ids , f):
res['done'] += product_ids
except Exception as e:
res['error'] = str(e)
coop_logger.error("Rayons, make_products_shelf_links : %s", str(e))
......
......@@ -387,13 +387,39 @@ async function open_change_shelf_modal() {
But, with CSS changes, it could happen that length == 0
*/
const shelfs = await get_all_shelfs();
let shelfs = await get_all_shelfs();
if (shelfs !== null) {
let modal_content = $('#templates #change_shelf_form').clone(),
shelf_selector = $('<select>').addClass('shelf_selection'),
table = modal_content.find('table tbody').empty();
//construct shelfs selector
/* construct shelfs selector */
// first of all, sort by name
shelfs.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
// if ahead_shelfs_ids is not empty, put them ahead
if (ahead_shelfs_ids.length > 0) {
let to_move = {},
idx = 0;
// find index of shelfs to move
shelfs.forEach((shelf) => {
if (ahead_shelfs_ids.indexOf(shelf.id) > -1) {
to_move[shelf.id] = idx;
}
idx += 1;
});
// Respecting ahead_shelfs_ids order, move shelf ahead
// splice can not be used, since more than 1 elt could be involved
let ahead_elts = [];
ahead_shelfs_ids.forEach((shelf_id) => {
let shelf = shelfs[to_move[shelf_id]];
ahead_elts.push(shelf);
});
//remove ahead elts
shelfs = shelfs.filter((item) => {return !ahead_elts.includes(item.id)});
// put them ahead by concatenation
shelfs = ahead_elts.concat(shelfs);
}
shelfs.forEach(
(shelf) => {
let option = $('<option>')
......@@ -401,6 +427,7 @@ async function open_change_shelf_modal() {
.text(shelf.name + ' (' + shelf.sort_order + ')');
shelf_selector.append(option);
});
/* add product rows */
selected_products_for_shelf_change.forEach(
(product) => {
let tr = $('<tr>').attr('data-id',product.id)
......@@ -429,6 +456,13 @@ async function open_change_shelf_modal() {
(product_id) => {
remove_from_toProcess(table_to_process.row($('tr#'+product_id)));
});
let message = "L'opération a bien réussi.";
if (update_result.length !== data.length) {
message = "L'opération a partiellement réussi.\n";
message += (data.length - update_result.length) + " produit(s) non déplacé(s).";
//TODO: display which products changes were in error
}
alert(message);
}
}
make_change();
......
......@@ -47,7 +47,9 @@ def shelf_inventory(request, id):
shelf_products = Shelf(id).get_products()
context = {'title': 'Inventaire du rayon',
'products': json.dumps(shelf_products['data'])}
'products': json.dumps(shelf_products['data']),
'ahead_shelfs_ids': json.dumps(getattr(settings, 'SHELFS_TO_BE_AHEAD_IN_SELECT_LIST', []))
}
template = loader.get_template('shelfs/shelf_inventory.html')
return HttpResponse(template.render(context, request))
......
......@@ -186,7 +186,8 @@
</div>
</div>
<script type="text/javascript">
var products = {{products|safe}}
const ahead_shelfs_ids = {{ahead_shelfs_ids|safe}};
var products = {{products|safe}};
</script>
<script src="{% static "js/all_common.js" %}?v="></script>
<script src="{% static "js/common.js" %}?v="></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment