Commit 552143d0 by François C.

Miscellious changes to make debug easier

parent e180c8f7
......@@ -456,6 +456,35 @@ class CagetteInventory(models.Model):
return {'missed': missed, 'done': done}
@staticmethod
def general_reset_stock(qty=0):
missed = []
done = []
api = OdooAPI()
# cond = [['active', '=', False], ['qty_available', '!=', 0]]
cond = [['active', '=', True]]
fields = ['uom_id', 'name', 'qty_available']
res = api.search_read('product.product', cond, fields, 100)
if len(res) > 0:
fields = {'company_id': 1, 'name': 'RAZ archivés',
'location_id': settings.STOCK_LOC_ID}
inv = api.create('stock.inventory', fields)
if not (inv is None):
for p in res:
try:
if p['qty_available'] != qty:
fields = {'product_id': p['id'],
'inventory_id': inv,
'product_qty': qty,
'product_uom_id': p['uom_id'][0],
'location_id': settings.STOCK_LOC_ID}
li = api.create('stock.inventory.line', fields)
done.append({'product': p, 'id': li})
except Exception as e:
missed.append({'product': p, 'msg': str(e)})
api.execute('stock.inventory', 'action_done', [inv])
return {'missed': missed, 'done': done}
@staticmethod
def raz_negative_stock():
missed = []
done = []
......
......@@ -16,6 +16,7 @@ urlpatterns = [
url(r'^get_product_categories$', views.get_product_categories),
url(r'^create_inventory$', views.create_inventory),
url(r'^update_odoo_stock$', views.update_odoo_stock),
url(r'^general_reset_stock/?([0-9]*)$', views.general_reset_stock),
url(r'^raz_archived_stock$', views.raz_archived_stock),
url(r'^raz_negative_stock$', views.raz_negative_stock),
url(r'^raz_not_saleable$', views.raz_not_saleable),
......
......@@ -168,6 +168,17 @@ def update_odoo_stock(request):
res['msg'] = 'Forbidden'
return JsonResponse(res)
def general_reset_stock(request, qty):
res = {}
if CagetteUser.are_credentials_ok(request):
try:
res['action'] = CagetteInventory.general_reset_stock(qty)
except Exception as e:
res['msg'] = str(e)
else:
res['msg'] = 'Forbidden'
return JsonResponse(res)
def raz_archived_stock(request):
res = {}
if CagetteUser.are_credentials_ok(request):
......
......@@ -1344,3 +1344,34 @@ class CagetteUser(models.Model):
pass
return answer
@staticmethod
def get_groups(request):
groups = []
if 'authtoken' in request.COOKIES and 'uid' in request.COOKIES:
api = OdooAPI()
cond = [['id', '=', request.COOKIES['uid']]]
fields = ['groups_id']
try:
res = api.search_read('res.users', cond, fields)
if len(res) > 0:
cond = [['id', 'in', res[0]['groups_id']]]
fields = ['full_name']
groups = api.search_read('res.groups', cond, fields)
except:
pass
return groups
@staticmethod
def isAllowedToAdmin(request):
"""Need to create an odoo Group called 'django admin'."""
answer = False
groups = CagetteUser.get_groups(request)
for g in groups:
if g['full_name'] == 'django admin':
answer = True
continue
return answer
......@@ -176,60 +176,72 @@ def home(request):
Consequently, the front-end url should be unknown from the server so the user is redirected to the index,
then the front-end index will call this endpoint to load the home page
"""
template = loader.get_template(getattr(settings, 'MEMBERS_SPACE_HOME_TEMPLATE', 'members_space/home.html'))
coop_can_change_shift_template = getattr(settings, 'COOP_CAN_CHANGE_SHIFT_TEMPLATE', False)
if coop_can_change_shift_template is True:
# make further investigation only if COOP_CAN_CHANGE_SHIFT_TEMPLATE is True
if 'id' in request.COOKIES:
partner_id = request.COOKIES['id']
cs = CagetteShift()
partnerData = cs.get_data_partner(partner_id)
if partnerData['cooperative_state'] == "unsubscribed":
coop_can_change_shift_template = False
if getattr(settings, 'ASSOCIATE_PEOPLE_CAN_CHANGE_SHIFT_TEMPLE_REGISTRATION', False) is False:
if partnerData['is_associated_people'] is True:
if 'id' in request.COOKIES:
partner_id = request.COOKIES['id']
template = loader.get_template(getattr(settings, 'MEMBERS_SPACE_HOME_TEMPLATE', 'members_space/home.html'))
coop_can_change_shift_template = getattr(settings, 'COOP_CAN_CHANGE_SHIFT_TEMPLATE', False)
if coop_can_change_shift_template is True:
# make further investigation only if COOP_CAN_CHANGE_SHIFT_TEMPLATE is True
cs = CagetteShift()
partnerData = cs.get_data_partner(partner_id)
if partnerData['cooperative_state'] == "unsubscribed":
coop_can_change_shift_template = False
context = {
'title': 'Espace Membres',
'coop_can_change_shift_template': coop_can_change_shift_template,
'max_begin_hour': settings.MAX_BEGIN_HOUR,
}
# Get messages to display
msettings = MConfig.get_settings('members')
if 'msg_accueil' in msettings:
context['msg_accueil'] = msettings['msg_accueil']['value']
if 'shop_opening_hours' in msettings:
context['shop_opening_hours'] = msettings['shop_opening_hours']['value']
return HttpResponse(template.render(context, request))
if getattr(settings, 'ASSOCIATE_PEOPLE_CAN_CHANGE_SHIFT_TEMPLE_REGISTRATION', False) is False:
if partnerData['is_associated_people'] is True:
coop_can_change_shift_template = False
context = {
'title': 'Espace Membres',
'coop_can_change_shift_template': coop_can_change_shift_template,
'max_begin_hour': settings.MAX_BEGIN_HOUR,
}
# Get messages to display
msettings = MConfig.get_settings('members')
if 'msg_accueil' in msettings:
context['msg_accueil'] = msettings['msg_accueil']['value']
if 'shop_opening_hours' in msettings:
context['shop_opening_hours'] = msettings['shop_opening_hours']['value']
return HttpResponse(template.render(context, request))
else:
# may occur : found in log
return redirect("../")
def my_info(request):
""" Endpoint the front-end will call to load the "My info" page. """
template = loader.get_template('members_space/my_info.html')
context = {
'title': 'Mes Infos',
'understand_my_status': getattr(settings, 'MEMBERS_SPACE_SHOW_UNDERSTAND_MY_STATUS', True),
'understand_my_status_template': getattr(settings, 'MEMBERS_SPACE_UNDERSTAND_MY_STATUS_TEMPLATE', "members_space/understand_my_status.html")
}
return HttpResponse(template.render(context, request))
if 'id' in request.COOKIES:
template = loader.get_template('members_space/my_info.html')
context = {
'title': 'Mes Infos',
'understand_my_status': getattr(settings, 'MEMBERS_SPACE_SHOW_UNDERSTAND_MY_STATUS', True),
'understand_my_status_template': getattr(settings, 'MEMBERS_SPACE_UNDERSTAND_MY_STATUS_TEMPLATE', "members_space/understand_my_status.html")
}
return HttpResponse(template.render(context, request))
else:
return redirect("../")
def my_shifts(request):
""" Endpoint the front-end will call to load the "My shifts" page. """
template = loader.get_template('members_space/my_shifts.html')
context = {
'title': 'Mes Services',
}
return HttpResponse(template.render(context, request))
if 'id' in request.COOKIES:
template = loader.get_template('members_space/my_shifts.html')
context = {
'title': 'Mes Services',
}
return HttpResponse(template.render(context, request))
else:
return redirect("../")
def shifts_exchange(request):
""" Endpoint the front-end will call to load the "Shifts exchange" page. """
template = loader.get_template(getattr(settings, 'MEMBERS_SPACE_SHIFTS_EXCHANGE_TEMPLATE', 'members_space/shifts_exchange.html'))
m = CagetteMembersSpace()
context = {
'title': 'Échange de Services',
'canAddShift': getattr(settings, 'CAN_ADD_SHIFT', False),
'extension_duration': m.get_extension_duration()
}
return HttpResponse(template.render(context, request))
if 'id' in request.COOKIES:
template = loader.get_template(getattr(settings, 'MEMBERS_SPACE_SHIFTS_EXCHANGE_TEMPLATE', 'members_space/shifts_exchange.html'))
m = CagetteMembersSpace()
context = {
'title': 'Échange de Services',
'canAddShift': getattr(settings, 'CAN_ADD_SHIFT', False),
'extension_duration': m.get_extension_duration()
}
return HttpResponse(template.render(context, request))
else:
return redirect("../")
def faqBDM(request):
template_path = getattr(settings, 'MEMBERS_SPACE_FAQ_TEMPLATE', 'members_space/faq.html')
......
......@@ -156,8 +156,13 @@ def export_one(request, oid):
'Qté', 'Référence', 'code-barre','Prix Unitaire', 'Remise', 'Sous-total'])
for line in order_data['lines']:
taxes += line['price_tax']
if 'supplier_code' in line:
supplier_code = line['supplier_code']
else:
supplier_code = "" # may occur : found in error log
ws1.append([line['product_id'][1], line['product_qty_package'], line['package_qty'],
line['product_qty'], line['supplier_code'], line['barcode'], line['price_unit'], line['discount'], line['price_subtotal']])
line['product_qty'], supplier_code, line['barcode'], line['price_unit'], line['discount'], line['price_subtotal']])
ws1.append([])
ws1.append(['', '', '', '', '', '', '', 'Montant HT', order_data['order']['amount_untaxed'], 'euros'])
ws1.append(['', '', '', '', '', '', '', 'Taxes', taxes, 'euros'])
......
......@@ -25,6 +25,7 @@ from .views import ExportOrders
urlpatterns = [
url('^$', RedirectView.as_view(url='/members/inscriptions/2')),
url(r'^administration/', include('administration.urls')),
url(r'^data/(.*)', views.data),
url(r'^log_js_error$', views.log_js_error),
url(r'^test_compta$', views.test_compta),
......
......@@ -35,7 +35,11 @@ class CagetteStock(models.Model):
@staticmethod
def do_stock_movement(stock_movement_data):
"""Do a stock movement : """
if getattr(settings, 'APP_ENV', 'prod') == 'dev':
coop_logger.info("do_stock_movement : reçu %s %s %s",
"movement type : " + str(stock_movement_data['movement_type']),
"operator : " + str(stock_movement_data['operator']['name']),
"products : " + str(stock_movement_data['products']))
TWOPLACES = Decimal(10) ** -2
api = OdooAPI()
errors = []
......@@ -115,7 +119,8 @@ class CagetteStock(models.Model):
"fresh_record": False
}
])
if getattr(settings, 'APP_ENV', 'prod') == 'dev':
coop_logger.info("fields = %s", str(fields))
# Exception rises when odoo method returns nothing
marshal_none_error = 'cannot marshal None unless allow_none is enabled'
try:
......
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