Commit 26bae4b3 by Damien Moulard

Merge branch 'story_2824' into 'dev_cooperatic'

Add change product shelf function

See merge request !175
parents bc6ab168 e42f5e6f
Pipeline #2196 failed with stage
in 1 minute 28 seconds
...@@ -47,6 +47,7 @@ def custom_list_inventory(request, id): ...@@ -47,6 +47,7 @@ def custom_list_inventory(request, id):
context = {'title': 'Inventaire', context = {'title': 'Inventaire',
'products' : json.dumps(products['data']), '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 # Reuse shelf inventory template: same process
......
...@@ -386,6 +386,12 @@ ...@@ -386,6 +386,12 @@
- MEALS_PICKING_TYPE_ID = 10 - 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 ### New members space
- USE_NEW_MEMBERS_SPACE = True - USE_NEW_MEMBERS_SPACE = True
......
...@@ -528,10 +528,13 @@ class Shelf(models.Model): ...@@ -528,10 +528,13 @@ class Shelf(models.Model):
class Shelfs(models.Model): class Shelfs(models.Model):
def get_all(): def get_all(precision='full'):
res = [] res = []
try: try:
api = OdooAPI() api = OdooAPI()
if precision == 'simple':
res = api.search_read('product.shelfs', [], ['name', 'sort_order'], order='sort_order asc')
else:
res = api.execute('product.shelfs', 'get', {}) res = api.execute('product.shelfs', 'get', {})
except Exception as e: except Exception as e:
coop_logger.error("Rayons, get_all : %s", str(e)) coop_logger.error("Rayons, get_all : %s", str(e))
...@@ -552,3 +555,28 @@ class Shelfs(models.Model): ...@@ -552,3 +555,28 @@ class Shelfs(models.Model):
except Exception as e: except Exception as e:
coop_logger.error("Rayons, get_shelfs_sortorder : %s", str(e)) coop_logger.error("Rayons, get_shelfs_sortorder : %s", str(e))
return res return res
@staticmethod
def make_products_shelf_links(data):
"""Set shelf_id for each product found in data."""
res = {}
try:
api = OdooAPI()
res['done'] = []
# First of all, group product by shelf_id to save api server calls
products_shelf = {}
for elt in data:
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))
return res
\ No newline at end of file
...@@ -147,6 +147,13 @@ table.dataTable { ...@@ -147,6 +147,13 @@ table.dataTable {
padding: 5px; padding: 5px;
} }
#header_container_left {
float: left;
}
#change_shelf_btn {
float: right;
}
div#container_edition { div#container_edition {
padding: 8px; padding: 8px;
background-color: #e7e9ed; background-color: #e7e9ed;
...@@ -296,3 +303,8 @@ hr { ...@@ -296,3 +303,8 @@ hr {
opacity: 1; opacity: 1;
} }
/* Change shelf modal */
.shelf_selection {
max-width: 240px;
}
...@@ -9,8 +9,9 @@ urlpatterns = [ ...@@ -9,8 +9,9 @@ urlpatterns = [
url(r'^shelf_view/([0-9]+)$', views.shelf_view), url(r'^shelf_view/([0-9]+)$', views.shelf_view),
url(r'^shelf_inventory/([0-9]+)$', views.shelf_inventory), url(r'^shelf_inventory/([0-9]+)$', views.shelf_inventory),
url(r'^inventory_process_state/([0-9]+)$', views.inventory_process_state), url(r'^inventory_process_state/([0-9]+)$', views.inventory_process_state),
url(r'^all$', views.all), url(r'^all/?([a-z]*)$', views.all),
url(r'^get_shelves_extra_data$', views.get_shelves_extra_data), url(r'^get_shelves_extra_data$', views.get_shelves_extra_data),
url(r'^change_products_shelfs$', views.change_products_shelfs),
url(r'^(?P<shelf_id>\d+)$', views.shelf_data), url(r'^(?P<shelf_id>\d+)$', views.shelf_data),
url(r'^(?P<shelf_id>\d+)/products$', views.products), url(r'^(?P<shelf_id>\d+)/products$', views.products),
url(r'^(?P<shelf_id>\d+)/add_product$', views.add_product), url(r'^(?P<shelf_id>\d+)/add_product$', views.add_product),
......
...@@ -47,7 +47,9 @@ def shelf_inventory(request, id): ...@@ -47,7 +47,9 @@ def shelf_inventory(request, id):
shelf_products = Shelf(id).get_products() shelf_products = Shelf(id).get_products()
context = {'title': 'Inventaire du rayon', 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') template = loader.get_template('shelfs/shelf_inventory.html')
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
...@@ -79,9 +81,9 @@ def delete_ongoing_inv_data(request, shelf_id): ...@@ -79,9 +81,9 @@ def delete_ongoing_inv_data(request, shelf_id):
else: else:
return JsonResponse({'res': res}) return JsonResponse({'res': res})
def all(request): def all(request, precision):
"""Get all shelves data""" """Get all shelves data"""
return JsonResponse({'res': Shelfs.get_all()}) return JsonResponse({'res': Shelfs.get_all(precision)})
def get_shelves_extra_data(request): def get_shelves_extra_data(request):
"""Get data that need calculation, so long execution time""" """Get data that need calculation, so long execution time"""
...@@ -138,6 +140,19 @@ def inventory_process_state(request, shelf_id): ...@@ -138,6 +140,19 @@ def inventory_process_state(request, shelf_id):
else: else:
return JsonResponse({'res': res}) return JsonResponse({'res': res})
def change_products_shelfs(request):
res = {}
try:
data = json.loads(request.body.decode())
res = Shelfs.make_products_shelf_links(data)
except Exception as e:
res['error'] = str(e)
coop_logger.error("change_products_shelfs : %s", str(e))
if 'error' in res:
return JsonResponse(res, status=500)
else:
return JsonResponse({'res': res})
def do_shelf_inventory(request): def do_shelf_inventory(request):
"""Process shelf inventory""" """Process shelf inventory"""
""" """
......
...@@ -91,6 +91,9 @@ ...@@ -91,6 +91,9 @@
<div class="container_products" id="container_left"> <div class="container_products" id="container_left">
<h4 id="header_container_left">Produits à compter</h4> <h4 id="header_container_left">Produits à compter</h4>
<button style="display:none;" id="change_shelf_btn" class="btn btn--primary">
Changer de rayon
</button>
<table id="table_to_process" class="display" cellspacing="0"></table> <table id="table_to_process" class="display" cellspacing="0"></table>
</div> </div>
<div class="container_products" id="container_right"> <div class="container_products" id="container_right">
...@@ -167,10 +170,24 @@ ...@@ -167,10 +170,24 @@
<input autocomplete="off" type="text" placeholder="Code barre du produit" class="add_product_input"> <input autocomplete="off" type="text" placeholder="Code barre du produit" class="add_product_input">
<hr /> <hr />
</div> </div>
<div id="change_shelf_form">
<h3>Changement de rayons</h3>
<hr />
<table>
<thead>
<tr>
<th>Produit</th>
<th>Rayon</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var products = {{products|safe}} const ahead_shelfs_ids = {{ahead_shelfs_ids|safe}};
var products = {{products|safe}};
</script> </script>
<script src="{% static "js/all_common.js" %}?v="></script> <script src="{% static "js/all_common.js" %}?v="></script>
<script src="{% static "js/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