diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc index c0b82294..55c1f304 100644 Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ diff --git a/app.log b/app.log index d730f558..40115f3a 100644 --- a/app.log +++ b/app.log @@ -1,56 +1,51 @@ -Server Error: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. -Request: 127.0.0.1 GET http /login_callback?code=JMmHntUooZqn-PHB_xXhxkzf0lBMA6CcFQC1whmN23xUb&state=%2F Host: 127.0.0.1:5000 -Connection: keep-alive -Pragma: no-cache -Cache-Control: no-cache -Dnt: 1 -Upgrade-Insecure-Requests: 1 -User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 -Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 -Sec-Fetch-Site: cross-site -Sec-Fetch-Mode: navigate -Sec-Fetch-User: ?1 -Sec-Fetch-Dest: document -Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128" -Sec-Ch-Ua-Mobile: ?0 -Sec-Ch-Ua-Platform: "Windows" -Accept-Encoding: gzip, deflate, br, zstd -Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 -Cookie: session=.eJxtkG1rwjAQx79LwL7R9SG2aVooww2cCJvMMX1ZYnq10ZrUND5M2XdfKmNsMHLhwt3_cj_-V5S3hhnI2cFUfu6h9IoKZliXpZIcUIoeJrMZDquFv6mO7-PqeCrDCA2QhkJo4CY_aGFVlTFN6nkBjl3fniCNfN_3arUWMuesrleMb-3UQdff4taqCzjeyRPbYp8QKElFxVm6h9a90bhc7bzupbS4wL2GtlGyhdx8NJBxVYDDawHS5KLI1k-bD7N_eV4-Vm_ivJ_FeP56WUyWIwbT6WUunN-0Wbe-Nxz18NjGD7GtdMy29JfaabmyG-2Voug3WpWihj7smKidm3mZHXFubmX_evU5QHBuUBrEmETJMKSBGyUUUxLaDm91mRu1BWl9CUpK4pWPCcEkLjEDUuAoSRJKOUkIJauSch7E9ssvTeiOWA.ZumruQ.WqTz2NgZC14EQFnfvllT6CC2T3U - - -Request data: b'' -Traceback: Traceback (most recent call last): - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\user.py", line 91, in login_callback - users, errors = datastore_user.get_many_user(user_filters, user) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\datastores\datastore_user.py", line 134, in get_many_user - guid = Helper_DB_MySQL.create_guid() - ^^^^^^^^^^^^^^^ -NameError: name 'Helper_DB_MySQL' is not defined - -During handling of the above exception, another exception occurred: - -Traceback (most recent call last): - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app - response = self.full_dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request - rv = self.handle_user_exception(e) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function - return cors_after_request(app.make_response(f(*args, **kwargs))) - ^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request - rv = self.dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request - return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\user.py", line 120, in login_callback - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Controller error.\n{e}'}) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\_internal\_model_construction.py", line 237, in __getattr__ - raise AttributeError(item) -AttributeError: STATUS_FAILURE - +Traceback: Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\controllers\store\product_category.py", line 57, in categories + return render_template('pages/store/_product_categories.html', model = model) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\templating.py", line 150, in render_template + return _render(app, template, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\templating.py", line 131, in _render + rv = template.render(context) + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\jinja2\environment.py", line 1304, in render + self.environment.handle_exception() + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\jinja2\environment.py", line 939, in handle_exception + raise rewrite_traceback_stack(source=source) + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\pages\store\_product_categories.html", line 1, in top-level template code + {% extends 'layouts/layout.html' %} + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\layouts\layout.html", line 316, in top-level template code + {% block page_body %}{% endblock %} + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\pages\store\_product_categories.html", line 99, in block 'page_body' + var currencies = {{ model.convert_list_objects_to_dict_json_by_attribute_key_default(model.access_levels) | tojson | safe }}; + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 330, in convert_list_objects_to_dict_json_by_attribute_key_default + return Model_View_Base.convert_list_objects_to_dict_json_by_attribute_key(list_objects, getattr(obj_class, obj_class.FLAG_NAME_ATTR_OPTION_VALUE)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 318, in convert_list_objects_to_dict_json_by_attribute_key + return {getattr(obj, key): obj.to_json() for obj in list_objects} + ^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\business_objects\store\access_level.py", line 66, in to_json + self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\lib\argument_validation.py", line 493, in input_bool + raise ValueError(error_msg) +ValueError: Invalid Access_Level.to_json argument active. Type = . Value = 2 + diff --git a/app.log.1 b/app.log.1 index dcc9f9e2..5712a4fc 100644 --- a/app.log.1 +++ b/app.log.1 @@ -1,4 +1,4 @@ -Exception on /store/products [GET] +Exception on /store/categories [GET] Traceback (most recent call last): File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app response = self.full_dispatch_request() @@ -15,89 +15,60 @@ Traceback (most recent call last): File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\store\product.py", line 40, in products - filters.is_not_empty = filters.is_not_empty if arg_filter_is_not_empty is None else av.input_bool(arg_filter_is_not_empty, 'is_not_empty', 'filter') - ^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\main.py", line 828, in __getattr__ - raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') -AttributeError: 'Filters_Product' object has no attribute 'is_not_empty' + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\controllers\store\product_category.py", line 57, in categories + return render_template('pages/store/_product_categories.html', model = model) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\templating.py", line 150, in render_template + return _render(app, template, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\templating.py", line 131, in _render + rv = template.render(context) + ^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\jinja2\environment.py", line 1304, in render + self.environment.handle_exception() + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\jinja2\environment.py", line 939, in handle_exception + raise rewrite_traceback_stack(source=source) + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\pages\store\_product_categories.html", line 1, in top-level template code + {% extends 'layouts/layout.html' %} + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\layouts\layout.html", line 316, in top-level template code + {% block page_body %}{% endblock %} + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\templates\pages\store\_product_categories.html", line 99, in block 'page_body' + var currencies = {{ model.convert_list_objects_to_dict_json_by_attribute_key_default(model.access_levels) | tojson | safe }}; + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 330, in convert_list_objects_to_dict_json_by_attribute_key_default + return Model_View_Base.convert_list_objects_to_dict_json_by_attribute_key(list_objects, getattr(obj_class, obj_class.FLAG_NAME_ATTR_OPTION_VALUE)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 318, in convert_list_objects_to_dict_json_by_attribute_key + return {getattr(obj, key): obj.to_json() for obj in list_objects} + ^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\business_objects\store\access_level.py", line 66, in to_json + self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\lib\argument_validation.py", line 493, in input_bool + raise ValueError(error_msg) +ValueError: Invalid Access_Level.to_json argument active. Type = . Value = 2 Server Error: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. -Request: 127.0.0.1 GET http /store/products? Host: 127.0.0.1:5000 +Request: 127.0.0.1 GET http /store/categories? Host: 127.0.0.1:5000 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128" Sec-Ch-Ua-Mobile: ?0 Sec-Ch-Ua-Platform: "Windows" -Upgrade-Insecure-Requests: 1 Dnt: 1 +Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Sec-Fetch-Site: same-origin Sec-Fetch-Mode: navigate Sec-Fetch-User: ?1 Sec-Fetch-Dest: document -Referer: http://127.0.0.1:5000/store/products +Referer: http://127.0.0.1:5000/store/categories Accept-Encoding: gzip, deflate, br, zstd Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 -Cookie: session=.eJytVlmvqzgS_iutSN1PnXPB7EdqzWQFcgJJSFhfIseGYLYQlgTovv99TM6de_uhZ5NGCsF2FVVfudbfJ7Bt4ltF6hDbdVhN3n-fIFicIc5Jca6bWxVO3puqDX_903H7Yvw8DXNIssn7JMRPWOG3nGCchc2tqHPSxH-_jtQ3dMsnv04iUtVNAXMqcHIKMe7pGcFn1FZVWKD-jMMItlkzeS_aLHuRqvBKbsVfED4BsN_X59EIhsp9vf8QBRlcFAHJioAZBUrMBbJMFEajwvr8Qnx-hBWJSIgn7xHM6vBFIQXKWhziszM7_dD6aScl121JVf3Z-Lqtvhlk_NPu6XE0fPKV3lddRefmloYFpQMlwgoQsYKlSxRCSQKcKCGJh5iHUBIVXpAlxIkshdh-cwNEKKzr7xLCfhNfVER2ZJNCTyfbxSa75Ma4nxuJDSzGNHXyJNAzBz25EahZDNIMcdsraeD5zaXAMRz0p5kEWZAEt52a8RcisKgXYuxZN2MhJBfAPPSCeXvze4tKEYTwmU3D5zp7c4SZLjNFgfY8-gjvHnuYabF2nJVyG-RcftMz42oEkvshrnMju1PU_bkqJC3z5i1MdprqYeuYRPLixBtp1xIQA8Xp-dapiMF2q3XBR7DyhLpr0E7Wc0U_SbVnFpqqM4_iHkBj734cVW7rFlwjHLzNw_WZM75Ws6WzUE6mVZ8f25PTbk9q90xdrdib7sbkhZnk5Iv1dGb46v1cwKMpbhqIV7t-Olsqnn44cz2zFstD_vHs9oqg9OFB2HN8L2SsxXe4q4fkYzhraz0Jmfn8ZkgztLA0rXkmDNsN-5pM8-3DkvIti_VcXnv3_rhke1GlydQaInPyuhvjMqudLekflrk8V7IVgT1bK9usW5sw3byFSz-WpuG534rKND3C3f3jsZjRMAi7klRhfYY0BFkJ8JLCA4n7cU5oUMgizzCvLPiLKDnag86aRK_1whLQQhf1tPScBd3nTRmM-8J5hF5gWynPX5LNI9CurJOut8Y6Zq1-o7xRYS10zeqSr5vgSD_InRSDdR8shAa6VnpRHeYChOHiZgx8CRbii2uPyrNAwzHKDy2lpYHaZVhVWgTYEqvxLABsDN1n6wOlGUMWqVmCNaf_1BEzWJsPOyI_aGgWKF8D37NiRD7D0_eCGKvrfjvYQ7A0cyM5MMYSp-aJGgt83lT93gRmbCwRbw4WCZY-s-cMxVxen5tCV5CK8mDJ3rBmPVFvD4ej3VuEPrmZ0nT4cypkRkp15WvG9zbD5rRRA_fQIlUoRszYm6cUVxaslRiPl5noT4qlMZbXxkgC20hWojHQ56S3u6XRu6Mjcqfx3awe0zNwLY7KTbc5WwaqVQee9bgUZgOp_oOKX3zb3Hxcjj--87ggQ3mWQ9dJ9aTMfbcbguP_IeWpPb43yqS4GHwPPas7pax3APEJenF3GuhNZWvRSWPv4K6zY1qKdp6OJaj0vQPZJSuO2s593rkx4uXHgDNOqDeXiDGGK2f01M-cQ0YdVBcDl3PZTGzeyHXBdA1-d3JSY5nF5jAn_mn1DHInf8UGyF64fC4GFpupgeM8Ajue23lTBKqwN_Ly6J7i1k07YKhKYuSrEVdL4zJ5xVNyYEM1digtDoY5H6hpb3M4NtR4NZa62lxb5-BKHJ-5qoVdajZnlPuzVazqW-MRdyezCjSVVfjQFnay2OaaKUXA6QU9AF2xVze7JPUUwlv2gLj99n7XpG2UwvlSjqMqR_gBBj9sTZNfzbIbK88Jm8b6ScmwLboPgDwP28vzAe6Jve-rbLbWzdPUkjeLsJLSSJ0zRGkS3lxZ9rXNHd2XzMtuhYDdAbT1uzTxC6yWxqoaem56MUV1WGhXJlJMf1668VTeldou1ARNP2ERHmc7jdSYd4J0teM6Ge27w95p5_e5EIG2STucgGNM7BLuNGjNHwuwmw5G0JRbrduLW8VAZ24mrKKj5YNl1qvk3q8ObHe_xayr6i6u4xKtMCPx7JXWrxrdyrEz0v-C4J_K6haRLPzpc174dfIqWOemf_HMQ1jRpvfZ-0gR3V79r6XNeXJVk765m4a7iI-ku-8kYB0GR3NnMNxsaH5P_pcR5F-0flpSv9VYnpPHGku-F11G-jyoa6ogbpqyfv_yBYePafGEKWBEMYzEWCZd8dbWb6_pY1T1her6Nhj8Z1AFQem_Yx5ZbgUa6bzQxTZzg1emwwQcn5CJl5RcEtS046D2HWH9dq3gAzawesH5XH4ROMxFgOcZCQtAkCKZj4CE4Ggjf8Ei_7f6N15mfql-K6-_4N9esn7mZj-DNf0hXPywj-4_RdZ0FeK3snh5nIwOQ91D9dehfQu1mZVecbEDieXLRbB9MDcE4MjYXv6bWa0tMWzoNDY6YwIYwE8ZeQrEE2DfOfadBW8yB4LJ169f_wFsnZ0r.Zsz0IQ.CsqbE-G2jF9oYmUiZKS36HfeRw4 +Cookie: session=.eJytVlnTqkgS_SsdRnQ_tV5WgS_ixgyKoAioyP5iQBXIDrIp9Nz_PoXf7b790LNFTIQLVZlknqw8mZW_Lfy-i6smaUNotmGz-PhtAfzy5sMiKW9tVzXh4qNr-vDXP233b8XP3bDwk3zxsQjh02_gqkggzMOuKtsi6eK_32fpClTF4tdFlDRtV_oFMrgwQghHtJfAG-ibJizBeINh5Pd5t_go-zx_i5rwnlTlXwg-AeB_PN_mIDBk9_3_jzXNEgFHA5ajIcb5DBb4OBaF0eywvb0R34awSaIkhIuPyM_b8C1JSpD3MIQ3izd-eP2ME4nbvkau_hx82zffA1J_j3t5nQNffEPn1TbRrauysETyiGQIwFI050MqBCzJQJZZQ5JiYQQ53McjjgoRYogg9t_T4AMQtu0fFsJRjgMJJKdEznznkChbOQ8KdV5v1NQkdEzTDskz8R1tOqRV4u91DOzVtTJymee4XVDC2J8OTy31ci_1qpOUU0FC42CkY-jolbql04DAhkOJrVZ4n9zgPW_UttIjONSrmOV8heXutnKHMDvZjkRs4HXq8UySz1WP1W5xZ578UPS15lgaOHpFFrG3K2-KwrkYwUYfDLspeyqv24yIb0dSiGzHMXL2pGwd7jCFnJDLRXxWjnz5jGi60A1XXPO3IfBUoTT6uN_YJWljzLLFqaOQtnbKBDl8SntNI240lsbTeCJt3uaNc6B4JXO-hcNdleCVnKjWL4FYAckglMEQlmFaVje-60VR3lmVIk92l7g7esc1k8jDfkjOHhsMBK33ob08W8fA7yMI9zUjMolNWGIlc85u34mH55otmlTcFOmpF9fPnhwjke8LhhP7ZVNuhh31YEnV5ze2fIkC6wLxQ2zuy3tXPTi2bBrBXPlKoC1v2qSbxnEa6Gc7HXfiBdEgfNVJE7Y3H1EQZ4j1mmFxjvmxnyBSsGsKw95V8BcsuZrTAdeSQ3sodRpsD-tDVjvWFq2LrvbmdWkNoeOZekZRQSoP3v6OW5moqGKM66PMrZCx3re1JijEzruiFworg4Q4elu68209CyQLCwh6Cuwc89-G6Tiwzdl57u1hDIpLj2SZJ71yKHE9IPAaSjHvEXjs28_eJbhupiyQ8hTurfHTR4zB_WY6JeyAqFmCQiRcR49B8klP1_FiKImjMpmTJ2iFml4wVYCZZqBgCZfSJHfUCC1WBUChU008wcXOpMppwv0plwcOSKDwBLyCe_0JRnO6XM1RT9C30DJUDn8uhVzNkK9CxFxHnmRDljz70gOJLmfM0NlkCFfuiVwM58NMD0-EpVOFrFMNaKqGu9aEbK0ZWa9O6sueE1FYnWvn7Vyenq2TyG6mFHjtSXrrOfoQlFrnI_8XCb71lEIbguuP9xzSy0GRF75tZYe0Llz7NXnX_0PJo3hcZ7aJcGHwETr6y8hw50LEhu_EL2NCJ5WLayuLnYst5tesXptFNreg2nUuySndkWrq4idjR6kCP-OlZsKpBhi1FOVjuj_VLcozaSWzD-QL84UNq6UmpRYHWrNV6mRYmSrksTZtEtfYPb3CKt7cIPI3LheTNb3USm9XK1bOHS5OLOp7y7KMjQPxOtYn62yQULETbMbVI16mbz6VGa06snDNXp6ZiQ4wX74vWkSwi8m51WknEB7azjhfdEZ1sshI11ePfSn8stg8z4oRUWVvc6_lut0nU6w3BHu_nBrRiqPNqDCipeoPPF9uAvzxkp7OVt7jdjatRfPU9Nchf9Giae8f2SsDcjcJYSIwtAcFEssTd8zrTW09judpixsysSzNi8a5nSzxugbwzbKNNl1p5B2w475NFUehT4o3iNSJBn7U2A8KkiDa8lUaHA2dwCKW3IZSLp12hfPisfLSu5ozyJUXkBJqe2FtBUe-6KuXR98ft93oHl-vssBuo8uMB2W3g8dk_6qOPrZLzBIfyO4B2tSJNog8rM7uL7Vwx7xj4tSg4ZXtwYwmpwOvitlXN_y5t6txT06uU16WXLh8ov7Vgqqeb0b0Wybwp7qpoiQPf_qcF35dvBvWrRvfOpvQb9Cl93n3JWVUve-_Hl3Oi7uUjt1DU-1tfE1ejxND6JfJ2tu8H8oyqu_F_zKC_IurH7XU7z2WYNh3Q_296dIc_rnRtshB3HV1-_HlCwyHZfn0MwJbr8NoHbPJq1z17eo9fcyuviBf3weD_wyqTED275RnlaoEs3zk8GYrK67O2w_Fi80h389HXSeg6-dB7Q-E7ere-IPf-c0bzufjF5qEZERQFMZAmqCZiKUiggE-xrAMFcA19bf2K8VivzRf6_sv8Ovb1s8k_zMhog-A5Y_40PrTZIueQriqy_uc8WROGNioYnuH8tG67fnXTuhNE7Ofni_Rp9Pz6C1nxT74b2a1voZ-h6axORkLAiOoJcYtccbA1x8U90FzK5LEvcW3b9_-CTbvo8I.ZumzNg.3EndhjI8QnbotIPyN-mo04fvFAg Request data: b'' -Traceback: Traceback (most recent call last): - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app - response = self.full_dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request - rv = self.handle_user_exception(e) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function - return cors_after_request(app.make_response(f(*args, **kwargs))) - ^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request - rv = self.dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request - return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\store\product.py", line 40, in products - filters.is_not_empty = filters.is_not_empty if arg_filter_is_not_empty is None else av.input_bool(arg_filter_is_not_empty, 'is_not_empty', 'filter') - ^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\main.py", line 828, in __getattr__ - raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') -AttributeError: 'Filters_Product' object has no attribute 'is_not_empty' - -Exception on /login_callback [GET] -Traceback (most recent call last): - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\user.py", line 91, in login_callback - users, errors = datastore_user.get_many_user(user_filters, user) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\datastores\datastore_user.py", line 134, in get_many_user - guid = Helper_DB_MySQL.create_guid() - ^^^^^^^^^^^^^^^ -NameError: name 'Helper_DB_MySQL' is not defined - -During handling of the above exception, another exception occurred: - -Traceback (most recent call last): - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app - response = self.full_dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request - rv = self.handle_user_exception(e) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function - return cors_after_request(app.make_response(f(*args, **kwargs))) - ^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request - rv = self.dispatch_request() - ^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request - return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\routing\user.py", line 120, in login_callback - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Controller error.\n{e}'}) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydantic\_internal\_model_construction.py", line 237, in __getattr__ - raise AttributeError(item) -AttributeError: STATUS_FAILURE diff --git a/app.log.2 b/app.log.2 new file mode 100644 index 00000000..ef0caaaf --- /dev/null +++ b/app.log.2 @@ -0,0 +1,52 @@ +Request: 127.0.0.1 GET http /store/categories? Host: 127.0.0.1:5000 +Connection: keep-alive +Pragma: no-cache +Cache-Control: no-cache +Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128" +Sec-Ch-Ua-Mobile: ?0 +Sec-Ch-Ua-Platform: "Windows" +Dnt: 1 +Upgrade-Insecure-Requests: 1 +User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 +Sec-Fetch-Site: same-origin +Sec-Fetch-Mode: navigate +Sec-Fetch-User: ?1 +Sec-Fetch-Dest: document +Referer: http://127.0.0.1:5000/store/categories +Accept-Encoding: gzip, deflate, br, zstd +Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 +Cookie: session=.eJytVlnTqkgS_SsdRnQ_tV5WgS_ixgyKoAioyP5iQBXIDrIp9Nz_PoXf7b790LNFTIQLVZlknqw8mZW_Lfy-i6smaUNotmGz-PhtAfzy5sMiKW9tVzXh4qNr-vDXP233b8XP3bDwk3zxsQjh02_gqkggzMOuKtsi6eK_32fpClTF4tdFlDRtV_oFMrgwQghHtJfAG-ibJizBeINh5Pd5t_go-zx_i5rwnlTlXwg-AeB_PN_mIDBk9_3_jzXNEgFHA5ajIcb5DBb4OBaF0eywvb0R34awSaIkhIuPyM_b8C1JSpD3MIQ3izd-eP2ME4nbvkau_hx82zffA1J_j3t5nQNffEPn1TbRrauysETyiGQIwFI050MqBCzJQJZZQ5JiYQQ53McjjgoRYogg9t_T4AMQtu0fFsJRjgMJJKdEznznkChbOQ8KdV5v1NQkdEzTDskz8R1tOqRV4u91DOzVtTJymee4XVDC2J8OTy31ci_1qpOUU0FC42CkY-jolbql04DAhkOJrVZ4n9zgPW_UttIjONSrmOV8heXutnKHMDvZjkRs4HXq8UySz1WP1W5xZ578UPS15lgaOHpFFrG3K2-KwrkYwUYfDLspeyqv24yIb0dSiGzHMXL2pGwd7jCFnJDLRXxWjnz5jGi60A1XXPO3IfBUoTT6uN_YJWljzLLFqaOQtnbKBDl8SntNI240lsbTeCJt3uaNc6B4JXO-hcNdleCVnKjWL4FYAckglMEQlmFaVje-60VR3lmVIk92l7g7esc1k8jDfkjOHhsMBK33ob08W8fA7yMI9zUjMolNWGIlc85u34mH55otmlTcFOmpF9fPnhwjke8LhhP7ZVNuhh31YEnV5ze2fIkC6wLxQ2zuy3tXPTi2bBrBXPlKoC1v2qSbxnEa6Gc7HXfiBdEgfNVJE7Y3H1EQZ4j1mmFxjvmxnyBSsGsKw95V8BcsuZrTAdeSQ3sodRpsD-tDVjvWFq2LrvbmdWkNoeOZekZRQSoP3v6OW5moqGKM66PMrZCx3re1JijEzruiFworg4Q4elu68209CyQLCwh6Cuwc89-G6Tiwzdl57u1hDIpLj2SZJ71yKHE9IPAaSjHvEXjs28_eJbhupiyQ8hTurfHTR4zB_WY6JeyAqFmCQiRcR49B8klP1_FiKImjMpmTJ2iFml4wVYCZZqBgCZfSJHfUCC1WBUChU008wcXOpMppwv0plwcOSKDwBLyCe_0JRnO6XM1RT9C30DJUDn8uhVzNkK9CxFxHnmRDljz70gOJLmfM0NlkCFfuiVwM58NMD0-EpVOFrFMNaKqGu9aEbK0ZWa9O6sueE1FYnWvn7Vyenq2TyG6mFHjtSXrrOfoQlFrnI_8XCb71lEIbguuP9xzSy0GRF75tZYe0Llz7NXnX_0PJo3hcZ7aJcGHwETr6y8hw50LEhu_EL2NCJ5WLayuLnYst5tesXptFNreg2nUuySndkWrq4idjR6kCP-OlZsKpBhi1FOVjuj_VLcozaSWzD-QL84UNq6UmpRYHWrNV6mRYmSrksTZtEtfYPb3CKt7cIPI3LheTNb3USm9XK1bOHS5OLOp7y7KMjQPxOtYn62yQULETbMbVI16mbz6VGa06snDNXp6ZiQ4wX74vWkSwi8m51WknEB7azjhfdEZ1sshI11ePfSn8stg8z4oRUWVvc6_lut0nU6w3BHu_nBrRiqPNqDCipeoPPF9uAvzxkp7OVt7jdjatRfPU9Nchf9Giae8f2SsDcjcJYSIwtAcFEssTd8zrTW09judpixsysSzNi8a5nSzxugbwzbKNNl1p5B2w475NFUehT4o3iNSJBn7U2A8KkiDa8lUaHA2dwCKW3IZSLp12hfPisfLSu5ozyJUXkBJqe2FtBUe-6KuXR98ft93oHl-vssBuo8uMB2W3g8dk_6qOPrZLzBIfyO4B2tSJNog8rM7uL7Vwx7xj4tSg4ZXtwYwmpwOvitlXN_y5t6txT06uU16WXLh8ov7Vgqqeb0b0Wybwp7qpoiQPf_qcF35dvBvWrRvfOpvQb9Cl93n3JWVUve-_Hl3Oi7uUjt1DU-1tfE1ejxND6JfJ2tu8H8oyqu_F_zKC_IurH7XU7z2WYNh3Q_296dIc_rnRtshB3HV1-_HlCwyHZfn0MwJbr8NoHbPJq1z17eo9fcyuviBf3weD_wyqTED275RnlaoEs3zk8GYrK67O2w_Fi80h389HXSeg6-dB7Q-E7ere-IPf-c0bzufjF5qEZERQFMZAmqCZiKUiggE-xrAMFcA19bf2K8VivzRf6_sv8Ovb1s8k_zMhog-A5Y_40PrTZIueQriqy_uc8WROGNioYnuH8tG67fnXTuhNE7Ofni_Rp9Pz6C1nxT74b2a1voZ-h6axORkLAiOoJcYtccbA1x8U90FzK5LEvcW3b9_-CTbvo8I.ZumzNg.3EndhjI8QnbotIPyN-mo04fvFAg + + +Request data: b'' +Traceback: Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\controllers\store\product_category.py", line 56, in categories + model = Model_View_Store_Product_Category(form_filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_store_product_category.py", line 46, in __init__ + self.access_levels = self.get_many_access_level(Filters_Access_Level()) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 299, in get_many_access_level + access_levels, errors = DataStore_Base.get_many_access_level(filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\datastores\datastore_base.py", line 216, in get_many_access_level + argument_dict = filters.to_json() + ^^^^^^^^^^^^^^^ +AttributeError: 'Filters_Access_Level' object has no attribute 'to_json'. Did you mean: 'from_json'? + diff --git a/app.log.3 b/app.log.3 new file mode 100644 index 00000000..1e9193bb --- /dev/null +++ b/app.log.3 @@ -0,0 +1,83 @@ +Request: 127.0.0.1 GET http /store/categories? Host: 127.0.0.1:5000 +Connection: keep-alive +Pragma: no-cache +Cache-Control: no-cache +Sec-Ch-Ua: "Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128" +Sec-Ch-Ua-Mobile: ?0 +Sec-Ch-Ua-Platform: "Windows" +Dnt: 1 +Upgrade-Insecure-Requests: 1 +User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 +Sec-Fetch-Site: same-origin +Sec-Fetch-Mode: navigate +Sec-Fetch-User: ?1 +Sec-Fetch-Dest: document +Referer: http://127.0.0.1:5000/store/categories +Accept-Encoding: gzip, deflate, br, zstd +Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 +Cookie: session=.eJytVlnTqkgS_SsdRnQ_tV5WgS_ixgyKoAioyP5iQBXIDrIp9Nz_PoXf7b790LNFTIQLVZlknqw8mZW_Lfy-i6smaUNotmGz-PhtAfzy5sMiKW9tVzXh4qNr-vDXP233b8XP3bDwk3zxsQjh02_gqkggzMOuKtsi6eK_32fpClTF4tdFlDRtV_oFMrgwQghHtJfAG-ibJizBeINh5Pd5t_go-zx_i5rwnlTlXwg-AeB_PN_mIDBk9_3_jzXNEgFHA5ajIcb5DBb4OBaF0eywvb0R34awSaIkhIuPyM_b8C1JSpD3MIQ3izd-eP2ME4nbvkau_hx82zffA1J_j3t5nQNffEPn1TbRrauysETyiGQIwFI050MqBCzJQJZZQ5JiYQQ53McjjgoRYogg9t_T4AMQtu0fFsJRjgMJJKdEznznkChbOQ8KdV5v1NQkdEzTDskz8R1tOqRV4u91DOzVtTJymee4XVDC2J8OTy31ci_1qpOUU0FC42CkY-jolbql04DAhkOJrVZ4n9zgPW_UttIjONSrmOV8heXutnKHMDvZjkRs4HXq8UySz1WP1W5xZ578UPS15lgaOHpFFrG3K2-KwrkYwUYfDLspeyqv24yIb0dSiGzHMXL2pGwd7jCFnJDLRXxWjnz5jGi60A1XXPO3IfBUoTT6uN_YJWljzLLFqaOQtnbKBDl8SntNI240lsbTeCJt3uaNc6B4JXO-hcNdleCVnKjWL4FYAckglMEQlmFaVje-60VR3lmVIk92l7g7esc1k8jDfkjOHhsMBK33ob08W8fA7yMI9zUjMolNWGIlc85u34mH55otmlTcFOmpF9fPnhwjke8LhhP7ZVNuhh31YEnV5ze2fIkC6wLxQ2zuy3tXPTi2bBrBXPlKoC1v2qSbxnEa6Gc7HXfiBdEgfNVJE7Y3H1EQZ4j1mmFxjvmxnyBSsGsKw95V8BcsuZrTAdeSQ3sodRpsD-tDVjvWFq2LrvbmdWkNoeOZekZRQSoP3v6OW5moqGKM66PMrZCx3re1JijEzruiFworg4Q4elu68209CyQLCwh6Cuwc89-G6Tiwzdl57u1hDIpLj2SZJ71yKHE9IPAaSjHvEXjs28_eJbhupiyQ8hTurfHTR4zB_WY6JeyAqFmCQiRcR49B8klP1_FiKImjMpmTJ2iFml4wVYCZZqBgCZfSJHfUCC1WBUChU008wcXOpMppwv0plwcOSKDwBLyCe_0JRnO6XM1RT9C30DJUDn8uhVzNkK9CxFxHnmRDljz70gOJLmfM0NlkCFfuiVwM58NMD0-EpVOFrFMNaKqGu9aEbK0ZWa9O6sueE1FYnWvn7Vyenq2TyG6mFHjtSXrrOfoQlFrnI_8XCb71lEIbguuP9xzSy0GRF75tZYe0Llz7NXnX_0PJo3hcZ7aJcGHwETr6y8hw50LEhu_EL2NCJ5WLayuLnYst5tesXptFNreg2nUuySndkWrq4idjR6kCP-OlZsKpBhi1FOVjuj_VLcozaSWzD-QL84UNq6UmpRYHWrNV6mRYmSrksTZtEtfYPb3CKt7cIPI3LheTNb3USm9XK1bOHS5OLOp7y7KMjQPxOtYn62yQULETbMbVI16mbz6VGa06snDNXp6ZiQ4wX74vWkSwi8m51WknEB7azjhfdEZ1sshI11ePfSn8stg8z4oRUWVvc6_lut0nU6w3BHu_nBrRiqPNqDCipeoPPF9uAvzxkp7OVt7jdjatRfPU9Nchf9Giae8f2SsDcjcJYSIwtAcFEssTd8zrTW09judpixsysSzNi8a5nSzxugbwzbKNNl1p5B2w475NFUehT4o3iNSJBn7U2A8KkiDa8lUaHA2dwCKW3IZSLp12hfPisfLSu5ozyJUXkBJqe2FtBUe-6KuXR98ft93oHl-vssBuo8uMB2W3g8dk_6qOPrZLzBIfyO4B2tSJNog8rM7uL7Vwx7xj4tSg4ZXtwYwmpwOvitlXN_y5t6txT06uU16WXLh8ov7Vgqqeb0b0Wybwp7qpoiQPf_qcF35dvBvWrRvfOpvQb9Cl93n3JWVUve-_Hl3Oi7uUjt1DU-1tfE1ejxND6JfJ2tu8H8oyqu_F_zKC_IurH7XU7z2WYNh3Q_296dIc_rnRtshB3HV1-_HlCwyHZfn0MwJbr8NoHbPJq1z17eo9fcyuviBf3weD_wyqTED275RnlaoEs3zk8GYrK67O2w_Fi80h389HXSeg6-dB7Q-E7ere-IPf-c0bzufjF5qEZERQFMZAmqCZiKUiggE-xrAMFcA19bf2K8VivzRf6_sv8Ovb1s8k_zMhog-A5Y_40PrTZIueQriqy_uc8WROGNioYnuH8tG67fnXTuhNE7Ofni_Rp9Pz6C1nxT74b2a1voZ-h6axORkLAiOoJcYtccbA1x8U90FzK5LEvcW3b9_-CTbvo8I.ZumzNg.3EndhjI8QnbotIPyN-mo04fvFAg + + +Request data: b'' +Traceback: Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\controllers\store\product_category.py", line 56, in categories + model = Model_View_Store_Product_Category(form_filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_store_product_category.py", line 46, in __init__ + self.access_levels = self.get_many_access_level(Filters_Access_Level()) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 299, in get_many_access_level + access_levels, errors = DataStore_Base.get_many_access_level(filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\datastores\datastore_base.py", line 214, in get_many_access_level + av.val_instance(filters, 'filters', _m, Filters_Access_Level) + ^^^^^^^^^^^^^^^^^^^^ +NameError: name 'Filters_Access_Level' is not defined + +Exception on /store/categories [GET] +Traceback (most recent call last): + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1473, in wsgi_app + response = self.full_dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request + rv = self.handle_user_exception(e) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask_cors\extension.py", line 178, in wrapped_function + return cors_after_request(app.make_response(f(*args, **kwargs))) + ^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request + rv = self.dispatch_request() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 865, in dispatch_request + return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\controllers\store\product_category.py", line 56, in categories + model = Model_View_Store_Product_Category(form_filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_store_product_category.py", line 46, in __init__ + self.access_levels = self.get_many_access_level(Filters_Access_Level()) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\models\model_view_base.py", line 299, in get_many_access_level + access_levels, errors = DataStore_Base.get_many_access_level(filters) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\datastores\datastore_base.py", line 216, in get_many_access_level + argument_dict = filters.to_json() + ^^^^^^^^^^^^^^^ +AttributeError: 'Filters_Access_Level' object has no attribute 'to_json'. Did you mean: 'from_json'? +Server Error: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. diff --git a/app.py b/app.py index 7794704e..bfc68cb7 100644 --- a/app.py +++ b/app.py @@ -37,15 +37,15 @@ from datastores.datastore_store_base import DataStore_Store from helpers.helper_app import Helper_App import lib.argument_validation as av """ -from routing.core import routes_core -from routing.legal import routes_legal -from routing.store.store import routes_store -from routing.store.product import routes_store_product -from routing.store.product_category import routes_store_product_category -from routing.store.product_permutation import routes_store_product_permutation -from routing.store.stock_item import routes_store_stock_item -from routing.store.supplier import routes_store_supplier -from routing.user import routes_user +from controllers.core import routes_core +from controllers.legal import routes_legal +from controllers.store.store import routes_store +from controllers.store.product import routes_store_product +from controllers.store.product_category import routes_store_product_category +from controllers.store.product_permutation import routes_store_product_permutation +from controllers.store.stock_item import routes_store_stock_item +from controllers.store.supplier import routes_store_supplier +from controllers.user import routes_user # external from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session # from flask_appconfig import AppConfig @@ -131,3 +131,10 @@ app.register_blueprint(routes_store_product_permutation) app.register_blueprint(routes_store_stock_item) app.register_blueprint(routes_store_supplier) app.register_blueprint(routes_user) + + + +@app.template_filter('console_log') +def console_log(value): + print(value) + return value \ No newline at end of file diff --git a/business_objects/__pycache__/base.cpython-312.pyc b/business_objects/__pycache__/base.cpython-312.pyc index c7ef2d0f..0dfde09f 100644 Binary files a/business_objects/__pycache__/base.cpython-312.pyc and b/business_objects/__pycache__/base.cpython-312.pyc differ diff --git a/business_objects/__pycache__/db_base.cpython-312.pyc b/business_objects/__pycache__/db_base.cpython-312.pyc index 75c2841e..57af9764 100644 Binary files a/business_objects/__pycache__/db_base.cpython-312.pyc and b/business_objects/__pycache__/db_base.cpython-312.pyc differ diff --git a/business_objects/__pycache__/unit_measurement.cpython-312.pyc b/business_objects/__pycache__/unit_measurement.cpython-312.pyc new file mode 100644 index 00000000..2747280a Binary files /dev/null and b/business_objects/__pycache__/unit_measurement.cpython-312.pyc differ diff --git a/business_objects/__pycache__/user.cpython-312.pyc b/business_objects/__pycache__/user.cpython-312.pyc index 85d51bf6..112be66a 100644 Binary files a/business_objects/__pycache__/user.cpython-312.pyc and b/business_objects/__pycache__/user.cpython-312.pyc differ diff --git a/business_objects/base.py b/business_objects/base.py new file mode 100644 index 00000000..c5b1a1b2 --- /dev/null +++ b/business_objects/base.py @@ -0,0 +1,59 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Business Objects +Feature: Base Business Object + +Description: +Abstract business object +""" + +# internal +from extensions import db +import lib.argument_validation as av +# external +from typing import ClassVar + + +class Base(): + ATTR_ID_ACCESS_LEVEL: ClassVar[str] = 'id_access_level' + ATTR_ID_CURRENCY: ClassVar[str] = 'id_currency' + ATTR_ID_DELIVERY_REGION: ClassVar[str] = 'id_delivery_region' + ATTR_ID_USER: ClassVar[str] = 'id_user' + FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = 'access_level_required' + FLAG_ACTIVE: ClassVar[str] = 'active' + FLAG_CAN_ADMIN: ClassVar[str] = 'can_admin' + FLAG_CAN_EDIT: ClassVar[str] = 'can_edit' + FLAG_CAN_VIEW: ClassVar[str] = 'can_view' + FLAG_CODE: ClassVar[str] = 'code' + FLAG_DESCRIPTION: ClassVar[str] = 'description' + FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order' + FLAG_GUID: ClassVar[str] = 'guid' + FLAG_IS_NOT_EMPTY: ClassVar[str] = 'is_not_empty' + # FLAG_KEY_PRIMARY: ClassVar[str] = 'key_primary' + FLAG_NAME: ClassVar[str] = 'name' + FLAG_NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'NAME_ATTR_OPTION_TEXT' + FLAG_NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'NAME_ATTR_OPTION_VALUE' + FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular' + FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural' + FLAG_PRIORITY: ClassVar[str] = 'priority' + FLAG_ROWS: ClassVar[str] = 'rows' + FLAG_SYMBOL: ClassVar[str] = 'symbol' + FLAG_URL: ClassVar[str] = 'url' + NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'name-attribute-option-text' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'name-attribute-option-value' + + @classmethod + def output_bool(cls, value): + return av.input_bool(value, f'{cls.__name__} bool attribute', f'{cls.__name__}.output_bool') + @staticmethod + def convert_list_objects_to_list_options(objects): + return [object.to_json_option() for object in objects] + @classmethod + def get_shared_json_attributes(cls, object): + return { + cls.FLAG_NAME_ATTR_OPTION_TEXT: object.NAME_ATTR_OPTION_TEXT, + cls.FLAG_NAME_ATTR_OPTION_VALUE: object.NAME_ATTR_OPTION_VALUE + } \ No newline at end of file diff --git a/business_objects/db_base.py b/business_objects/db_base.py index be09dc7b..cefee2ee 100644 --- a/business_objects/db_base.py +++ b/business_objects/db_base.py @@ -61,8 +61,10 @@ class SQLAlchemy_ABC(db.Model, metaclass=SQLAlchemy_ABCMeta): @classmethod def from_json(cls, json): pass + """ def to_json_option(self): pass + """ def to_temporary_record(self): pass def to_object_with_missing_attributes(self, excluded_attributes): diff --git a/business_objects/store/__pycache__/access_level.cpython-312.pyc b/business_objects/store/__pycache__/access_level.cpython-312.pyc index a5cfe08f..0253f0ed 100644 Binary files a/business_objects/store/__pycache__/access_level.cpython-312.pyc and b/business_objects/store/__pycache__/access_level.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/basket.cpython-312.pyc b/business_objects/store/__pycache__/basket.cpython-312.pyc index 053352a6..53e4e70c 100644 Binary files a/business_objects/store/__pycache__/basket.cpython-312.pyc and b/business_objects/store/__pycache__/basket.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/currency.cpython-312.pyc b/business_objects/store/__pycache__/currency.cpython-312.pyc index b9e8f026..81cebae2 100644 Binary files a/business_objects/store/__pycache__/currency.cpython-312.pyc and b/business_objects/store/__pycache__/currency.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/delivery_region.cpython-312.pyc b/business_objects/store/__pycache__/delivery_region.cpython-312.pyc index 8b3529c7..07582857 100644 Binary files a/business_objects/store/__pycache__/delivery_region.cpython-312.pyc and b/business_objects/store/__pycache__/delivery_region.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/image.cpython-312.pyc b/business_objects/store/__pycache__/image.cpython-312.pyc index 28d28bca..949ab514 100644 Binary files a/business_objects/store/__pycache__/image.cpython-312.pyc and b/business_objects/store/__pycache__/image.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/order.cpython-312.pyc b/business_objects/store/__pycache__/order.cpython-312.pyc index 8210f475..c700bb9b 100644 Binary files a/business_objects/store/__pycache__/order.cpython-312.pyc and b/business_objects/store/__pycache__/order.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product.cpython-312.pyc b/business_objects/store/__pycache__/product.cpython-312.pyc index ed4981c7..8172f623 100644 Binary files a/business_objects/store/__pycache__/product.cpython-312.pyc and b/business_objects/store/__pycache__/product.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_category.cpython-312.pyc b/business_objects/store/__pycache__/product_category.cpython-312.pyc index 7e2f12e9..6b1d5174 100644 Binary files a/business_objects/store/__pycache__/product_category.cpython-312.pyc and b/business_objects/store/__pycache__/product_category.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_permutation.cpython-312.pyc b/business_objects/store/__pycache__/product_permutation.cpython-312.pyc index 3642ef73..3a940a64 100644 Binary files a/business_objects/store/__pycache__/product_permutation.cpython-312.pyc and b/business_objects/store/__pycache__/product_permutation.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_price.cpython-312.pyc b/business_objects/store/__pycache__/product_price.cpython-312.pyc index 5554e929..903acc7b 100644 Binary files a/business_objects/store/__pycache__/product_price.cpython-312.pyc and b/business_objects/store/__pycache__/product_price.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_variation.cpython-312.pyc b/business_objects/store/__pycache__/product_variation.cpython-312.pyc index 29babe0d..1dd0c758 100644 Binary files a/business_objects/store/__pycache__/product_variation.cpython-312.pyc and b/business_objects/store/__pycache__/product_variation.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_variation_tree.cpython-312.pyc b/business_objects/store/__pycache__/product_variation_tree.cpython-312.pyc index 05f65774..6664205a 100644 Binary files a/business_objects/store/__pycache__/product_variation_tree.cpython-312.pyc and b/business_objects/store/__pycache__/product_variation_tree.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/product_variation_type.cpython-312.pyc b/business_objects/store/__pycache__/product_variation_type.cpython-312.pyc new file mode 100644 index 00000000..45656987 Binary files /dev/null and b/business_objects/store/__pycache__/product_variation_type.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/stock_item.cpython-312.pyc b/business_objects/store/__pycache__/stock_item.cpython-312.pyc index c5e06616..f40d2f06 100644 Binary files a/business_objects/store/__pycache__/stock_item.cpython-312.pyc and b/business_objects/store/__pycache__/stock_item.cpython-312.pyc differ diff --git a/business_objects/store/__pycache__/store_base.cpython-312.pyc b/business_objects/store/__pycache__/store_base.cpython-312.pyc index 01a1a0c6..8e8723e1 100644 Binary files a/business_objects/store/__pycache__/store_base.cpython-312.pyc and b/business_objects/store/__pycache__/store_base.cpython-312.pyc differ diff --git a/business_objects/store/access_level.py b/business_objects/store/access_level.py index 108097e4..3cb269b1 100644 --- a/business_objects/store/access_level.py +++ b/business_objects/store/access_level.py @@ -20,6 +20,8 @@ from typing import ClassVar class Access_Level(db.Model, Store_Base): + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_ACCESS_LEVEL + NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME __tablename__ = 'Shop_Access_Level_Temp' id_access_level = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(50)) @@ -33,8 +35,9 @@ class Access_Level(db.Model, Store_Base): def __init__(self): super().__init__() Store_Base.__init__(self) - def from_DB_access_level(query_row): - access_level = Access_Level() + @classmethod + def from_DB_access_level(cls, query_row): + access_level = cls() access_level.id_access_level = query_row[0] access_level.code = query_row[1] access_level.name = query_row[2] @@ -54,13 +57,14 @@ class Access_Level(db.Model, Store_Base): ''' def to_json(self): return { + **self.get_shared_json_attributes(self), self.ATTR_ID_ACCESS_LEVEL: self.id_access_level[0] if isinstance(self.id_access_level, tuple) else self.id_access_level, self.FLAG_CODE: self.code[0] if isinstance(self.code, tuple) else self.code, self.FLAG_NAME: self.name[0] if isinstance(self.name, tuple) else self.name, self.FLAG_DESCRIPTION: self.description[0] if isinstance(self.description, tuple) else self.description, self.FLAG_PRIORITY: self.priority[0] if isinstance(self.priority, tuple) else self.priority, self.FLAG_DISPLAY_ORDER: self.display_order, - self.FLAG_ACTIVE: self.active + self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') } def to_json_option(self): return { @@ -79,17 +83,3 @@ class Access_Level(db.Model, Store_Base): access_level.display_order = json[cls.FLAG_DISPLAY_ORDER] access_level.active = json[cls.FLAG_ACTIVE] return access_level - -class Filters_Access_Level(BaseModel): - get_inactive_access_level: bool - def __init__(self, get_inactive_access_level = False): - super().__init__(get_inactive_access_level = get_inactive_access_level) - def to_json(self): - return { - 'a_get_inactive_access_level': self.get_inactive_access_level - } - @classmethod - def from_json(cls, json): - filters = cls() - filters.get_inactive_access_level = json['a_get_inactive_access_level'] - return filters \ No newline at end of file diff --git a/business_objects/store/basket.py b/business_objects/store/basket.py index ef7bff0d..17a21ce5 100644 --- a/business_objects/store/basket.py +++ b/business_objects/store/basket.py @@ -22,6 +22,7 @@ import lib.argument_validation as av from business_objects.store.product import Product #, Filters_Product from business_objects.store.discount import Discount from business_objects.store.delivery_option import Delivery_Option +from business_objects.store.store_base import Store_Base # from forms import Form_Product # from models.model_view_store import Model_View_Store # circular # from datastores.datastore_store import DataStore_Store # circular @@ -107,7 +108,7 @@ class Basket_Item(): subtotal: {self.get_subtotal()} ''' -class Basket(): +class Basket(Store_Base): KEY_BASKET: str = 'basket' KEY_ID_CURRENCY: str = 'id_currency' KEY_ID_REGION_DELIVERY: str = 'id_region_delivery' @@ -147,6 +148,7 @@ class Basket(): return json_list def to_json(self): return { + **self.get_shared_json_attributes(self), Basket.KEY_ITEMS: self.to_json_list(), Basket.KEY_IS_INCLUDED_VAT: self.is_included_VAT, Basket.KEY_ID_CURRENCY: self.id_currency, diff --git a/business_objects/store/currency.py b/business_objects/store/currency.py index 498e1a51..eb67f2b9 100644 --- a/business_objects/store/currency.py +++ b/business_objects/store/currency.py @@ -11,7 +11,9 @@ Business object for product """ # internal +from business_objects.store.store_base import Store_Base from extensions import db +from lib import argument_validation as av # external from typing import ClassVar @@ -39,13 +41,10 @@ class Currency_Enum(Enum): # return Resolution_Level_Enum.HIGH """ -class Currency(db.Model): - ATTR_ID_CURRENCY: ClassVar[str] = 'id-currency' - FLAG_CODE: ClassVar[str] = 'code-currency' - FLAG_NAME: ClassVar[str] = 'name-currency' - FLAG_SYMBOL: ClassVar[str] = 'symbol-currency' - FLAG_FACTOR_FROM_GBP: ClassVar[str] = 'factor-from-GBP-currency' - FLAG_DISPLAY_ORDER: ClassVar[str] = 'display-order-currency' +class Currency(db.Model, Store_Base): + FLAG_FACTOR_FROM_GBP: ClassVar[str] = 'factor-from-GBP' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_CURRENCY + NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME id_currency = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(50)) @@ -53,29 +52,35 @@ class Currency(db.Model): symbol = db.Column(db.String(50)) factor_from_GBP = db.Column(db.Float) display_order = db.Column(db.Integer) - - def from_DB_currency(query_row): - # _m = 'Currency.from_DB_currency' - # v_arg_type = 'class attribute' - currency = Currency() + active = db.Column(db.Boolean) + @classmethod + def from_DB_currency(cls, query_row): + _m = 'Currency.from_DB_currency' + v_arg_type = 'class attribute' + currency = cls() currency.id_currency = query_row[0] currency.code = query_row[1] currency.name = query_row[2] currency.symbol = query_row[3] currency.factor_from_GBP = query_row[4] currency.display_order = query_row[5] + currency.active = av.input_bool(query_row[6], 'active', _m, v_arg_type=v_arg_type) return currency - """ - def from_DB_get_many_product_catalogue(query_row): - _m = 'Currency.from_DB_get_many_product_catalogue' + @classmethod + def from_DB_get_many_product_catalogue_product_permutation(cls, query_row): + _m = 'Currency.from_DB_get_many_product_catalogue_product_permutation' v_arg_type = 'class attribute' - currency = Currency() - currency.id_permutation = query_row[0] - currency.id_product = query_row[1] - currency.id_category = query_row[2] - currency.id_variation = query_row[3] + currency = cls() + currency.id_currency = query_row[5] + currency.code = query_row[6] + currency.symbol = query_row[7] + return currency + @classmethod + def from_DB_get_many_product_price_and_discount_and_delivery_region(cls, query_row): + _m = 'Currency.from_DB_get_many_product_price_and_discount_and_delivery_region' + v_arg_type = 'class attribute' + currency = cls() return currency - """ def __repr__(self): return f''' id: {self.id_currency} @@ -84,23 +89,35 @@ class Currency(db.Model): symbol: {self.symbol} factor from GBP: {self.factor_from_GBP} display_order: {self.display_order} + active: {self.active} ''' def to_json(self): return { - Currency.ATTR_ID_CURRENCY: self.id_currency, - Currency.FLAG_CODE: self.code, - Currency.FLAG_NAME: self.name, - Currency.FLAG_SYMBOL: self.symbol, - Currency.FLAG_FACTOR_FROM_GBP: self.factor_from_GBP, - Currency.FLAG_DISPLAY_ORDER: self.display_order + **self.get_shared_json_attributes(self), + self.NAME_ATTR_OPTION_TEXT: self.FLAG_NAME, + self.NAME_ATTR_OPTION_VALUE: self.ATTR_ID_CURRENCY, + self.ATTR_ID_CURRENCY: self.id_currency, + self.FLAG_CODE: self.code, + self.FLAG_NAME: self.name, + self.FLAG_SYMBOL: self.symbol, + self.FLAG_FACTOR_FROM_GBP: self.factor_from_GBP, + self.FLAG_DISPLAY_ORDER: self.display_order, + self.FLAG_ACTIVE: self.active, } - @staticmethod - def from_json(json_currency): - currency = Currency() - currency.id_currency = json_currency[Currency.ATTR_ID_CURRENCY] - currency.code = json_currency[Currency.FLAG_CODE] - currency.name = json_currency[Currency.FLAG_NAME] - currency.symbol = json_currency[Currency.FLAG_SYMBOL] - currency.factor_from_GBP = json_currency[Currency.FLAG_FACTOR_FROM_GBP] - currency.display_order = json_currency[Currency.FLAG_DISPLAY_ORDER] - return currency \ No newline at end of file + @classmethod + def from_json(cls, json_currency, key_suffix = ''): + currency = cls() + currency.id_currency = json_currency[f'{cls.ATTR_ID_CURRENCY}{key_suffix}'] + currency.code = json_currency.get(f'{cls.FLAG_CODE}{key_suffix}') + currency.name = json_currency.get(f'{cls.FLAG_NAME}{key_suffix}') + currency.symbol = json_currency.get(f'{cls.FLAG_SYMBOL}{key_suffix}') + currency.factor_from_GBP = json_currency.get(f'{cls.FLAG_FACTOR_FROM_GBP}{key_suffix}') + currency.display_order = json_currency.get(f'{cls.FLAG_DISPLAY_ORDER}{key_suffix}') + currency.active = json_currency.get(f'{cls.FLAG_ACTIVE}{key_suffix}') + return currency + + def to_json_option(self): + return { + 'value': self.id_currency, + 'text': self.name + } \ No newline at end of file diff --git a/business_objects/store/delivery_region.py b/business_objects/store/delivery_region.py index 5f7ceca8..94516b64 100644 --- a/business_objects/store/delivery_region.py +++ b/business_objects/store/delivery_region.py @@ -11,7 +11,9 @@ Business object for delivery region """ # internal +from business_objects.store.store_base import Store_Base from extensions import db +from lib import argument_validation as av # external from enum import Enum from typing import ClassVar @@ -20,12 +22,9 @@ from typing import ClassVar class Enum_Delivery_Region(Enum): UK = 0 -class Delivery_Region(db.Model): - ATTR_ID_REGION: ClassVar[str] = 'id-region' - FLAG_CODE: ClassVar[str] = 'code-region' - FLAG_NAME: ClassVar[str] = 'name-region' - FLAG_ACTIVE: ClassVar[str] = 'active-region' - FLAG_DISPLAY_ORDER: ClassVar[str] = 'display-order-region' +class Delivery_Region(db.Model, Store_Base): + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_DELIVERY_REGION + NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME id_region = db.Column(db.Integer, primary_key=True) """ @@ -59,19 +58,21 @@ class Delivery_Region(db.Model): self.code = code self.display_order = display_order """ - def from_DB_get_many_product_catalogue(query_row): - region = Delivery_Region() + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): + region = cls() region.id_region = query_row[0] region.name = query_row[1] region.code = query_row[2] # self.display_order = query_row[3] return region - def from_DB_region(query_row): - region = Delivery_Region() + @classmethod + def from_DB_region(cls, query_row): + region = cls() region.id_region = query_row[0] region.code = query_row[1] region.name = query_row[2] - region.active = query_row[3] + region.active = av.input_bool(query_row[3], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_region') region.display_order = query_row[4] return region def __repr__(self): @@ -84,11 +85,12 @@ class Delivery_Region(db.Model): ''' def to_json(self): return { - Delivery_Region.ATTR_ID_REGION: self.id_region, - Delivery_Region.FLAG_CODE: self.code, - Delivery_Region.FLAG_NAME: self.name, - Delivery_Region.FLAG_ACTIVE: self.active, - Delivery_Region.FLAG_DISPLAY_ORDER: self.display_order + **self.get_shared_json_attributes(self), + self.ATTR_ID_REGION: self.id_region, + self.FLAG_CODE: self.code, + self.FLAG_NAME: self.name, + self.FLAG_ACTIVE: self.active, + self.FLAG_DISPLAY_ORDER: self.display_order } @staticmethod def from_json(json_region): diff --git a/business_objects/store/image.py b/business_objects/store/image.py index bbd886e5..0af26884 100644 --- a/business_objects/store/image.py +++ b/business_objects/store/image.py @@ -11,8 +11,9 @@ Business object for product image """ # internal -import lib.argument_validation as av +from business_objects.store.store_base import Store_Base from extensions import db +import lib.argument_validation as av # external from enum import Enum @@ -46,7 +47,7 @@ class Resolution_Level_Enum(Enum): return Resolution_Level_Enum.HIGH -class Image(db.Model): +class Image(db.Model, Store_Base): id_image = db.Column(db.Integer, primary_key=True) id_product = db.Column(db.Integer) id_permutation = db.Column(db.Integer) @@ -93,6 +94,15 @@ class Image(db.Model): url: {self.url} display_order: {self.display_order} ''' + def to_json(self): + return { + **self.get_shared_json_attributes(self), + self.ATTR_ID_PRODUCT_IMAGE: self.id_image, + self.ATTR_ID_PRODUCT: self.id_product, + self.ATTR_ID_PRODUCT_CATEGORY: self.id_category, + self.FLAG_URL: self.url, + self.FLAG_DISPLAY_ORDER: self.display_order + } class Product_Image_Filters(): diff --git a/business_objects/store/order.py b/business_objects/store/order.py index 8832db9a..12e02bb8 100644 --- a/business_objects/store/order.py +++ b/business_objects/store/order.py @@ -15,6 +15,7 @@ import lib.argument_validation as av # from lib import data_types from business_objects.store.product import Product from business_objects.store.delivery_option import Delivery_Option +from business_objects.store.store_base import Store_Base # from forms import Form_Product # from models.model_view_store import Model_View_Store # circular # external @@ -26,7 +27,7 @@ import locale # VARIABLE INSTANTIATION # CLASSES -class Order(): +class Order(Store_Base): category: str product: Product quantity: int @@ -69,6 +70,7 @@ class Order(): def to_json(self): return { + **self.get_shared_json_attributes(self), 'product_id': self.product.id_product, 'price': self.product.price_GBP_full, 'quantity': self.quantity diff --git a/business_objects/store/product.py b/business_objects/store/product.py index dce91325..5b8d704d 100644 --- a/business_objects/store/product.py +++ b/business_objects/store/product.py @@ -13,7 +13,8 @@ Business object for product # internal import lib.argument_validation as av from lib import data_types -from forms.forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation +from forms.forms import Form_Basket_Add, Form_Basket_Edit +from forms.store.product_permutation import Filters_Product_Permutation from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base from business_objects.store.delivery_option import Delivery_Option from business_objects.store.discount import Discount @@ -52,14 +53,11 @@ class Enum_Status_Stock(Enum): """ class Product(SQLAlchemy_ABC, Store_Base): - FLAG_NAME: ClassVar[str] = 'name-product' - FLAG_DISPLAY_ORDER: ClassVar[str] = 'display-order-product' - FLAG_CAN_VIEW: ClassVar[str] = 'can-view-product' - FLAG_CAN_EDIT: ClassVar[str] = 'can-edit-product' - FLAG_CAN_ADMIN: ClassVar[str] = 'can-admin-product' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME FLAG_HAS_VARIATIONS: ClassVar[str] = 'has-variations-product' FLAG_INDEX_PERMUTATION_SELECTED: ClassVar[str] = 'index-permutation-selected' - FLAG_VARIATION_TREES: ClassVar[str] = 'variation-trees' + FLAG_PRODUCT_VARIATION_TREES: ClassVar[str] = 'variation-trees' id_product = db.Column(db.Integer, primary_key=True) id_category = db.Column(db.Integer) @@ -305,11 +303,12 @@ class Product(SQLAlchemy_ABC, Store_Base): for json_permutation in json[cls.ATTR_ID_PRODUCT_PERMUTATION]: product.permutations.append(Product_Permutation.from_json(json_permutation)) product.variation_trees = [] - for json_tree in json[cls.FLAG_VARIATION_TREES]: + for json_tree in json[cls.FLAG_PRODUCT_VARIATION_TREES]: product.variation_trees.append(Product_Variation_Tree.from_json(json_tree)) return product def to_json(self): return { + **self.get_shared_json_attributes(self), self.ATTR_ID_PRODUCT: self.id_product, self.ATTR_ID_PRODUCT_CATEGORY: self.id_category, self.FLAG_NAME: self.name, @@ -320,7 +319,7 @@ class Product(SQLAlchemy_ABC, Store_Base): self.FLAG_HAS_VARIATIONS: self.has_variations, self.FLAG_INDEX_PERMUTATION_SELECTED: self.index_permutation_selected, self.ATTR_ID_PRODUCT_PERMUTATION: [permutation.to_json() for permutation in self.permutations], - self.FLAG_VARIATION_TREES: [tree.to_json() for tree in self.variation_trees] + self.FLAG_PRODUCT_VARIATION_TREES: [tree.to_json() for tree in self.variation_trees] } def to_json_option(self): return { @@ -421,7 +420,7 @@ class Filters_Product(): @staticmethod def from_form_filters_product(form): - # if not (form is Form_Filters_Permutation): raise ValueError(f'Invalid form type: {type(form)}') + # if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}') av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Product) has_filter_category = not (form.id_category.data == '0' or form.id_category.data == '') is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Filters_Product.from_form_filters_product") @@ -458,8 +457,8 @@ class Filters_Product(): ) @staticmethod def from_form_filters_product_permutation(form): - # if not (form is Form_Filters_Permutation): raise ValueError(f'Invalid form type: {type(form)}') - av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Permutation) + # if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}') + av.val_instance(form, 'form', 'Filters_Product.from_form', Filters_Product_Permutation) has_category_filter = not (form.id_category.data == '0' or form.id_category.data == '') has_product_filter = not (form.id_product.data == '0' or form.id_product.data == '') get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form") @@ -651,7 +650,7 @@ class Filters_Product(Get_Many_Parameters_Base): @staticmethod def from_form_filters_product(form): - # if not (form is Form_Filters_Permutation): raise ValueError(f'Invalid form type: {type(form)}') + # if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}') av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Product) has_filter_category = not (form.id_category.data == '0' or form.id_category.data == '') is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Filters_Product.from_form_filters_product") @@ -660,7 +659,7 @@ class Filters_Product(Get_Many_Parameters_Base): get_all_product_category = not has_filter_category, get_inactive_product_category = not active, # get_first_product_category_only = False, - ids_product_category = form.id_category.data, + ids_product_category = str(form.id_category.data), get_all_product = True, get_inactive_product = not active, # get_first_product_only = False, @@ -686,23 +685,23 @@ class Filters_Product(Get_Many_Parameters_Base): # ids_discount = '', get_products_quantity_stock_below_min = False ) - @staticmethod + @staticmethod def from_form_filters_product_permutation(form): - # if not (form is Form_Filters_Permutation): raise ValueError(f'Invalid form type: {type(form)}') - av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Permutation) - has_category_filter = not (form.id_category.data == '0' or form.id_category.data == '') - has_product_filter = not (form.id_product.data == '0' or form.id_product.data == '') + # if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}') + av.val_instance(form, 'form', 'Filters_Product.from_form', Filters_Product_Permutation) + has_category_filter = not (form.id_category.data is None or form.id_category.data == '0' or form.id_category.data == '') + has_product_filter = not (form.id_product.data is None or form.id_product.data == '0' or form.id_product.data == '') get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form") print(f'form question: {type(form.is_out_of_stock)}\nbool interpretted: {get_permutations_stock_below_min}\type form: {type(form)}') return Filters_Product( get_all_product_category = not has_category_filter, get_inactive_product_category = False, # get_first_product_category_only = False, - ids_product_category = form.id_category.data, + ids_product_category = str(form.id_category.data) if has_category_filter else '', get_all_product = not has_product_filter, get_inactive_product = False, # get_first_product_only = False, - ids_product = form.id_product.data, + ids_product = str(form.id_product.data) if has_product_filter else '', get_all_permutation = not get_permutations_stock_below_min, get_inactive_permutation = False, # get_first_permutation_only = False, diff --git a/business_objects/store/product_category.py b/business_objects/store/product_category.py index 6f28cf8b..98655944 100644 --- a/business_objects/store/product_category.py +++ b/business_objects/store/product_category.py @@ -28,6 +28,9 @@ from typing import ClassVar class Product_Category(SQLAlchemy_ABC, Store_Base): FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = 'id_access_level_required' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT_CATEGORY + NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME + __tablename__ = 'Shop_Product_Category_Temp' id_category = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(50)) @@ -48,8 +51,9 @@ class Product_Category(SQLAlchemy_ABC, Store_Base): super().__init__() Store_Base.__init__(self) self.name_access_level_required = None - def from_DB_get_many_product_catalogue(query_row): - category = Product_Category() + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): + category = cls() category.id_category = query_row[0] category.code = query_row[1] category.name = query_row[2] @@ -57,10 +61,10 @@ class Product_Category(SQLAlchemy_ABC, Store_Base): category.id_access_level_required = query_row[4] category.name_access_level_required = query_row[5] category.display_order = query_row[6] - category.active = query_row[7] - category.can_view = query_row[8] - category.can_edit = query_row[9] - category.can_admin = query_row[10] + category.active = av.input_bool(query_row[7], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_get_many_product_catalogue') + category.can_view = av.input_bool(query_row[8], cls.FLAG_CAN_VIEW, f'{cls.__name__}.from_DB_get_many_product_catalogue') + category.can_edit = av.input_bool(query_row[9], cls.FLAG_CAN_EDIT, f'{cls.__name__}.from_DB_get_many_product_catalogue') + category.can_admin = av.input_bool(query_row[10], cls.FLAG_CAN_ADMIN, f'{cls.__name__}.from_DB_get_many_product_catalogue') return category """ def key_product_index_from_ids_product_permutation(id_product, id_permutation): @@ -178,7 +182,7 @@ class Product_Category(SQLAlchemy_ABC, Store_Base): return list_products def to_json(self): return { - self.FLAG_KEY_PRIMARY: self.ATTR_ID_PRODUCT_CATEGORY, + **self.get_shared_json_attributes(self), self.ATTR_ID_PRODUCT_CATEGORY: self.id_category[0] if isinstance(self.id_category, tuple) else self.id_category, self.FLAG_CODE: self.code[0] if isinstance(self.code, tuple) else self.code, self.FLAG_NAME: self.name[0] if isinstance(self.name, tuple) else self.name, @@ -195,12 +199,12 @@ class Product_Category(SQLAlchemy_ABC, Store_Base): def from_json(cls, json): print(f' Category.from_json: {json}') category = cls() - category.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY], - category.code = json[cls.FLAG_CODE], - category.name = json[cls.FLAG_NAME], - category.description = json[cls.FLAG_DESCRIPTION], - category.id_access_level_required = json[cls.ATTR_ID_ACCESS_LEVEL], - category.name_access_level_required = json.get(cls.FLAG_ACCESS_LEVEL_REQUIRED, ''), + category.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY] + category.code = json[cls.FLAG_CODE] + category.name = json[cls.FLAG_NAME] + category.description = json[cls.FLAG_DESCRIPTION] + category.id_access_level_required = json[cls.ATTR_ID_ACCESS_LEVEL] + category.name_access_level_required = json.get(cls.FLAG_ACCESS_LEVEL_REQUIRED, '') category.display_order = json[cls.FLAG_DISPLAY_ORDER] category.active = json[cls.FLAG_ACTIVE] category.can_view = json.get(cls.FLAG_CAN_VIEW, False) @@ -258,8 +262,9 @@ class Filters_Product_Category(BaseModel, Store_Base): ids_product_category = '', ids_product = '' ) - def to_json(self): + def to_json(self): return { + **self.get_shared_json_attributes(self), 'a_ids_product_category': self.ids_product_category, 'a_ids_product': self.ids_product } @@ -282,10 +287,11 @@ class Filters_Product_Category(Get_Many_Parameters_Base): is_not_empty = False, active = True ) - def to_json(self): + def to_json(self): return { + **self.get_shared_json_attributes(self), self.FLAG_IS_NOT_EMPTY: self.is_not_empty, - self.FLAG_ACTIVE: self.active + self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') } @classmethod def from_json(cls, json): @@ -379,13 +385,19 @@ class Product_Category_Container(Store_Base): for category in self.categories: list_categories.append({'value': category.id_category, 'text': category.name}) return list_categories - def to_product_option_list(self): + def get_list_products(self): list_products = [] for category in self.categories: # list_products.append(category.to_product_option_list()) + """ for product in category.products: list_products.append({'value': product.id_product, 'text': product.name, Product.ATTR_ID_PRODUCT_CATEGORY: product.id_category}) + """ + list_products += category.products return list_products + def to_product_option_list(self): + list_products = self.get_list_products() + return [{'value': product.id_product, 'text': product.name, Product.ATTR_ID_PRODUCT_CATEGORY: product.id_category} for product in list_products] def get_product_option_lists_by_category(self): dict_lists_products = {} for category in self.categories: @@ -393,6 +405,7 @@ class Product_Category_Container(Store_Base): return dict_lists_products def to_json(self): return { + **self.get_shared_json_attributes(self), f'{self.FLAG_ROWS}': [category.to_json() for category in self.categories] } """ @@ -412,4 +425,64 @@ class Product_Category_Container(Store_Base): for column in self.__table__.columns if column.name not in ['created_on', 'created_by'] } - return self.to_object_with_missing_attributes(excluded_attributes) \ No newline at end of file + return self.to_object_with_missing_attributes(excluded_attributes) + + +""" +class Table_Shop_Product_Category(db.Model): + __tablename__ = 'Shop_Product_Category' + id_category: int = db.Column(db.Integer, primary_key=True) + code: str = db.Column(db.String(50)) + name: str = db.Column(db.String(255)) + description: str = db.Column(db.String(4000)) + active: bool = db.Column(db.Boolean) + display_order: int = db.Column(db.Integer) + created_on: datetime = db.Column(db.DateTime) + created_by: int = db.Column(db.Integer) + id_change_set: int = db.Column(db.Integer) +""" +class Product_Category_Temp(db.Model): + __tablename__ = 'Shop_Product_Category_Temp' + __table_args__ = { 'extend_existing': True } + id_category: int = db.Column(db.Integer, primary_key=True) + code: str = db.Column(db.String(50)) + name: str = db.Column(db.String(255)) + description: str = db.Column(db.String(4000)) + id_access_level_required: int = db.Column(db.Integer) + active: bool = db.Column(db.Boolean) + display_order: int = db.Column(db.Integer) + guid: str = db.Column(db.BINARY(36)) + # created_on: datetime = db.Column(db.DateTime) + # created_by: int = db.Column(db.Integer) + + @classmethod + def from_product_category(cls, product_category): + row = cls() + row.id_category = product_category.id_category[0] if isinstance(product_category.id_category, tuple) else product_category.id_category + row.code = product_category.code[0] if isinstance(product_category.code, tuple) else product_category.code + row.name = product_category.name[0] if isinstance(product_category.name, tuple) else product_category.name + row.description = product_category.description[0] if isinstance(product_category.description, tuple) else product_category.description + row.id_access_level_required = product_category.id_access_level_required[0] if isinstance(product_category.id_access_level_required, tuple) else product_category.id_access_level_required + row.active = product_category.active + row.display_order = product_category.display_order + """ + row.guid = product_category.guid + row.created_on = product_category.created_on + row.created_by = product_category.created_by + """ + return row + def to_json(self): + return { + 'id_category': self.id_category, + 'code': self.code, + 'name': self.name, + 'description': self.description, + 'id_access_level_required': self.id_access_level_required, + 'active': av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'), + 'display_order': self.display_order, + 'guid': self.guid, + } + """ + 'created_on': self.created_on, + 'created_by': self.created_by + """ diff --git a/business_objects/store/product_permutation.py b/business_objects/store/product_permutation.py index 8354a4c4..ee9285f2 100644 --- a/business_objects/store/product_permutation.py +++ b/business_objects/store/product_permutation.py @@ -13,7 +13,8 @@ Business object for product permutation # internal import lib.argument_validation as av from lib import data_types -from forms.forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation +from forms.forms import Form_Basket_Add, Form_Basket_Edit +from business_objects.store.currency import Currency from business_objects.store.delivery_option import Delivery_Option from business_objects.store.discount import Discount from business_objects.store.image import Image @@ -22,42 +23,91 @@ from business_objects.store.stock_item import Stock_Item from business_objects.store.store_base import Store_Base from business_objects.store.product_variation import Product_Variation from business_objects.store.product_variation_tree import Product_Variation_Tree +from business_objects.unit_measurement import Unit_Measurement from extensions import db # external from datetime import datetime, timedelta import locale from dataclasses import dataclass +from typing import ClassVar class Product_Permutation(db.Model, Store_Base): - FLAG_QUANTITY_STOCK = 'quantity-stock' - FLAG_QUANTITY_MIN = 'quantity-min' - FLAG_QUANTITY_MAX = 'quantity-max' - FLAG_COST_LOCAL = 'cost-local' + NAME_ATTR_OPTION_VALUE = Store_Base.ATTR_ID_PRODUCT_PERMUTATION + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME + FLAG_CURRENCY_COST = f'{Currency.ATTR_ID_CURRENCY}_cost' + FLAG_CODE_CURRENCY_COST = f'{Currency.FLAG_CODE}_cost' + FLAG_SYMBOL_CURRENCY_COST = f'{Currency.FLAG_SYMBOL}_cost' + FLAG_COST_LOCAL = 'cost_local' + FLAG_PROFIT_LOCAL_MIN = 'profit_local_min' + FLAG_HAS_VARIATIONS = 'has_variations' + FLAG_LATENCY_MANUFACTURE_DAYS = 'latency_manufacture_days' + FLAG_UNIT_MEASUREMENT_QUANTITY = f'{Unit_Measurement.ATTR_ID_UNIT_MEASUREMENT}_quantity' + FLAG_SYMBOL_UNIT_MEASUREMENT_QUANTITY = f'{Unit_Measurement.FLAG_SYMBOL}_quantity' + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY = f'{Unit_Measurement.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX}_quantity' + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_QUANTITY = f'{Unit_Measurement.FLAG_NAME_SINGULAR}_quantity' + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_QUANTITY = f'{Unit_Measurement.FLAG_NAME_PLURAL}_quantity' + FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP = 'count_unit_measurement_per_quantity_step' + FLAG_QUANTITY_STOCK = 'quantity_stock' + FLAG_IS_SUBSCRIPTION = 'is_subscription' + FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = f'{Unit_Measurement.ATTR_ID_UNIT_MEASUREMENT}_interval_recurrence' + FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = f'{Unit_Measurement.FLAG_SYMBOL}_unit_measurement_interval_recurrence' + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = f'{Unit_Measurement.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX}_unit_measurement_interval_recurrence' + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = f'{Unit_Measurement.FLAG_NAME_SINGULAR}_unit_measurement_interval_recurrence' + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = f'{Unit_Measurement.FLAG_NAME_PLURAL}_unit_measurement_interval_recurrence' + FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE = 'count_interval_recurrence' + FLAG_ID_STRIPE_PRODUCT = 'id_stripe_product' + FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED = 'does_expire_faster_once_unsealed' + FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = f'{Unit_Measurement.ATTR_ID_UNIT_MEASUREMENT}_interval_expiration_unsealed' + FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = f'{Unit_Measurement.FLAG_SYMBOL}_interval_expiration_unsealed' + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = f'{Unit_Measurement.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX}_interval_expiration_unsealed' + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = f'{Unit_Measurement.FLAG_NAME_SINGULAR}_interval_expiration_unsealed' + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = f'{Unit_Measurement.FLAG_NAME_PLURAL}_interval_expiration_unsealed' + FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED = 'count_interval_expiration_unsealed' - id_product = db.Column(db.Integer, primary_key=True) id_permutation = db.Column(db.Integer, primary_key=True) + id_product = db.Column(db.Integer) + id_category = db.Column(db.Integer) # name = db.Column(db.String(255)) description = db.Column(db.String(4000)) # price_GBP_full = db.Column(db.Float) # price_GBP_min = db.Column(db.Float) + """ id_currency_cost = db.Column(db.Integer) code_currency_cost = db.Column(db.String(3)) symbol_currency_cost = db.Column(db.String(3)) + """ + # currency_cost: Currency cost_local = db.Column(db.Float) + profit_local_min = db.Column(db.Float) has_variations = db.Column(db.Boolean) - id_category = db.Column(db.Integer) - latency_manufacture = db.Column(db.Integer) + latency_manufacture_days = db.Column(db.Integer) + id_unit_measurement_quantity = db.Column(db.Integer) + symbol_unit_measurement_quantity = db.Column(db.String(50)) + symbol_is_suffix_not_prefix_unit_measurement_quantity = db.Column(db.Boolean) + name_singular_unit_measurement_quantity = db.Column(db.String(255)) + name_plural_unit_measurement_quantity = db.Column(db.String(256)) + count_unit_measurement_per_quantity_step = db.Column(db.Integer) quantity_min = db.Column(db.Float) quantity_max = db.Column(db.Float) - quantity_step = db.Column(db.Float) quantity_stock = db.Column(db.Float) - id_stripe_product = db.Column(db.String(100)) is_subscription = db.Column(db.Boolean) - name_recurrence_interval = db.Column(db.String(255)) - name_plural_recurrence_interval = db.Column(db.String(256)) - count_recurrence_interval = db.Column(db.Integer) + id_unit_measurement_interval_recurrence = db.Column(db.Integer) + symbol_unit_measurement_interval_recurrence = db.Column(db.String(50)) + symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence = db.Column(db.Boolean) + name_singular_unit_measurement_interval_recurrence = db.Column(db.String(255)) + name_plural_unit_measurement_interval_recurrence = db.Column(db.String(256)) + count_interval_recurrence = db.Column(db.Integer) + id_stripe_product = db.Column(db.String(100)) + does_expire_faster_once_unsealed = db.Column(db.Boolean) + id_unit_measurement_interval_expiration_unsealed = db.Column(db.Integer) + symbol_unit_measurement_interval_expiration_unsealed = db.Column(db.String(50)) + symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed = db.Column(db.Boolean) + name_singular_unit_measurement_interval_expiration_unsealed = db.Column(db.String(255)) + name_plural_unit_measurement_interval_expiration_unsealed = db.Column(db.String(256)) + count_interval_expiration_unsealed = db.Column(db.Integer) + has_variations = db.Column(db.Boolean) active = db.Column(db.Boolean) - display_order = db.Column(db.Integer) + # display_order = db.Column(db.Integer) can_view = db.Column(db.Boolean) can_edit = db.Column(db.Boolean) can_admin = db.Column(db.Boolean) @@ -82,41 +132,56 @@ class Product_Permutation(db.Model, Store_Base): self.stock_item_index = {} super().__init__() Store_Base.__init__(self) + self.currency_cost = None self.form_basket_add = Form_Basket_Add() self.form_basket_edit = Form_Basket_Edit() self.is_unavailable_in_currency_or_region = False # self.is_available = False self.variation_tree = None - - def from_DB_get_many_product_catalogue(query_row): - _m = 'Product_Permutation.from_DB_get_many_product_catalogue' + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): + _m = f'{cls.__name__}.from_DB_get_many_product_catalogue' v_arg_type = 'class attribute' print(f'query_row: {query_row}') - permutation = Product_Permutation() + permutation = cls() permutation.id_permutation = query_row[0] permutation.id_product = query_row[1] permutation.id_category = query_row[2] permutation.description = query_row[3] permutation.cost_local = query_row[4] - permutation.id_currency_cost = query_row[5] - permutation.code_currency_cost = query_row[6] - permutation.symbol_currency_cost = query_row[7] - # permutation.profit_local_min = query_row[8] - permutation.latency_manufacture = query_row[9] - permutation.quantity_min = query_row[10] - permutation.quantity_max = query_row[11] - permutation.quantity_step = query_row[12] - permutation.quantity_stock = query_row[13] - permutation.id_stripe_product = query_row[14] - permutation.is_subscription = av.input_bool(query_row[15], "is_subscription", _m, v_arg_type=v_arg_type) - permutation.name_recurrence_interval = query_row[16] - permutation.name_plural_recurrence_interval = query_row[17] - permutation.count_recurrence_interval = query_row[18] - permutation.active = query_row[19] - permutation.display_order = query_row[20] - permutation.can_view = av.input_bool(query_row[21], "can_view", _m, v_arg_type=v_arg_type) - permutation.can_edit = av.input_bool(query_row[22], "can_edit", _m, v_arg_type=v_arg_type) - permutation.can_admin = av.input_bool(query_row[23], "can_admin", _m, v_arg_type=v_arg_type) + permutation.currency_cost = Currency.from_DB_get_many_product_catalogue_product_permutation(query_row) + permutation.profit_local_min = query_row[8] + permutation.latency_manufacture_days = query_row[9] + permutation.id_unit_measurement_quantity = query_row[10] + permutation.symbol_unit_measurement_quantity = query_row[11] + permutation.symbol_is_suffix_not_prefix_unit_measurement_quantity = av.input_bool(query_row[12], cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY, _m, v_arg_type=v_arg_type) + permutation.name_singular_unit_measurement_quantity = query_row[13] + permutation.name_plural_unit_measurement_quantity = query_row[14] + permutation.count_unit_measurement_per_quantity_step = query_row[15] + permutation.quantity_min = query_row[16] + permutation.quantity_max = query_row[17] + permutation.quantity_stock = query_row[18] + permutation.is_subscription = av.input_bool(query_row[19], "is_subscription", _m, v_arg_type=v_arg_type) + permutation.id_unit_measurement_interval_recurrence = query_row[20] + permutation.symbol_unit_measurement_interval_recurrence = query_row[21] + permutation.symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence = av.input_bool(query_row[22], cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE, _m, v_arg_type=v_arg_type) + permutation.name_singular_unit_measurement_interval_recurrence = query_row[23] + permutation.name_plural_unit_measurement_interval_recurrence = query_row[24] + permutation.count_interval_recurrence = query_row[25] + permutation.id_stripe_product = query_row[26] + permutation.does_expire_faster_once_unsealed = av.input_bool(query_row[27], "does_expire_faster_once_unsealed", _m, v_arg_type=v_arg_type) + permutation.id_unit_measurement_interval_expiration_unsealed = query_row[28] + permutation.symbol_unit_measurement_interval_expiration_unsealed = query_row[29] + permutation.symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed = av.input_bool(query_row[30], cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED, _m, v_arg_type=v_arg_type) + permutation.name_singular_unit_measurement_interval_expiration_unsealed = query_row[31] + permutation.name_plural_unit_measurement_interval_expiration_unsealed = query_row[32] + permutation.count_interval_expiration_unsealed = query_row[33] + permutation.has_variations = av.input_bool(query_row[34], cls.FLAG_HAS_VARIATIONS, _m, v_arg_type=v_arg_type) + permutation.active = av.input_bool(query_row[35], cls.FLAG_ACTIVE, _m, v_arg_type=v_arg_type) + # permutation.display_order = query_row[27] + permutation.can_view = av.input_bool(query_row[36], "can_view", _m, v_arg_type=v_arg_type) + permutation.can_edit = av.input_bool(query_row[37], "can_edit", _m, v_arg_type=v_arg_type) + permutation.can_admin = av.input_bool(query_row[38], "can_admin", _m, v_arg_type=v_arg_type) return permutation def from_DB_Stripe_product(query_row): @@ -136,8 +201,8 @@ class Product_Permutation(db.Model, Store_Base): # permutation.price_GBP_full = query_row[1] permutation.id_stripe_product = query_row[2] permutation.is_subscription = av.input_bool(query_row[3], "is_subscription", _m, v_arg_type=v_arg_type) - permutation.name_recurrence_interval = query_row[4] - permutation.count_recurrence_interval = query_row[5] + permutation.name_singular_unit_measurement_interval_recurrence = query_row[4] + permutation.count_interval_recurrence = query_row[5] return permutation """ def from_json(json_basket_item, key_id_product, key_id_permutation): @@ -150,49 +215,102 @@ class Product_Permutation(db.Model, Store_Base): """ @classmethod def from_json(cls, json): + _m = f'{cls.__name__}.from_json' permutation = cls() - permutation.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY] - permutation.id_product = json[cls.ATTR_ID_PRODUCT] permutation.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION] - permutation.has_variations = len(json[cls.ATTR_ID_PRODUCT_VARIATION]) > 0 - if permutation.has_variations: - for jsonProductVariation in json[cls.ATTR_ID_PRODUCT_VARIATION]: - variation = Product_Variation.from_json(jsonProductVariation) - permutation.add_product_variation(variation) - permutation.quantity_stock = json[cls.FLAG_QUANTITY_STOCK] + permutation.id_product = json[cls.ATTR_ID_PRODUCT] + permutation.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY] + permutation.description = json[cls.FLAG_DESCRIPTION] + permutation.cost_local = json[cls.FLAG_COST_LOCAL] + permutation.currency_cost = Currency.from_json(json, '_cost') + permutation.profit_local_min = json[cls.FLAG_PROFIT_LOCAL_MIN] + permutation.latency_manufacture_days = json[cls.FLAG_LATENCY_MANUFACTURE_DAYS] + permutation.id_unit_measurement_quantity = json[cls.FLAG_UNIT_MEASUREMENT_QUANTITY] + permutation.symbol_unit_measurement_quantity = json.get(cls.FLAG_SYMBOL_UNIT_MEASUREMENT_QUANTITY) + permutation.symbol_is_suffix_not_prefix_unit_measurement_quantity = json.get(cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY) + permutation.name_singular_unit_measurement_quantity = json.get(cls.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_QUANTITY) + permutation.name_plural_unit_measurement_quantity = json.get(cls.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_QUANTITY) + permutation.count_unit_measurement_per_quantity_step = json[cls.FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP] permutation.quantity_min = json[cls.FLAG_QUANTITY_MIN] permutation.quantity_max = json[cls.FLAG_QUANTITY_MAX] + permutation.quantity_stock = json[cls.FLAG_QUANTITY_STOCK] + permutation.is_subscription = 1 if av.input_bool(json[cls.FLAG_IS_SUBSCRIPTION], cls.FLAG_IS_SUBSCRIPTION, _m) else 0 + permutation.id_unit_measurement_interval_recurrence = json[cls.FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE] if json[cls.FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE] != '' else None + permutation.symbol_unit_measurement_interval_recurrence = json.get(cls.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE) + permutation.symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence = json.get(cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE) + permutation.name_singular_unit_measurement_interval_recurrence = json.get(cls.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_RECURRENCE) + permutation.name_plural_unit_measurement_interval_recurrence = json.get(cls.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE) + permutation.count_interval_recurrence = json[cls.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE] if json[cls.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE] != '' else None + permutation.id_stripe_product = json[cls.FLAG_ID_STRIPE_PRODUCT] + permutation.does_expire_faster_once_unsealed = 1 if av.input_bool(json[cls.FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED], cls.FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED, _m) else 0 + permutation.id_unit_measurement_interval_expiration_unsealed = json[cls.FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED] if json[cls.FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED] != '' else None + permutation.symbol_unit_measurement_interval_expiration_unsealed = json.get(cls.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED) + permutation.symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed = json.get(cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED) + permutation.name_singular_unit_measurement_interval_expiration_unsealed = json.get(cls.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED) + permutation.name_plural_unit_measurement_interval_expiration_unsealed = json.get(cls.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED) + permutation.count_interval_expiration_unsealed = json[cls.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED] if json[cls.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED] != '' else None + permutation.has_variations = json[cls.FLAG_HAS_VARIATIONS] + permutation.active = 1 if av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, _m) else 0 + if permutation.has_variations: + permutation.variation_tree = Product_Variation_Tree.from_json_str(json[cls.FLAG_PRODUCT_VARIATIONS]) + """ + for jsonProductVariation in json[cls.FLAG_PRODUCT_VARIATIONS]: + variation = Product_Variation.from_json(jsonProductVariation) + permutation.add_product_variation(variation) + """ return permutation def to_json(self): return { - 'id_product': {self.id_product}, - 'id_permutation': {self.id_permutation}, - 'description': {self.description}, - 'id_category': {self.id_category}, - 'latency_manufacture': {self.latency_manufacture}, - 'quantity_min': {self.quantity_min}, - 'quantity_max': {self.quantity_max}, - 'quantity_step': {self.quantity_step}, - 'quantity_stock': {self.quantity_stock}, - 'id_stripe_product': {self.id_stripe_product}, - 'is_subscription': {self.is_subscription}, - 'name_recurrence_interval': {self.name_recurrence_interval}, - 'name_plural_recurrence_interval': {self.name_plural_recurrence_interval}, - 'count_recurrence_interval': {self.count_recurrence_interval}, - 'display_order': {self.display_order}, - 'can_view': {self.can_view}, - 'can_edit': {self.can_edit}, - 'can_admin': {self.can_admin}, - 'variations': {self.variations}, - 'images': {self.images}, - 'delivery_options': {self.delivery_options}, - 'prices': {self.prices} + **self.get_shared_json_attributes(self), + self.ATTR_ID_PRODUCT_PERMUTATION: self.id_permutation, + self.ATTR_ID_PRODUCT: self.id_product, + self.ATTR_ID_PRODUCT_CATEGORY: self.id_category, + self.FLAG_DESCRIPTION: self.description, + self.FLAG_COST_LOCAL: self.cost_local, + self.FLAG_CURRENCY_COST: self.currency_cost.to_json(), + self.FLAG_PROFIT_LOCAL_MIN: self.profit_local_min, + self.FLAG_LATENCY_MANUFACTURE_DAYS: self.latency_manufacture_days, + self.FLAG_UNIT_MEASUREMENT_QUANTITY: self.id_unit_measurement_quantity, + self.FLAG_SYMBOL_UNIT_MEASUREMENT_QUANTITY: self.symbol_unit_measurement_quantity, + self.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY: self.symbol_is_suffix_not_prefix_unit_measurement_quantity, + self.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_QUANTITY: self.name_singular_unit_measurement_quantity, + self.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_QUANTITY: self.name_plural_unit_measurement_quantity, + self.FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP: self.count_unit_measurement_per_quantity_step, + self.FLAG_QUANTITY_MIN: self.quantity_min, + self.FLAG_QUANTITY_MAX: self.quantity_max, + self.FLAG_QUANTITY_STOCK: self.quantity_stock, + self.FLAG_IS_SUBSCRIPTION: self.is_subscription, + self.FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.id_unit_measurement_interval_recurrence, + self.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.symbol_unit_measurement_interval_recurrence, + self.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence, + self.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.name_singular_unit_measurement_interval_recurrence, + self.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.name_plural_unit_measurement_interval_recurrence, + self.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: self.count_interval_recurrence, + self.FLAG_ID_STRIPE_PRODUCT: self.id_stripe_product, + self.FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED: self.does_expire_faster_once_unsealed, + self.FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.id_unit_measurement_interval_expiration_unsealed, + self.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.symbol_unit_measurement_interval_expiration_unsealed, + self.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed, + self.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.name_singular_unit_measurement_interval_expiration_unsealed, + self.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.name_plural_unit_measurement_interval_expiration_unsealed, + self.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: self.count_interval_expiration_unsealed, + self.FLAG_HAS_VARIATIONS: self.has_variations, + self.FLAG_ACTIVE: self.active, + self.FLAG_CAN_VIEW: self.can_view, + self.FLAG_CAN_EDIT: self.can_edit, + self.FLAG_CAN_ADMIN: self.can_admin, + self.FLAG_PRODUCT_VARIATION: [variation.to_json() for variation in self.variations], + self.FLAG_PRODUCT_IMAGE: [image.to_json() for image in self.images], + self.FLAG_DELIVERY_OPTION: [option.to_json() for option in self.delivery_options], + self.FLAG_PRODUCT_PRICE: [price.to_json() for price in self.prices], } def to_json_option(self): return { 'value': self.id_permutation, 'text': self.get_name_variations() } + def get_name(self): + return def get_name_variations(self): return self.variation_tree.get_name_variations() def is_available(self): @@ -207,10 +325,10 @@ class Product_Permutation(db.Model, Store_Base): return price.value_local_VAT_excl def output_lead_time(self): - return '1 day' if self.latency_manufacture == 1 else f'{self.latency_manufacture} days' + return '1 day' if self.latency_manufacture_days == 1 else f'{self.latency_manufacture_days} days' def output_delivery_date(self): - return (datetime.now() + timedelta(days=self.latency_manufacture)).strftime('%A, %d %B %Y') + return (datetime.now() + timedelta(days=self.latency_manufacture_days)).strftime('%A, %d %B %Y') def output_price(self, is_included_VAT): if self.is_unavailable_in_currency_or_region: @@ -252,21 +370,38 @@ class Product_Permutation(db.Model, Store_Base): """ def __repr__(self): return f'''Product_Permutation - id_product: {self.id_product} id_permutation: {self.id_permutation} - description: {self.description} + id_product: {self.id_product} id_category: {self.id_category} - latency_manufacture: {self.latency_manufacture} + description: {self.description} + cost_local: {self.cost_local} + currency_cost: {self.currency_cost} + latency_manufacture_days: {self.latency_manufacture_days} + id_unit_measurement_quantity: {self.id_unit_measurement_quantity} + symbol_unit_measurement_quantity: {self.symbol_unit_measurement_quantity} + symbol_is_suffix_not_prefix_unit_measurement_quantity: {self.symbol_is_suffix_not_prefix_unit_measurement_quantity} + name_singular_unit_measurement_quantity: {self.name_singular_unit_measurement_quantity} + name_plural_unit_measurement_quantity: {self.name_plural_unit_measurement_quantity} + count_unit_measurement_per_quantity_step: {self.count_unit_measurement_per_quantity_step} quantity_min: {self.quantity_min} quantity_max: {self.quantity_max} - quantity_step: {self.quantity_step} quantity_stock: {self.quantity_stock} - id_stripe_product: {self.id_stripe_product} is_subscription: {self.is_subscription} - name_recurrence_interval: {self.name_recurrence_interval} - name_plural_recurrence_interval: {self.name_plural_recurrence_interval} - count_recurrence_interval: {self.count_recurrence_interval} - display_order: {self.display_order} + id_unit_measurement_interval_recurrence: {self.id_unit_measurement_interval_recurrence} + symbol_unit_measurement_interval_recurrence: {self.symbol_unit_measurement_interval_recurrence} + symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence: {self.symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence} + name_singular_unit_measurement_interval_recurrence: {self.name_singular_unit_measurement_interval_recurrence} + name_plural_unit_measurement_interval_recurrence: {self.name_plural_unit_measurement_interval_recurrence} + count_interval_recurrence: {self.count_interval_recurrence} + id_stripe_product: {self.id_stripe_product} + does_expire_faster_once_unsealed: {self.does_expire_faster_once_unsealed} + id_unit_measurement_interval_expiration_unsealed: {self.id_unit_measurement_interval_expiration_unsealed} + symbol_unit_measurement_interval_expiration_unsealed: {self.symbol_unit_measurement_interval_expiration_unsealed} + symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed: {self.symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed} + name_singular_unit_measurement_interval_expiration_unsealed: {self.name_singular_unit_measurement_interval_expiration_unsealed} + name_plural_unit_measurement_interval_expiration_unsealed: {self.name_plural_unit_measurement_interval_expiration_unsealed} + count_interval_expiration_unsealed: {self.count_interval_expiration_unsealed} + has_variations: {self.has_variations} can_view: {self.can_view} can_edit: {self.can_edit} can_admin: {self.can_admin} @@ -378,3 +513,104 @@ class Permutation_Product_Variation_Link(db.Model): link.id_variation = query_row[3] return link """ + +class Product_Permutation_Temp(db.Model, Store_Base): + __tablename__: ClassVar[str] = 'Shop_Product_Permutation_Temp' + __table_args__ = { 'extend_existing': True } + id_permutation: int = db.Column(db.Integer, primary_key=True) + id_product: int = db.Column(db.Integer) + description: str = db.Column(db.String(4000)) + cost_local: float = db.Column(db.Float) + id_currency_cost: int = db.Column(db.Integer) + profit_local_min: float = db.Column(db.Float) + latency_manufacture_days: int = db.Column(db.Integer) + id_unit_measurement_quantity: int = db.Column(db.Integer) + count_unit_measurement_per_quantity_step: int = db.Column(db.Float) + quantity_min: int = db.Column(db.Integer) + quantity_max: int = db.Column(db.Integer) + quantity_stock: int = db.Column(db.Integer) + is_subscription: bool = db.Column(db.Boolean) + id_unit_measurement_interval_recurrence: int = db.Column(db.Integer) + count_interval_recurrence: int = db.Column(db.Float) + id_stripe_product: str = db.Column(db.String(50)) + does_expire_faster_once_unsealed: bool = db.Column(db.Boolean) + id_unit_measurement_interval_expiration_unsealed: int = db.Column(db.Integer) + count_interval_expiration_unsealed: int = db.Column(db.Integer) + active: bool = db.Column(db.Boolean) + guid: str = db.Column(db.String(36)) + + @classmethod + def from_product_permutation(cls, product_permutation): + row = cls() + row.id_permutation = product_permutation.id_permutation + row.id_product = product_permutation.id_product + row.description = product_permutation.description + row.cost_local = product_permutation.cost_local + row.id_currency_cost = product_permutation.currency_cost.id_currency + row.profit_local_min = product_permutation.profit_local_min + row.latency_manufacture_days = product_permutation.latency_manufacture_days + row.id_unit_measurement_quantity = product_permutation.id_unit_measurement_quantity + row.count_unit_measurement_per_quantity_step = product_permutation.count_unit_measurement_per_quantity_step + row.quantity_min = product_permutation.quantity_min + row.quantity_max = product_permutation.quantity_max + row.quantity_stock = product_permutation.quantity_stock + row.is_subscription = product_permutation.is_subscription + row.id_unit_measurement_interval_recurrence = product_permutation.id_unit_measurement_interval_recurrence + row.count_interval_recurrence = product_permutation.count_interval_recurrence + row.id_stripe_product = product_permutation.id_stripe_product + row.does_expire_faster_once_unsealed = product_permutation.does_expire_faster_once_unsealed + row.id_unit_measurement_interval_expiration_unsealed = product_permutation.id_unit_measurement_interval_expiration_unsealed + row.count_interval_expiration_unsealed = product_permutation.count_interval_expiration_unsealed + row.active = product_permutation.active + return row + def __repr__(self): + return f''' + id_permutation: {self.id_permutation} + id_product: {self.id_product} + description: {self.description} + cost_local: {self.cost_local} + id_currency_cost: {self.id_currency_cost} + profit_local_min: {self.profit_local_min} + latency_manufacture_days: {self.latency_manufacture_days} + id_unit_measurement_quantity: {self.id_unit_measurement_quantity} + {Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP}: {self.count_unit_measurement_per_quantity_step} + quantity_min: {self.quantity_min} + quantity_max: {self.quantity_max} + quantity_stock: {self.quantity_stock} + is_subscription: {self.is_subscription} + id_unit_measurement_interval_recurrence: {self.id_unit_measurement_interval_recurrence} + count_interval_recurrence: {self.count_interval_recurrence} + id_stripe_product: {self.id_stripe_product} + does_expire_faster_once_unsealed: {self.does_expire_faster_once_unsealed} + id_unit_measurement_interval_expiration_unsealed: {self.id_unit_measurement_interval_expiration_unsealed} + count_interval_expiration_unsealed: {self.count_interval_expiration_unsealed} + active: {self.active} + guid: {self.guid} + ''' + """ + def to_json(self): + return { + self.ATTR_ID_PRODUCT_PERMUTATION: int(self.id_permutation), + self.ATTR_ID_PRODUCT: int(self.id_product), + self.FLAG_DESCRIPTION: self.description, + Product_Permutation.FLAG_COST_LOCAL: float(self.cost_local), + Product_Permutation.FLAG_CURRENCY_COST: int(self.id_currency_cost), + Product_Permutation.FLAG_PROFIT_LOCAL_MIN: float(self.profit_local_min), + Product_Permutation.FLAG_LATENCY_MANUFACTURE_DAYS: int(self.latency_manufacture_days), + Product_Permutation.FLAG_UNIT_MEASUREMENT_QUANTITY: int(self.id_unit_measurement_quantity), + Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP: float(self.count_unit_measurement_per_quantity_step), + self.FLAG_QUANTITY_MIN: float(self.quantity_min), + self.FLAG_QUANTITY_MAX: float(self.quantity_max), + Product_Permutation.FLAG_QUANTITY_STOCK: float(self.quantity_stock), + Product_Permutation.FLAG_IS_SUBSCRIPTION: bool(self.is_subscription), + Product_Permutation.FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: int(self.id_unit_measurement_interval_recurrence) if self.id_unit_measurement_interval_recurrence != '' else None, + Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: float(self.count_interval_recurrence) if self.count_interval_recurrence != '' else None, + Product_Permutation.FLAG_ID_STRIPE_PRODUCT: self.id_stripe_product, + Product_Permutation.FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED: bool(self.does_expire_faster_once_unsealed), + Product_Permutation.FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: int(self.id_unit_measurement_interval_expiration_unsealed) if self.id_unit_measurement_interval_expiration_unsealed != '' else None, + Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: float(self.count_interval_expiration_unsealed) if self.count_interval_expiration_unsealed != '' else None, + self.FLAG_ACTIVE: bool(self.active), + self.FLAG_GUID: self.guid + } + """ + \ No newline at end of file diff --git a/business_objects/store/product_price.py b/business_objects/store/product_price.py index 71adab43..8f5df9f3 100644 --- a/business_objects/store/product_price.py +++ b/business_objects/store/product_price.py @@ -20,19 +20,21 @@ from dataclasses import dataclass from typing import ClassVar class Product_Price(db.Model, Store_Base): - ATTR_ID_PRODUCT_PRICE: ClassVar[str] = 'id-price' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT_PRICE + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_TEXT FLAG_VALUE_LOCAL_VAT_INCL: ClassVar[str] = 'value-local-vat-incl' FLAG_VALUE_LOCAL_VAT_EXCL: ClassVar[str] = 'value-local-vat-excl' - FLAG_DISPLAY_ORDER: ClassVar[str] = 'display-order-price' id_price = db.Column(db.Integer, primary_key=True) id_permutation = db.Column(db.Integer) id_product = db.Column(db.Integer) id_category = db.Column(db.Integer) + """ id_currency = db.Column(db.Integer) code_currency = db.Column(db.String(50)) name_currency = db.Column(db.String(255)) symbol_currency = db.Column(db.String(50)) + """ id_region = db.Column(db.Integer) value_local_VAT_incl = db.Column(db.Float) value_local_VAT_excl = db.Column(db.Float) @@ -41,18 +43,23 @@ class Product_Price(db.Model, Store_Base): def __init__(self): super().__init__() Store_Base.__init__(self) - - def from_DB_get_many_product_catalogue(query_row): + self.currency = None + self.delivery_region = None + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): # _m = 'Product_Price.from_DB_get_many_product_catalogue' - price = Product_Price() + price = cls() price.id_price = query_row[0] price.id_permutation = query_row[1] price.id_product = query_row[2] price.id_category = query_row[3] + price.currency = Currency.from_DB_get_many_product_price_and_discount_and_delivery_region(query_row) + """ price.id_currency = query_row[4] price.code_currency = query_row[5] price.name_currency = query_row[6] price.symbol_currency = query_row[7] + """ price.id_region = query_row[8] price.value_local_VAT_incl = query_row[9] price.value_local_VAT_excl = query_row[10] @@ -65,35 +72,26 @@ class Product_Price(db.Model, Store_Base): id_permutation: {self.id_permutation} id_product: {self.id_product} id_category: {self.id_category} - id_currency: {self.id_currency} - code_currency: {self.code_currency} - name_currency: {self.name_currency} - symbol_currency: {self.symbol_currency} + currency: {self.currency} id_region: {self.id_region} value_local (VAT incl): {self.value_local_VAT_incl} value_local (VAT excl): {self.value_local_VAT_excl} display_order (UID): {self.display_order} + {self.FLAG_TEXT}: {self.currency.symbol} {self.value_local_VAT_incl} ''' def to_json(self): return { - self.ATTR_ID_PRODUCT_PRICE: {self.id_price}, - self.ATTR_ID_PRODUCT_PERMUTATION: {self.id_permutation}, - self.ATTR_ID_PRODUCT: {self.id_product}, - self.ATTR_ID_PRODUCT_CATEGORY: {self.id_category}, - Currency.ATTR_ID_CURRENCY: {self.id_currency}, - Currency.FLAG_CODE: {self.code_currency}, - Currency.FLAG_NAME: {self.name_currency}, - Currency.FLAG_SYMBOL: {self.symbol_currency}, - Delivery_Region.ATTR_ID_REGION: {self.id_region}, - self.FLAG_VALUE_LOCAL_VAT_INCL: {self.value_local_VAT_incl}, - self.FLAG_VALUE_LOCAL_VAT_EXCL: {self.value_local_VAT_excl}, - self.FLAG_DISPLAY_ORDER: {self.display_order} - } - def to_json_option(self): - return { - 'value': self.id_price, - 'text': f'{self.symbol_currency} {self.value_local_VAT_incl}' + **self.get_shared_json_attributes(self), + self.ATTR_ID_PRODUCT_PRICE: self.id_price, + self.ATTR_ID_PRODUCT_PERMUTATION: self.id_permutation, + self.ATTR_ID_PRODUCT: self.id_product, + self.ATTR_ID_PRODUCT_CATEGORY: self.id_category, + self.FLAG_CURRENCY: self.currency.to_json(), + Delivery_Region.ATTR_ID_DELIVERY_REGION: self.id_region, + self.FLAG_VALUE_LOCAL_VAT_INCL: self.value_local_VAT_incl, + self.FLAG_VALUE_LOCAL_VAT_EXCL: self.value_local_VAT_excl, + self.FLAG_DISPLAY_ORDER: self.display_order } @classmethod @@ -103,11 +101,8 @@ class Product_Price(db.Model, Store_Base): price.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION] price.id_product = json[cls.ATTR_ID_PRODUCT] price.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY] - price.id_currency = json[Currency.ATTR_ID_CURRENCY] - price.code_currency = json[Currency.FLAG_CODE] - price.name_currency = json[Currency.FLAG_NAME] - price.symbol_currency = json[Currency.FLAG_SYMBOL] - price.id_region = json[Delivery_Region.ATTR_ID_REGION] + price.currency = Currency.from_json(json) + price.id_region = json[Delivery_Region.ATTR_ID_DELIVERY_REGION] price.value_local_VAT_incl = json[cls.FLAG_VALUE_LOCAL_VAT_INCL] price.value_local_VAT_excl = json[cls.FLAG_VALUE_LOCAL_VAT_EXCL] price.display_order = json[cls.FLAG_DISPLAY_ORDER] diff --git a/business_objects/store/product_variation.py b/business_objects/store/product_variation.py index e6782677..d359cc98 100644 --- a/business_objects/store/product_variation.py +++ b/business_objects/store/product_variation.py @@ -19,124 +19,103 @@ Business object for product variation # internal import lib.argument_validation as av from business_objects.store.store_base import Store_Base +from business_objects.store.product_variation_type import Product_Variation_Type from extensions import db # external from dataclasses import dataclass from typing import ClassVar from pydantic import BaseModel +from itertools import filterfalse +from operator import attrgetter -# CLASSES class Product_Variation(db.Model, Store_Base): - KEY_ACTIVE_VARIATION: ClassVar[str] = 'active_variation' - KEY_ACTIVE_VARIATION_TYPE: ClassVar[str] = 'active_variation_type' - KEY_CODE_VARIATION: ClassVar[str] = 'code_variation' - KEY_CODE_VARIATION_TYPE: ClassVar[str] = 'code_variation_type' - KEY_DISPLAY_ORDER_VARIATION: ClassVar[str] = 'display_order_variation' - KEY_DISPLAY_ORDER_VARIATION_TYPE: ClassVar[str] = 'display_order_variation_type' - KEY_NAME_VARIATION: ClassVar[str] = 'name_variation' - KEY_NAME_VARIATION_TYPE: ClassVar[str] = 'name_variation_type' - + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT_VARIATION + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME + id_variation = db.Column(db.Integer, primary_key=True) - code_variation = db.Column(db.String(50)) - name_variation = db.Column(db.String(255)) - active_variation = db.Column(db.Boolean) - display_order_variation = db.Column(db.Integer) id_type = db.Column(db.Integer) - code_variation_type = db.Column(db.String(50)) - name_variation_type = db.Column(db.String(255)) - name_plural_variation_type = db.Column(db.String(255)) - active_variation_type = db.Column(db.Boolean) - display_order_variation_type = db.Column(db.Integer) - id_product = db.Column(db.Integer) - id_permutation = db.Column(db.Integer) - id_category = db.Column(db.Integer) + code = db.Column(db.String(50)) + name = db.Column(db.String(255)) + display_order = db.Column(db.Integer) + active = db.Column(db.Boolean) + id_permutation = db.Column(db.Integer) + id_product = db.Column(db.Integer) + id_category = db.Column(db.Integer) + def __init__(self): super().__init__() - Store_Base.__init__(self) + self.variation_type = None - def from_DB_get_many_product_catalogue(query_row): - variation = Product_Variation.from_DB_variation(query_row) + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): + variation = Product_Variation.from_DB_get_many_product_variation(query_row) variation.id_product = query_row[11] variation.id_permutation = query_row[12] variation.id_category = query_row[13] + variation.variation_type = Product_Variation_Type.from_DB_get_many_product_catalogue(query_row) return variation - def from_DB_variation(query_row): - _m = 'Product_Variation.from_DB_variation' - variation = Product_Variation() + @classmethod + def from_DB_get_many_product_variation(cls, query_row): + variation = cls() variation.id_variation = query_row[0] - variation.code_variation = query_row[1] - variation.name_variation = query_row[2] - variation.active_variation = av.input_bool(query_row[3], 'active_variation', _m) - variation.display_order_variation = query_row[4] - variation.id_type = query_row[5] - variation.code_variation_type = query_row[6] - variation.name_variation_type = query_row[7] - variation.name_plural_variation_type = query_row[8] - variation.active_variation_type = av.input_bool(query_row[9], 'active_variation', _m) - variation.display_order_variation_type = query_row[10] + variation.id_type = query_row[1] + variation.code = query_row[2] + variation.name = query_row[3] + variation.display_order = query_row[4] + variation.active = av.input_bool(query_row[5], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_get_many_product_variation') return variation @classmethod def from_json(cls, json): variation = cls() - variation.id_variation = json[cls.ATTR_ID_VARIATION] + variation.id_variation = json[cls.ATTR_ID_PRODUCT_VARIATION] + variation.code = json[cls.FLAG_CODE] + variation.name = json[cls.FLAG_NAME] + variation.display_order = json[cls.FLAG_DISPLAY_ORDER] + variation.active = json[cls.FLAG_ACTIVE] + variation.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION] variation.id_product = json[cls.ATTR_ID_PRODUCT] - variation.id_permutation = json[cls.ATTR_ID_PERMUTATION] - variation.id_category = json[cls.ATTR_ID_CATEGORY] - variation.name_variation_type = json[cls.KEY_NAME_VARIATION_TYPE] - variation.name_variation = json[cls.KEY_NAME_VARIATION] + variation.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY] return variation def __repr__(self): return f''' - id: {self.id_variation} - id_product: {self.id_product} + {self.__class__.__name__} + id_variation: {self.id_variation} + id_type: {self.id_type} + code: {self.code} + name: {self.name} + display_order: {self.display_order} + active: {self.active} id_permutation: {self.id_permutation} + id_product: {self.id_product} id_category: {self.id_category} - code_variation_type: {self.code_variation_type} - name_variation_type: {self.name_variation_type} - code_variation: {self.code_variation} - name_variation: {self.name_variation} - active_variation: {self.active_variation} - active_variation_type: {self.active_variation_type} - display_order_variation: {self.display_order_variation} - display_order_variation_type: {self.display_order_variation_type} + variation_type: {self.variation_type} ''' def to_json(self): return { + **self.get_shared_json_attributes(self), self.ATTR_ID_PRODUCT_VARIATION: self.id_variation, + self.ATTR_ID_PRODUCT_VARIATION_TYPE: self.id_type, + self.FLAG_CODE: self.code, + self.FLAG_NAME: self.name, + self.FLAG_DISPLAY_ORDER: self.display_order, + self.FLAG_ACTIVE: self.active, self.ATTR_ID_PRODUCT: self.id_product, self.ATTR_ID_PRODUCT_PERMUTATION: self.id_permutation, self.ATTR_ID_PRODUCT_CATEGORY: self.id_category, - self.ATTR_ID_PRODUCT_VARIATION_TYPE: self.id_type, - self.KEY_CODE_VARIATION_TYPE: self.code_variation_type, - self.KEY_CODE_VARIATION: self.code_variation, - self.KEY_DISPLAY_ORDER_VARIATION_TYPE: self.display_order_variation_type, - self.KEY_DISPLAY_ORDER_VARIATION: self.display_order_variation, - self.KEY_NAME_VARIATION_TYPE: self.name_variation_type, - self.KEY_NAME_VARIATION: self.name_variation, - self.KEY_ACTIVE_VARIATION_TYPE: self.active_variation_type, - self.KEY_ACTIVE_VARIATION: self.active_variation, } def to_json_option(self): return { 'value': self.id_variation, - 'text': self.name_variation - } - - def to_json_variation_type(self): - return { - self.ATTR_ID_PRODUCT_VARIATION_TYPE: self.id_type, - self.KEY_CODE_VARIATION_TYPE: self.code_variation_type, - self.KEY_DISPLAY_ORDER_VARIATION_TYPE: self.display_order_variation_type, - self.KEY_NAME_VARIATION_TYPE: self.name_variation_type, - self.KEY_ACTIVE_VARIATION_TYPE: self.active_variation_type, + 'text': self.name } + @dataclass class Product_Variation_Filters(): get_all_variation_type: bool @@ -198,30 +177,35 @@ class Product_Variation_Filters(): get_first_variation = False, ids_variation = '' ) - -class Product_Variation_List(BaseModel): + + +class Product_Variation_Container(BaseModel): + variation_types: list = [] variations: list = [] + def add_product_variation_type(self, variation_type): + av.val_instance(variation_type, 'variation_type', 'Product_Variation_Container.add_product_variation_type', Product_Variation_Type) + self.variations.append(variation_type) def add_product_variation(self, variation): - av.val_instance(variation, 'variation', 'Product_Variation_List.add_product_variation', Product_Variation) + av.val_instance(variation, 'variation', 'Product_Variation_Container.add_product_variation', Product_Variation) + if variation.variation_type is None: + variation_type = next(filterfalse(lambda x: x.id_type != variation.id_type, self.variation_types), None) + if variation_type is not None: + variation.variation_type = variation_type self.variations.append(variation) def __repr__(self): - return f'variations: {self.variations}' + return f'Product_Variation_Container:\nvariations_types: {self.variation_types}\nvariations: {self.variations}' - def to_list_variations(self): + def to_list_variation_options(self): list_variations = [] for variation in self.variations: - list_variations.append(variation.to_json()) + list_variations.append(variation.to_json_option()) print(f'list_variations: {list_variations}') return list_variations - - def to_list_variation_types(self): + def to_list_variation_type_options(self): list_variation_types = [] - list_variation_ids = [] - for variation in self.variations: - if variation.id_type not in list_variation_ids: - list_variation_ids.append(variation.id_type) - list_variation_types.append(variation.to_json_variation_type()) + for variation_type in self.variation_types: + list_variation_types.append(variation_type.to_json_option()) return list_variation_types \ No newline at end of file diff --git a/business_objects/store/product_variation_tree.py b/business_objects/store/product_variation_tree.py index 51910d6f..392c8798 100644 --- a/business_objects/store/product_variation_tree.py +++ b/business_objects/store/product_variation_tree.py @@ -55,20 +55,42 @@ class Product_Variation_Tree(): is_equal = (sz_me == sz_other) if is_equal: for index_type in range(sz_me): - if sz_me[index_type] != sz_other[index_type]: + if my_type_list[index_type] != other_type_list[index_type]: is_equal = False break return is_equal - def from_product_permutation(product_permutation): + @classmethod + def from_product_permutation(cls, product_permutation): depth_max = len(product_permutation.variations) node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_permutation.variations[0], None) node = node_root for depth in range(depth_max - 1): node = Product_Variation_Tree_Node.from_variation_and_node_parent(product_permutation.variations[depth + 1], node) - return Product_Variation_Tree.from_node_root(node_root) - def from_product_variation(product_variation): + return cls.from_node_root(node_root) + @classmethod + def from_product_variation(cls, product_variation): node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_variation, None) - return Product_Variation_Tree.from_node_root(node_root) + return cls.from_node_root(node_root) + @classmethod + def from_product_variations(cls, product_variations): + node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_variations[0], None) + tree = cls.from_node_root(node_root) + if len(product_variations) > 1: + for variation in product_variations[1:]: + tree.add_product_variation(variation) + return tree + @classmethod + def from_json_str(cls, json_str): + variations = [] + for json_variation in json_str.split(','): + parts = json_variation.split(':') + if len(parts) != 2: continue + variation = Product_Variation() + variation.id_type = parts[0] + variation.id_variation = parts[1] + variations.append(variation) + return cls.from_product_variations(variations) + """ def get_name_variations(self): node = self.node_root name = node.variation.name_variation_type @@ -78,6 +100,7 @@ class Product_Variation_Tree(): name += f', {node.variation.name_variation_type}' at_leaf_node = node.is_leaf() return name + """ def get_node_leaf(self): node = self.node_root at_leaf_node = node.is_leaf() @@ -102,8 +125,64 @@ class Product_Variation_Tree(): variations = [] node = self.node_root at_leaf_node = node.is_leaf() + variations.append(node.variation) while not at_leaf_node: - variations.append(node.variation) node = node.nodes_child[0] at_leaf_node = node.is_leaf() - return variations \ No newline at end of file + variations.append(node.variation) + return variations + def to_preview_str(self): + print(f'Product_Variation_Tree.to_preview_str') + variations = self.get_product_variations() + print(f'variations: {variations}') + preview_str = '' + for variation in variations: + is_first = (preview_str == '') + preview_str += f'{variation.variation_type.name_singular}: {variation.name}' + if is_first: + preview_str += '\n' + print(f'preview_str: {preview_str}') + return preview_str + def to_json(self): + variations = self.get_product_variations() + json_variations = [] + for variation in variations: + json_variations.append(variation.to_json()) + return json_variations + def to_variation_id_pairs_str(self): + variations = self.get_product_variations() + pairs_str = '' + for variation in variations: + pairs_str += f'{variation.id_type}:{variation.id_variation},' + return pairs_str +""" +class Product_Variation_Container(BaseModel): + variation_types: list = [] + variations: list = [] + + def add_product_variation_type(self, variation_type): + av.val_instance(variation_type, 'variation_type', 'Product_Variation_Container.add_product_variation_type', Product_Variation_Type) + self.variations.append(variation_type) + def add_product_variation(self, variation): + av.val_instance(variation, 'variation', 'Product_Variation_Container.add_product_variation', Product_Variation) + if variation.variation_type is None: + variation_type = next(filterfalse(lambda x: x.id_type != variation.id_type, self.variation_types), None) + if variation_type is not None: + variation.variation_type = variation_type + self.variations.append(variation) + + def __repr__(self): + return f'Product_Variation_Container:\nvariations_types: {self.variation_types}\nvariations: {self.variations}' + + def to_list_variation_options(self): + list_variations = [] + for variation in self.variations: + list_variations.append(variation.to_json_option()) + print(f'list_variations: {list_variations}') + return list_variations + def to_list_variation_type_options(self): + list_variation_types = [] + for variation_type in self.variation_types: + list_variation_types.append(variation_type.to_json_option()) + return list_variation_types +""" \ No newline at end of file diff --git a/business_objects/store/product_variation_type.py b/business_objects/store/product_variation_type.py new file mode 100644 index 00000000..2b77562e --- /dev/null +++ b/business_objects/store/product_variation_type.py @@ -0,0 +1,103 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Business Objects +Feature: Product Product_Variation Business Object + +Description: +Business object for product variation +""" + +# IMPORTS +# VARIABLE INSTANTIATION +# CLASSES +# METHODS + +# IMPORTS +# internal +import lib.argument_validation as av +from business_objects.store.store_base import Store_Base +from extensions import db +# external +from dataclasses import dataclass +from typing import ClassVar +from pydantic import BaseModel +from itertools import filterfalse +from operator import attrgetter + +class Product_Variation_Type(db.Model, Store_Base): + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT_VARIATION_TYPE + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME_SINGULAR + + id_type = db.Column(db.Integer, primary_key=True) + code = db.Column(db.String(50)) + name_singular = db.Column(db.String(255)) + name_plural = db.Column(db.String(255)) + display_order = db.Column(db.Integer) + active = db.Column(db.Boolean) + + def __init__(self): + super().__init__() + + @classmethod + def from_DB_get_many_product_catalogue(cls, query_row): + variation_type = cls() + variation_type.id_type = query_row[1] + variation_type.code = query_row[6] + variation_type.name_singular = query_row[7] + variation_type.name_plural = query_row[8] + variation_type.display_order = query_row[9] + variation_type.active = av.input_bool(query_row[10], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_get_many_product_catalogue') + return variation_type + + @classmethod + def from_DB_get_many_product_variation(cls, query_row): + variation_type = cls() + variation_type.id_type = query_row[0] + variation_type.code = query_row[1] + variation_type.name_singular = query_row[2] + variation_type.name_plural = query_row[3] + variation_type.display_order = query_row[4] + variation_type.active = av.input_bool(query_row[5], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_get_many_product_variation') + return variation_type + + @classmethod + def from_json(cls, json): + variation_type = cls() + variation_type.id_type = json[cls.ATTR_ID_PRODUCT_VARIATION_TYPE] + variation_type.code = json[cls.FLAG_CODE] + variation_type.name_singular = json[cls.FLAG_NAME_SINGULAR] + variation_type.name_plural = json[cls.FLAG_NAME_PLURAL] + variation_type.display_order = json[cls.FLAG_DISPLAY_ORDER] + variation_type.active = json[cls.FLAG_ACTIVE] + return variation_type + + def __repr__(self): + return f''' + {self.__class__.__name__} + id_type: {self.id_type} + code: {self.code} + name_singular: {self.name_singular} + name_plural: {self.name_plural} + display_order: {self.display_order} + active: {self.active} + ''' + + def to_json(self): + return { + **self.get_shared_json_attributes(self), + self.ATTR_ID_PRODUCT_VARIATION_TYPE: self.id_type, + self.FLAG_CODE: self.code, + self.FLAG_NAME_SINGULAR: self.name_singular, + self.FLAG_NAME_PLURAL: self.name_plural, + self.FLAG_DISPLAY_ORDER: self.display_order, + self.FLAG_ACTIVE: self.active, + } + def to_json_option(self): + return { + 'value': self.id_type, + 'text': self.name_singular + } + diff --git a/business_objects/store/stock_item.py b/business_objects/store/stock_item.py index 65b5e41a..9db66e44 100644 --- a/business_objects/store/stock_item.py +++ b/business_objects/store/stock_item.py @@ -24,6 +24,8 @@ from datetime import datetime class Stock_Item(db.Model, Store_Base): ATTR_ID_CURRENCY_COST: ClassVar[str] = f'{Store_Base.ATTR_ID_CURRENCY}-cost' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_CURRENCY + NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME FLAG_DATE_CONSUMED: ClassVar[str] = 'date-consumed' FLAG_DATE_EXPIRATION: ClassVar[str] = 'date-expiration' FLAG_DATE_PURCHASED: ClassVar[str] = 'date-purchased' @@ -175,6 +177,7 @@ class Stock_Item(db.Model, Store_Base): ''' def to_json(self): return { + **self.get_shared_json_attributes(self), self.ATTR_ID_PRODUCT: {self.id_product}, self.ATTR_ID_PRODUCT_CATEGORY: {self.id_category}, self.FLAG_NAME: {self.name}, @@ -183,8 +186,8 @@ class Stock_Item(db.Model, Store_Base): self.FLAG_CAN_EDIT: {self.can_edit}, self.FLAG_CAN_ADMIN: {self.can_admin}, self.FLAG_HAS_VARIATIONS: {self.has_variations}, - self.FLAG_PERMUTATIONS: {self.permutations}, - self.FLAG_VARIATION_TREES: {self.variation_trees}, + self.FLAG_PRODUCT_PERMUTATION: {self.permutations}, + self.FLAG_PRODUCT_VARIATION_TREES: {self.variation_trees}, } def has_permutations(self): return len(self.permutations) > 0 diff --git a/business_objects/store/store_base.py b/business_objects/store/store_base.py index 67a40d03..904c3308 100644 --- a/business_objects/store/store_base.py +++ b/business_objects/store/store_base.py @@ -12,6 +12,7 @@ Abstract business object for store objects # internal # from helpers.DEPRECATED.helper_abc import Interface_ABC +from business_objects.base import Base from extensions import db import lib.argument_validation as av # external @@ -55,40 +56,33 @@ class I_Store_Base(): "" """ -class Store_Base(): - ATTR_ID_ACCESS_LEVEL: ClassVar[str] = 'id_access_level' - ATTR_ID_CURRENCY: ClassVar[str] = 'id_currency' +class Store_Base(Base): # ATTR_ID_CURRENCY_COST: ClassVar[str] = 'id_currency_cost' - ATTR_ID_DELIVERY_REGION: ClassVar[str] = 'id_delivery_region' ATTR_ID_DISCOUNT: ClassVar[str] = 'id_discount' ATTR_ID_IMAGE: ClassVar[str] = 'id_image' ATTR_ID_LOCATION_STORAGE: ClassVar[str] = 'id_location_storage' ATTR_ID_PRODUCT: ClassVar[str] = 'id_product' ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = 'id_category' + ATTR_ID_PRODUCT_IMAGE: ClassVar[str] = 'id_image' ATTR_ID_PRODUCT_PERMUTATION: ClassVar[str] = 'id_permutation' ATTR_ID_PRODUCT_PRICE: ClassVar[str] = 'id_price' ATTR_ID_PRODUCT_VARIATION: ClassVar[str] = 'id_variation' - ATTR_ID_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'id_variation_type' + ATTR_ID_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'id_type' ATTR_ID_STOCK_ITEM: ClassVar[str] = 'id_stock_item' - FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = 'access_level_required' - FLAG_ACTIVE: ClassVar[str] = 'active' - FLAG_CAN_ADMIN: ClassVar[str] = 'can_admin' - FLAG_CAN_EDIT: ClassVar[str] = 'can_edit' - FLAG_CAN_VIEW: ClassVar[str] = 'can_view' - FLAG_CODE: ClassVar[str] = 'code' - FLAG_DESCRIPTION: ClassVar[str] = 'description' - FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order' + FLAG_CURRENCY: ClassVar[str] = 'currency' + FLAG_DELIVERY_OPTION: ClassVar[str] = 'delivery_option' FLAG_HAS_VARIATIONS: ClassVar[str] = 'has_variations' - FLAG_IS_NOT_EMPTY: ClassVar[str] = 'is_not_empty' - FLAG_KEY_PRIMARY: ClassVar[str] = 'key_primary' - FLAG_NAME: ClassVar[str] = 'name' - FLAG_PERMUTATIONS: ClassVar[str] = 'permutations' - FLAG_PRIORITY: ClassVar[str] = 'priority' - FLAG_ROWS: ClassVar[str] = 'rows' - FLAG_VARIATION_TREES: ClassVar[str] = 'variation_trees' - @classmethod - def output_bool(cls, value): - return av.input_bool(value, f'{cls.__name__} bool attribute', f'{cls.__name__}.output_bool') - @staticmethod - def convert_list_objects_to_list_options(objects): - return [object.to_json_option() for object in objects] + FLAG_IS_OUT_OF_STOCK: ClassVar[str] = 'is_out_of_stock' + FLAG_PRODUCT: ClassVar[str] = 'product' + FLAG_PRODUCT_CATEGORY: ClassVar[str] = 'product_category' + FLAG_PRODUCT_IMAGE: ClassVar[str] = 'product_image' + FLAG_PRODUCT_PERMUTATION: ClassVar[str] = 'product_permutation' + FLAG_PRODUCT_PRICE: ClassVar[str] = 'product_price' + FLAG_PRODUCT_VARIATION: ClassVar[str] = 'product_variation' + FLAG_PRODUCT_VARIATIONS: ClassVar[str] = f'{FLAG_PRODUCT_VARIATION}s' + FLAG_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'product_variation_type' + FLAG_QUANTITY_MIN: ClassVar[str] = 'quantity_min' + FLAG_QUANTITY_MAX: ClassVar[str] = 'quantity_max' + FLAG_TEXT: ClassVar[str] = 'text' + FLAG_VALUE_TEXT: ClassVar[str] = 'value_text' + \ No newline at end of file diff --git a/business_objects/unit_measurement.py b/business_objects/unit_measurement.py new file mode 100644 index 00000000..ffa91077 --- /dev/null +++ b/business_objects/unit_measurement.py @@ -0,0 +1,160 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Business Objects +Feature: Unit of Measurement Business Object +""" + +# internal +from business_objects.base import Base +from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base +from extensions import db +# from forms.forms import Form_Filters_User +import lib.argument_validation as av +# external +from dataclasses import dataclass +from typing import ClassVar + + +class Unit_Measurement(SQLAlchemy_ABC, Base): + ATTR_ID_UNIT_MEASUREMENT: ClassVar[str] = 'id_unit_measurement' + FLAG_IS_BASE_UNIT: ClassVar[str] = 'is_base_unit' + FLAG_IS_UNIT_OF_DISTANCE: ClassVar[str] = 'is_unit_of_distance' + FLAG_IS_UNIT_OF_MASS: ClassVar[str] = 'is_unit_of_mass' + FLAG_IS_UNIT_OF_TIME: ClassVar[str] = 'is_unit_of_time' + FLAG_IS_UNIT_OF_VOLUME: ClassVar[str] = 'is_unit_of_volume' + FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural' + FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular' + FLAG_SYMBOL: ClassVar[str] = 'symbol' + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX: ClassVar[str] = 'symbol_is_suffix_not_prefix' + # KEY_UNIT_MEASUREMENT: ClassVar[str] = 'unit_of_measurement' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_UNIT_MEASUREMENT + NAME_ATTR_OPTION_TEXT: ClassVar[str] = FLAG_NAME_SINGULAR + + id_unit_measurement = db.Column(db.Integer, primary_key=True) + name_singular = db.Column(db.String(255)) + name_plural = db.Column(db.String(256)) + symbol = db.Column(db.String(50)) + symbol_is_suffix_not_prefix = db.Column(db.Boolean) + is_base_unit = db.Column(db.Boolean) + is_unit_of_distance = db.Column(db.Boolean) + is_unit_of_mass = db.Column(db.Boolean) + is_unit_of_time = db.Column(db.Boolean) + is_unit_of_volume = db.Column(db.Boolean) + active = db.Column(db.Boolean) + + def from_DB_unit_measurement(query_row): + _m = 'Unit_Measurement.from_DB_unit_measurement' + unit = Unit_Measurement() + unit.id_unit_measurement = query_row[0] + unit.name_singular = query_row[1] + unit.name_plural = query_row[2] + unit.symbol = query_row[3] + unit.symbol_is_suffix_not_prefix = av.input_bool(query_row[4], 'symbol_is_suffix_not_prefix', _m) + unit.is_base_unit = av.input_bool(query_row[5], 'is_base_unit', _m) + unit.is_unit_of_distance = av.input_bool(query_row[6], 'is_unit_of_distance', _m) + unit.is_unit_of_mass = av.input_bool(query_row[7], 'is_unit_of_mass', _m) + unit.is_unit_of_time = av.input_bool(query_row[8], 'is_unit_of_time', _m) + unit.is_unit_of_volume = av.input_bool(query_row[9], 'is_unit_of_volume', _m) + unit.active = av.input_bool(query_row[10], 'active', _m) + return unit + + def to_json(self): + return { + **self.get_shared_json_attributes(self), + self.ATTR_ID_UNIT_MEASUREMENT: self.id_unit_measurement, + self.FLAG_NAME_SINGULAR: self.name_singular, + self.FLAG_NAME_PLURAL: self.name_plural, + self.FLAG_SYMBOL: self.symbol, + self.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX: self.symbol_is_suffix_not_prefix, + self.FLAG_IS_BASE_UNIT: self.is_base_unit, + self.FLAG_IS_UNIT_OF_DISTANCE: self.is_unit_of_distance, + self.FLAG_IS_UNIT_OF_MASS: self.is_unit_of_mass, + self.FLAG_IS_UNIT_OF_TIME: self.is_unit_of_time, + self.FLAG_IS_UNIT_OF_VOLUME: self.is_unit_of_volume, + self.FLAG_ACTIVE: self.active, + } + @classmethod + def from_json(cls, json): + print(f' Unit_Measurement.from_json: {json}') + unit = cls() + unit.id_unit_measurement = json[cls.ATTR_ID_UNIT_MEASUREMENT] + unit.name_singular = json[cls.FLAG_NAME_SINGULAR] + unit.name_plural = json[cls.FLAG_NAME_PLURAL] + unit.symbol = json[cls.FLAG_SYMBOL] + unit.symbol_is_suffix_not_prefix = json[cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX] + unit.is_base_unit = json[cls.FLAG_IS_BASE_UNIT] + unit.is_unit_of_distance = json[cls.FLAG_IS_UNIT_OF_DISTANCE] + unit.is_unit_of_mass = json[cls.FLAG_IS_UNIT_OF_MASS] + unit.is_unit_of_time = json[cls.FLAG_IS_UNIT_OF_TIME] + unit.is_unit_of_volume = json[cls.FLAG_IS_UNIT_OF_VOLUME] + unit.active = json[cls.FLAG_ACTIVE] + return unit + + def __repr__(self): + return f''' + id_unit_of_measurement: {self.id_unit_measurement}, + name_singular: {self.name_singular}, + name_plural: {self.name_plural}, + symbol: {self.symbol}, + symbol_is_suffix_not_prefix: {self.symbol_is_suffix_not_prefix}, + is_base_unit: {self.is_base_unit}, + is_unit_of_distance: {self.is_unit_of_distance}, + is_unit_of_mass: {self.is_unit_of_mass}, + is_unit_of_time: {self.is_unit_of_time}, + is_unit_of_volume: {self.is_unit_of_volume}, + active: {self.active} + ''' + +""" +@dataclass +class Filters_Unit_Measurement(): + active_only: bool = False + + def to_json(self): + return { + **self.get_shared_json_attributes(self), + 'a_get_all_user': self.get_all_user, + 'a_get_inactive_user': self.get_inactive_user, + 'a_get_first_user_only': self.get_first_user_only, + 'a_ids_user': self.ids_user, + 'a_ids_user_auth0': self.ids_user_auth0, + } + + @staticmethod + def from_form(form): + av.val_instance(form, 'form', 'User_Filters.from_form', Form_Filters_User) + get_inactive = av.input_bool(form.active.data, "active", "User_Filters.from_form") + id_user = form.id_user.data + return User_Filters( + get_all_user = (id_user is None), + get_inactive_user = get_inactive, + get_first_user_only = False, + ids_user = id_user, + ids_user_auth0 = '', + ) + + @staticmethod + def from_user(user): + av.val_instance(user, 'user', 'User_Filters.from_user', User) + return User_Filters( + get_all_user = (user.id_user is None and user.id_user_auth0 is None), + get_inactive_user = False, + get_first_user_only = False, + ids_user = user.id_user, + ids_user_auth0 = user.id_user_auth0, + ) + + @staticmethod + def get_default(datastore_store): + user = datastore_store.get_login_user() + return User_Filters( + get_all_user = False, + get_inactive_user = False, + get_first_user_only = False, + ids_user = user.id_user, + ids_user_auth0 = '', + ) +""" \ No newline at end of file diff --git a/business_objects/user.py b/business_objects/user.py index a55331ca..9b15cbe5 100644 --- a/business_objects/user.py +++ b/business_objects/user.py @@ -8,6 +8,7 @@ Feature: User Business Object """ # internal +from business_objects.base import Base import lib.argument_validation as av from forms.forms import Form_Filters_User from extensions import db @@ -16,8 +17,10 @@ from dataclasses import dataclass from typing import ClassVar -class User(db.Model): +class User(db.Model, Base): KEY_USER: ClassVar[str] = 'authorisedUser' # 'user' already used + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_USER + NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'email' id_user = db.Column(db.Integer, primary_key=True) id_user_auth0 = db.Column(db.String(255)) @@ -200,8 +203,9 @@ class User_Filters(): ids_access_level: str ids_product: str - def to_json(self): + def to_json(self): return { + **self.get_shared_json_attributes(self), 'a_ids_user': self.ids_user, 'a_get_inactive_users': self.get_inactive_users, 'a_ids_permission': self.ids_permission, diff --git a/routing/__init__.py b/controllers/__init__.py similarity index 100% rename from routing/__init__.py rename to controllers/__init__.py diff --git a/routing/__pycache__/__init__.cpython-312.pyc b/controllers/__pycache__/__init__.cpython-312.pyc similarity index 100% rename from routing/__pycache__/__init__.cpython-312.pyc rename to controllers/__pycache__/__init__.cpython-312.pyc diff --git a/controllers/__pycache__/core.cpython-312.pyc b/controllers/__pycache__/core.cpython-312.pyc new file mode 100644 index 00000000..5c685fa2 Binary files /dev/null and b/controllers/__pycache__/core.cpython-312.pyc differ diff --git a/routing/__pycache__/legal.cpython-312.pyc b/controllers/__pycache__/legal.cpython-312.pyc similarity index 100% rename from routing/__pycache__/legal.cpython-312.pyc rename to controllers/__pycache__/legal.cpython-312.pyc diff --git a/routing/__pycache__/store.cpython-312.pyc b/controllers/__pycache__/store.cpython-312.pyc similarity index 100% rename from routing/__pycache__/store.cpython-312.pyc rename to controllers/__pycache__/store.cpython-312.pyc diff --git a/routing/__pycache__/store_product_category.cpython-312.pyc b/controllers/__pycache__/store_product_category.cpython-312.pyc similarity index 100% rename from routing/__pycache__/store_product_category.cpython-312.pyc rename to controllers/__pycache__/store_product_category.cpython-312.pyc diff --git a/routing/__pycache__/store_product_permutation.cpython-312.pyc b/controllers/__pycache__/store_product_permutation.cpython-312.pyc similarity index 100% rename from routing/__pycache__/store_product_permutation.cpython-312.pyc rename to controllers/__pycache__/store_product_permutation.cpython-312.pyc diff --git a/routing/__pycache__/store_stock_item.cpython-312.pyc b/controllers/__pycache__/store_stock_item.cpython-312.pyc similarity index 100% rename from routing/__pycache__/store_stock_item.cpython-312.pyc rename to controllers/__pycache__/store_stock_item.cpython-312.pyc diff --git a/routing/__pycache__/store_supplier.cpython-312.pyc b/controllers/__pycache__/store_supplier.cpython-312.pyc similarity index 100% rename from routing/__pycache__/store_supplier.cpython-312.pyc rename to controllers/__pycache__/store_supplier.cpython-312.pyc diff --git a/routing/__pycache__/user.cpython-312.pyc b/controllers/__pycache__/user.cpython-312.pyc similarity index 100% rename from routing/__pycache__/user.cpython-312.pyc rename to controllers/__pycache__/user.cpython-312.pyc diff --git a/routing/core.py b/controllers/core.py similarity index 93% rename from routing/core.py rename to controllers/core.py index d8a15b78..a881a683 100644 --- a/routing/core.py +++ b/controllers/core.py @@ -12,6 +12,7 @@ Initializes the Flask application, sets the configuration based on the environme # IMPORTS # internal +from datastores.datastore_base import DataStore_Base from forms.forms import Form_Contact from models.model_view_admin_home import Model_View_Admin_Home from models.model_view_contact import Model_View_Contact @@ -44,7 +45,10 @@ def home(): @routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['GET']) def contact(): try: + user = DataStore_Base.get_user_session() form = Form_Contact() + form.email.data = user.email + form.name.data = user.firstname + (' ' if user.firstname and user.surname else '') + user.surname model = Model_View_Contact(form) html_body = render_template('pages/core/_contact.html', model = model) except Exception as e: diff --git a/routing/legal.py b/controllers/legal.py similarity index 100% rename from routing/legal.py rename to controllers/legal.py diff --git a/routing/store/__init__.py b/controllers/store/__init__.py similarity index 100% rename from routing/store/__init__.py rename to controllers/store/__init__.py diff --git a/routing/store/__pycache__/__init__.cpython-312.pyc b/controllers/store/__pycache__/__init__.cpython-312.pyc similarity index 100% rename from routing/store/__pycache__/__init__.cpython-312.pyc rename to controllers/store/__pycache__/__init__.cpython-312.pyc diff --git a/routing/store/__pycache__/product.cpython-312.pyc b/controllers/store/__pycache__/product.cpython-312.pyc similarity index 100% rename from routing/store/__pycache__/product.cpython-312.pyc rename to controllers/store/__pycache__/product.cpython-312.pyc diff --git a/routing/store/__pycache__/product_category.cpython-312.pyc b/controllers/store/__pycache__/product_category.cpython-312.pyc similarity index 75% rename from routing/store/__pycache__/product_category.cpython-312.pyc rename to controllers/store/__pycache__/product_category.cpython-312.pyc index 4d83af2c..487be009 100644 Binary files a/routing/store/__pycache__/product_category.cpython-312.pyc and b/controllers/store/__pycache__/product_category.cpython-312.pyc differ diff --git a/controllers/store/__pycache__/product_permutation.cpython-312.pyc b/controllers/store/__pycache__/product_permutation.cpython-312.pyc new file mode 100644 index 00000000..9f4ee3cd Binary files /dev/null and b/controllers/store/__pycache__/product_permutation.cpython-312.pyc differ diff --git a/controllers/store/__pycache__/stock_item.cpython-312.pyc b/controllers/store/__pycache__/stock_item.cpython-312.pyc new file mode 100644 index 00000000..ecd68242 Binary files /dev/null and b/controllers/store/__pycache__/stock_item.cpython-312.pyc differ diff --git a/routing/store/__pycache__/store.cpython-312.pyc b/controllers/store/__pycache__/store.cpython-312.pyc similarity index 100% rename from routing/store/__pycache__/store.cpython-312.pyc rename to controllers/store/__pycache__/store.cpython-312.pyc diff --git a/routing/store/__pycache__/supplier.cpython-312.pyc b/controllers/store/__pycache__/supplier.cpython-312.pyc similarity index 55% rename from routing/store/__pycache__/supplier.cpython-312.pyc rename to controllers/store/__pycache__/supplier.cpython-312.pyc index c4075ecc..1afe4c85 100644 Binary files a/routing/store/__pycache__/supplier.cpython-312.pyc and b/controllers/store/__pycache__/supplier.cpython-312.pyc differ diff --git a/routing/store/product.py b/controllers/store/product.py similarity index 100% rename from routing/store/product.py rename to controllers/store/product.py diff --git a/routing/store/product_category.py b/controllers/store/product_category.py similarity index 96% rename from routing/store/product_category.py rename to controllers/store/product_category.py index 0c3d5618..4eb4bf6b 100644 --- a/routing/store/product_category.py +++ b/controllers/store/product_category.py @@ -64,7 +64,7 @@ def filter_category(): form_filters = Filters_Product_Category.from_json(data) if not form_filters.validate_on_submit(): return jsonify({ - Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS, + Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_FAILURE, Model_View_Store_Product_Category.FLAG_MESSAGE: f'Form invalid.\n{form_filters.errors}' }) # ToDo: manually validate category, product @@ -76,7 +76,7 @@ def filter_category(): }) except Exception as e: return jsonify({ - Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS, + Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_FAILURE, Model_View_Store_Product_Category.FLAG_MESSAGE: f'Bad data received by controller.\n{e}' }) @@ -87,7 +87,7 @@ def save_category(): form_filters = Filters_Product_Category.from_json(data[Model_View_Store_Product_Category.FLAG_FORM_FILTERS]) if not form_filters.validate_on_submit(): return jsonify({ - Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS, + Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_FAILURE, Model_View_Store_Product_Category.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}' }) # filters_form = Filters_Product_Category.from_form(form_filters) @@ -95,7 +95,7 @@ def save_category(): categories = data[Model_View_Store_Product_Category.FLAG_PRODUCT_CATEGORY] if len(categories) == 0: return jsonify({ - Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS, + Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_FAILURE, Model_View_Store_Product_Category.FLAG_MESSAGE: f'No categories.' }) objsCategory = [] @@ -113,7 +113,7 @@ def save_category(): }) except Exception as e: return jsonify({ - Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS, + Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_FAILURE, Model_View_Store_Product_Category.FLAG_MESSAGE: f'Bad data received by controller.\n{e}' }) \ No newline at end of file diff --git a/controllers/store/product_permutation.py b/controllers/store/product_permutation.py new file mode 100644 index 00000000..8a10e0d5 --- /dev/null +++ b/controllers/store/product_permutation.py @@ -0,0 +1,159 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: App Routing +Feature: Store Product Permutation Routes + +Description: +Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles. +""" + + +# internal +from business_objects.store.product import Filters_Product, Product_Permutation +from forms.store.product_permutation import Filters_Product_Permutation +from models.model_view_base import Model_View_Base +from models.model_view_store import Model_View_Store +from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation +from helpers.helper_app import Helper_App +import lib.argument_validation as av +# external +from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app +from extensions import db, oauth +from urllib.parse import quote_plus, urlencode +from authlib.integrations.flask_client import OAuth +from authlib.integrations.base_client import OAuthError +from urllib.parse import quote, urlparse, parse_qs + + +routes_store_product_permutation = Blueprint('routes_store_product_permutation', __name__) +""" + +@routes_store_product_permutation.route('/store/permutations', methods=['GET']) +def permutation(): + filters = Filters_Product.get_default() + model = Model_View_Store_Product_Permutation(filters_product=filters) + return render_template('pages/store/_product_permutations.html', model = model) + +@routes_store_product_permutation.route('/store/permutation_filter', methods=['POST']) +def permutation_filter(): + data = Helper_App.get_request_data(request) + form_filters = None + try: + form_filters = get_Form_Filters_Permutation(data) + if not form_filters.validate_on_submit(): + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Form invalid.\n{form_filters.errors}'}) + # ToDo: manually validate category, product + filters_form = Filters_Product.from_form(form_filters) + model = Model_View_Store_Product_Permutation(filters_product=filters_form) + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model.category_list.to_permutation_row_list()}) + except Exception as e: + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'}) + +def get_Form_Filters_Permutation(data_request): + data_form = data_request[Model_View_Store_Product_Permutation.KEY_FORM] + form_filters = Filters_Product_Permutation(**data_form) + form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post') + return form_filters + +@routes_store_product_permutation.route('/store/permutation_save', methods=['POST']) +def permutation_save(): + data = Helper_App.get_request_data(request) + form_filters = None + try: + form_filters = get_Form_Filters_Permutation(data) + if not form_filters.validate_on_submit(): + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'}) + + permutations = data[Model_View_Store_Product_Permutation.FLAG_PRODUCT_PERMUTATION] + if len(permutations) == 0: + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'No permutations.'}) + objsPermutation = [] + for permutation in permutations: + objsPermutation.append(Product_Permutation.from_json(permutation)) + + # ToDo: manually validate category, product + filters_form = Filters_Product.from_form(form_filters) + model_save = Model_View_Store_Product_Permutation(filters_product=filters_form) + model_save.save_permutations(data.comment, objsPermutation) + + model_return = Model_View_Store_Product_Permutation(filters_product=filters_form) + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model_return.category_list.to_permutation_row_list()}) + except Exception as e: + return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'}) +""" + + +@routes_store_product_permutation.route(Model_View_Store_Product_Permutation.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS, methods=['GET']) +def permutations(): + print('permutations') + try: + form_filters = Filters_Product_Permutation.from_json(request.args) + except Exception as e: + print(f'Error: {e}') + form_filters = Filters_Product_Permutation() + print(f'form_filters={form_filters}') + model = Model_View_Store_Product_Permutation(form_filters) + return render_template('pages/store/_product_permutations.html', model = model) + +@routes_store_product_permutation.route(Model_View_Store_Product_Permutation.HASH_GET_STORE_PRODUCT_PERMUTATION, methods=['POST']) +def filter_permutation(): + data = Helper_App.get_request_data(request) + try: + form_filters = Filters_Product_Permutation.from_json(data) + if not form_filters.validate_on_submit(): + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_FAILURE, + Model_View_Store_Product_Permutation.FLAG_MESSAGE: f'Form invalid.\n{form_filters.errors}' + }) + model = Model_View_Store_Product_Permutation(form_filters = form_filters) + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_SUCCESS, + Model_View_Store_Product_Permutation.KEY_DATA: model.category_list.to_json() + }) + except Exception as e: + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_FAILURE, + Model_View_Store_Product_Permutation.FLAG_MESSAGE: f'Bad data received by controller.\n{e}' + }) + +@routes_store_product_permutation.route(Model_View_Store_Product_Permutation.HASH_SAVE_STORE_PRODUCT_PERMUTATION, methods=['POST']) +def save_permutation(): + data = Helper_App.get_request_data(request) + try: + form_filters = Filters_Product_Permutation.from_json(data[Model_View_Store_Product_Permutation.FLAG_FORM_FILTERS]) + if not form_filters.validate_on_submit(): + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_FAILURE, + Model_View_Store_Product_Permutation.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}' + }) + # filters_form = Filters_Product_Permutation.from_form(form_filters) + print(f'form_filters: {form_filters}') + + permutations = data[Model_View_Store_Product_Permutation.FLAG_PRODUCT_PERMUTATION] + if len(permutations) == 0: + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_FAILURE, + Model_View_Store_Product_Permutation.FLAG_MESSAGE: f'No permutations.' + }) + objsPermutation = [] + for permutation in permutations: + objsPermutation.append(Product_Permutation.from_json(permutation)) + # model_save = Model_View_Store_Product_Permutation() # filters_product=filters_form) + print(f'objsPermutation={objsPermutation}') + Model_View_Store_Product_Permutation.save_permutations(data.get('comment', 'No comment'), objsPermutation) + + model_return = Model_View_Store_Product_Permutation(form_filters=form_filters) + print('nips') + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_SUCCESS, + Model_View_Store_Product_Permutation.KEY_DATA: model_return.category_list.to_json() + }) + except Exception as e: + return jsonify({ + Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_FAILURE, + Model_View_Store_Product_Permutation.FLAG_MESSAGE: f'Bad data received by controller.\n{e}' + }) + \ No newline at end of file diff --git a/routing/store/stock_item.py b/controllers/store/stock_item.py similarity index 98% rename from routing/store/stock_item.py rename to controllers/store/stock_item.py index 4941b161..8f545be7 100644 --- a/routing/store/stock_item.py +++ b/controllers/store/stock_item.py @@ -13,7 +13,7 @@ Initializes the Flask application, sets the configuration based on the environme # internal from business_objects.store.product import Product, Filters_Product, Product_Permutation from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters -from forms.forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item +from forms.forms import Form_Filters_Stock_Item from models.model_view_base import Model_View_Base from models.model_view_store import Model_View_Store from models.model_view_store_supplier import Model_View_Store_Supplier diff --git a/routing/store/store.py b/controllers/store/store.py similarity index 100% rename from routing/store/store.py rename to controllers/store/store.py diff --git a/routing/store/supplier.py b/controllers/store/supplier.py similarity index 97% rename from routing/store/supplier.py rename to controllers/store/supplier.py index 4c4e9500..44e42841 100644 --- a/routing/store/supplier.py +++ b/controllers/store/supplier.py @@ -14,7 +14,7 @@ Initializes the Flask application, sets the configuration based on the environme # internal from business_objects.store.product import Product, Filters_Product, Product_Permutation from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters -from forms.forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item +from forms.forms import Form_Supplier, Form_Filters_Stock_Item from models.model_view_base import Model_View_Base from models.model_view_store import Model_View_Store from models.model_view_store_supplier import Model_View_Store_Supplier diff --git a/routing/user.py b/controllers/user.py similarity index 100% rename from routing/user.py rename to controllers/user.py diff --git a/datastores/__pycache__/datastore_base.cpython-312.pyc b/datastores/__pycache__/datastore_base.cpython-312.pyc index 60f70209..712b97fe 100644 Binary files a/datastores/__pycache__/datastore_base.cpython-312.pyc and b/datastores/__pycache__/datastore_base.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_store_base.cpython-312.pyc b/datastores/__pycache__/datastore_store_base.cpython-312.pyc index d4134262..88a9ec72 100644 Binary files a/datastores/__pycache__/datastore_store_base.cpython-312.pyc and b/datastores/__pycache__/datastore_store_base.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_store_basket.cpython-312.pyc b/datastores/__pycache__/datastore_store_basket.cpython-312.pyc index 850a0869..c509e757 100644 Binary files a/datastores/__pycache__/datastore_store_basket.cpython-312.pyc and b/datastores/__pycache__/datastore_store_basket.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_store_product_category.cpython-312.pyc b/datastores/__pycache__/datastore_store_product_category.cpython-312.pyc index 8403f80c..7e4245b2 100644 Binary files a/datastores/__pycache__/datastore_store_product_category.cpython-312.pyc and b/datastores/__pycache__/datastore_store_product_category.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_store_product_permutation.cpython-312.pyc b/datastores/__pycache__/datastore_store_product_permutation.cpython-312.pyc index 09b2f8a4..f4c9a94d 100644 Binary files a/datastores/__pycache__/datastore_store_product_permutation.cpython-312.pyc and b/datastores/__pycache__/datastore_store_product_permutation.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_store_stock_item.cpython-312.pyc b/datastores/__pycache__/datastore_store_stock_item.cpython-312.pyc index 6a415a29..3dfde80b 100644 Binary files a/datastores/__pycache__/datastore_store_stock_item.cpython-312.pyc and b/datastores/__pycache__/datastore_store_stock_item.cpython-312.pyc differ diff --git a/datastores/__pycache__/datastore_user.cpython-312.pyc b/datastores/__pycache__/datastore_user.cpython-312.pyc index 7abc9606..5c27228d 100644 Binary files a/datastores/__pycache__/datastore_user.cpython-312.pyc and b/datastores/__pycache__/datastore_user.cpython-312.pyc differ diff --git a/datastores/datastore_base.py b/datastores/datastore_base.py index c316a45c..52e94f6b 100644 --- a/datastores/datastore_base.py +++ b/datastores/datastore_base.py @@ -13,7 +13,8 @@ Datastore for Store # internal # from routes import bp_home import lib.argument_validation as av -from business_objects.store.access_level import Access_Level, Filters_Access_Level +from business_objects.store.access_level import Access_Level +""" from business_objects.store.basket import Basket, Basket_Item from business_objects.store.product_category import Product_Category_Container, Product_Category from business_objects.store.currency import Currency @@ -23,13 +24,17 @@ from business_objects.store.delivery_region import Delivery_Region from business_objects.store.discount import Discount from business_objects.store.order import Order from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product # Permutation_Variation_Link +""" from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters +from business_objects.unit_measurement import Unit_Measurement from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +# from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! from extensions import db +from forms.access_level import Filters_Access_Level +from forms.unit_measurement import Filters_Unit_Measurement # external # from abc import ABC, abstractmethod, abstractproperty from flask_sqlalchemy import SQLAlchemy @@ -105,8 +110,8 @@ class DataStore_Base(BaseModel): while cursor.nextset(): print(f'new result set: {cursor.fetchall()}') @classmethod - def get_regions_and_currencies(cls): - _m = 'DataStore_Base.get_regions_and_currencies' + def get_many_region_and_currency(cls): + _m = 'DataStore_Base.get_many_region_and_currency' _m_db_currency = 'p_shop_get_many_currency' _m_db_region = 'p_shop_get_many_region' @@ -168,20 +173,45 @@ class DataStore_Base(BaseModel): def upload_bulk(permanent_table_name, records, batch_size): _m = 'DataStore_Base.upload_bulk' print(f'{_m}\nstarting...') + print(f'permanent_table_name: {permanent_table_name}') + if db.session.dirty or db.session.new or db.session.deleted: + print("Session is not clean") + return + # Assuming `permanent_table_name` is a string representing the table name + table_object = db.metadata.tables.get(permanent_table_name) + if table_object is None: + print(f"Table {permanent_table_name} not found in metadata.") + return + else: + expected_columns = set(column.name for column in db.inspect(table_object).columns) + print(f'expected_columns: {expected_columns}') + try: for i in range(0, len(records), batch_size): batch = records[i:i+batch_size] + print(f'batch: {batch}') + db.session.bulk_save_objects(batch) + """ data = [object.to_json() for object in batch] - print(f'batch: {batch}\ndata: {data}') - db.session.bulk_insert_mappings(permanent_table_name, data) + print(f'data: {data}') + for row in data: + row_keys = set(row.keys()) + if row_keys != expected_columns: + print(f"Column mismatch in row: {row}") + print(f'missing columns: {expected_columns - row_keys}') + print(f'extra columns: {row_keys - expected_columns}') + # db.session.bulk_insert_mappings(permanent_table_name, data) + """ db.session.commit() except Exception as e: print(f'{_m}\n{e}') db.session.rollback() raise e @classmethod - def get_many_access_level(cls, filters): + def get_many_access_level(cls, filters=None): _m = 'DataStore_Store_Base.get_many_access_level' + if filters is None: + filters = Filters_Access_Level() av.val_instance(filters, 'filters', _m, Filters_Access_Level) argument_dict = filters.to_json() # user = cls.get_user_session() @@ -213,4 +243,41 @@ class DataStore_Base(BaseModel): DataStore_Base.db_cursor_clear(cursor) cursor.close() - return access_levels, errors \ No newline at end of file + return access_levels, errors + @classmethod + def get_many_unit_measurement(cls, filters=None): + _m = 'DataStore_Store_Base.get_many_unit_measurement' + if filters is None: + filters = Filters_Unit_Measurement() + av.val_instance(filters, 'filters', _m, Filters_Unit_Measurement) + argument_dict = filters.to_json() + # user = cls.get_user_session() + # argument_dict['a_id_user'] = 1 # 'auth0|6582b95c895d09a70ba10fef' # id_user + print(f'argument_dict: {argument_dict}') + print('executing p_shop_get_many_unit_measurement') + result = cls.db_procedure_execute('p_shop_get_many_unit_measurement', argument_dict) + cursor = result.cursor + print('data received') + + # units of measurement + result_set_1 = cursor.fetchall() + print(f'raw units of measurement: {result_set_1}') + units = [] + for row in result_set_1: + new_unit = Unit_Measurement.from_DB_unit_measurement(row) + units.append(new_unit) + + # Errors + cursor.nextset() + result_set_e = cursor.fetchall() + print(f'raw errors: {result_set_e}') + errors = [] + if len(result_set_e) > 0: + errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1]) + for error in errors: + print(f"Error [{error.code}]: {error.msg}") + + DataStore_Base.db_cursor_clear(cursor) + cursor.close() + + return units, errors \ No newline at end of file diff --git a/datastores/datastore_store_base.py b/datastores/datastore_store_base.py index 352856cf..042a17e5 100644 --- a/datastores/datastore_store_base.py +++ b/datastores/datastore_store_base.py @@ -12,8 +12,6 @@ Datastore for Store # internal # from routes import bp_home -import lib.argument_validation as av -# from business_objects.store.access_level import Access_Level, Filters_Access_Level from business_objects.store.basket import Basket, Basket_Item from business_objects.store.product_category import Product_Category_Container, Product_Category from business_objects.store.currency import Currency @@ -26,11 +24,12 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation_Type, Product_Variation, Product_Variation_Filters, Product_Variation_Container from datastores.datastore_base import DataStore_Base -# from helpers.helper_db_mysql import Helper_DB_MySQL -# from models.model_view_store_checkout import Model_View_Store_Checkout # circular! from extensions import db +from helpers.helper_db_mysql import Helper_DB_MySQL +import lib.argument_validation as av +# from models.model_view_store_checkout import Model_View_Store_Checkout # circular! # external # from abc import ABC, abstractmethod, abstractproperty from flask_sqlalchemy import SQLAlchemy @@ -118,12 +117,8 @@ class DataStore_Store_Base(DataStore_Base): # variations = [Product_Variation(**row) for row in result_set_4] variations = [] for row in result_set_4: - new_variation = Product_Variation.from_DB_get_many_product_catalogue(row) # (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]) + new_variation = Product_Variation.from_DB_get_many_product_catalogue(row) variations.append(new_variation) - # products[product_index[new_variation.id_product]].variations.append(new_variation) - # index_category = category_index[new_variation.id_category] - # index_product = categories[index_category].index_product_from_ids_product_permutation(new_variation.id_product, new_variation.id_permutation) - # categories[index_category].products[index_product].variations.append(new_variation) category_list.add_product_variation(new_variation) # print(f'variations: {variations}') # print(f'products: {[p.id_product for p in products]}') @@ -209,17 +204,13 @@ class DataStore_Store_Base(DataStore_Base): ids_permutation.append(msg_error_availability[:index_comma]) return ids_permutation @classmethod - def get_regions_and_currencies(cls): - _m = 'DataStore_Store_Base.get_regions_and_currencies' + def get_many_currency(cls): + _m = 'DataStore_Store_Base.get_many_currency' _m_db_currency = 'p_shop_get_many_currency' - _m_db_region = 'p_shop_get_many_region' argument_dict_list_currency = { 'a_get_inactive_currency': 0 } - argument_dict_list_region = { - 'a_get_inactive_currency': 0 - } print(f'executing {_m_db_currency}') result = cls.db_procedure_execute(_m_db_currency, argument_dict_list_currency) @@ -235,6 +226,17 @@ class DataStore_Store_Base(DataStore_Base): print(f'currencies: {currencies}') DataStore_Store_Base.db_cursor_clear(cursor) + return currencies + + @classmethod + def get_many_region(cls): + _m = 'DataStore_Store_Base.get_many_region' + _m_db_region = 'p_shop_get_many_region' + + argument_dict_list_region = { + 'a_get_inactive_currency': 0 + } + print(f'executing {_m_db_region}') result = cls.db_procedure_execute(_m_db_region, argument_dict_list_region) cursor = result.cursor @@ -250,7 +252,15 @@ class DataStore_Store_Base(DataStore_Base): DataStore_Store_Base.db_cursor_clear(cursor) cursor.close() + return regions + + @classmethod + def get_many_region_and_currency(cls): + _m = 'DataStore_Store_Base.get_many_region_and_currency' + currencies = cls.get_many_currency() + regions = cls.get_many_region() return regions, currencies + @classmethod def get_many_product_variation(cls, variation_filters): _m = 'DataStore_Store_Base.get_many_product_variation' @@ -278,13 +288,30 @@ class DataStore_Store_Base(DataStore_Base): result = cls.db_procedure_execute('p_shop_get_many_product_variation', argument_dict_list) cursor = result.cursor - result_set = cursor.fetchall() + result_set_vt = cursor.fetchall() + # Product_Variation Types + # variation_container = Product_Variation_Container() + variation_types = [] + variation_types_dict = {} + for row in result_set_vt: + new_variation_type = Product_Variation_Type.from_DB_get_many_product_variation(row) + # variation_container.add_product_variation_type(new_variation_type) + variation_types.append(new_variation_type) + variation_types_dict[new_variation_type.id_type] = new_variation_type + + print(f'variation_types_dict: {variation_types_dict}') + # Product_Variations - variations = Product_Variation_List() - for row in result_set: - new_variation = Product_Variation.from_DB_variation(row) - variations.add_product_variation(new_variation) + cursor.nextset() + result_set_v = cursor.fetchall() + # variations = Product_Variation_Container() + variations = [] + for row in result_set_v: + new_variation = Product_Variation.from_DB_get_many_product_variation(row) + new_variation.variation_type = variation_types_dict[new_variation.id_type] + # variation_container.add_product_variation(new_variation) + variations.append(new_variation) errors = [] cursor.nextset() @@ -299,5 +326,5 @@ class DataStore_Store_Base(DataStore_Base): cursor.close() - return variations, errors + return variation_types, variations, errors \ No newline at end of file diff --git a/datastores/datastore_store_basket.py b/datastores/datastore_store_basket.py index b4b31a3b..fd77dc9e 100644 --- a/datastores/datastore_store_basket.py +++ b/datastores/datastore_store_basket.py @@ -25,7 +25,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container from datastores.datastore_store_base import DataStore_Store_Base # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! diff --git a/datastores/datastore_store_product.py b/datastores/datastore_store_product.py index 86b18e1e..bea50e2d 100644 --- a/datastores/datastore_store_product.py +++ b/datastores/datastore_store_product.py @@ -24,7 +24,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container # from datastores.datastore_base import Table_Shop_Product_Category, Table_Shop_Product_Category_Temp from datastores.datastore_store_base import DataStore_Store_Base from helpers.helper_db_mysql import Helper_DB_MySQL @@ -83,7 +83,7 @@ class Row_Shop_Product_Temp(db.Model): 'id_category': self.id_category, 'name': self.name, 'id_access_level_required': self.id_access_level_required, - 'active': self.active, + 'active': av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'), 'display_order': self.display_order, 'guid': self.guid, } diff --git a/datastores/datastore_store_product_category.py b/datastores/datastore_store_product_category.py index 2c057cb0..ebfce816 100644 --- a/datastores/datastore_store_product_category.py +++ b/datastores/datastore_store_product_category.py @@ -13,7 +13,7 @@ Datastore for Store Product Categories # internal import lib.argument_validation as av from business_objects.store.basket import Basket, Basket_Item -from business_objects.store.product_category import Product_Category_Container, Product_Category +from business_objects.store.product_category import Product_Category_Container, Product_Category, Product_Category_Temp from business_objects.store.currency import Currency from business_objects.store.image import Image from business_objects.store.delivery_option import Delivery_Option @@ -24,7 +24,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container # from datastores.datastore_base import Table_Shop_Product_Category, Table_Shop_Product_Category_Temp from datastores.datastore_store_base import DataStore_Store_Base from helpers.helper_db_mysql import Helper_DB_MySQL @@ -41,67 +41,6 @@ from pydantic import BaseModel, ConfigDict from typing import ClassVar from datetime import datetime -# db = SQLAlchemy() - -""" -class Table_Shop_Product_Category(db.Model): - __tablename__ = 'Shop_Product_Category' - id_category: int = db.Column(db.Integer, primary_key=True) - code: str = db.Column(db.String(50)) - name: str = db.Column(db.String(255)) - description: str = db.Column(db.String(4000)) - active: bool = db.Column(db.Boolean) - display_order: int = db.Column(db.Integer) - created_on: datetime = db.Column(db.DateTime) - created_by: int = db.Column(db.Integer) - id_change_set: int = db.Column(db.Integer) -""" -class Row_Shop_Product_Category_Temp(db.Model): - __tablename__ = 'Shop_Product_Category_Temp' - __table_args__ = { 'extend_existing': True } - id_category: int = db.Column(db.Integer, primary_key=True) - code: str = db.Column(db.String(50)) - name: str = db.Column(db.String(255)) - description: str = db.Column(db.String(4000)) - id_access_level_required: int = db.Column(db.Integer) - active: bool = db.Column(db.Boolean) - display_order: int = db.Column(db.Integer) - guid: str = db.Column(db.BINARY(36)) - # created_on: datetime = db.Column(db.DateTime) - # created_by: int = db.Column(db.Integer) - - @classmethod - def from_product_category(cls, product_category): - row = cls() - row.id_category = product_category.id_category[0] if isinstance(product_category.id_category, tuple) else product_category.id_category - row.code = product_category.code[0] if isinstance(product_category.code, tuple) else product_category.code - row.name = product_category.name[0] if isinstance(product_category.name, tuple) else product_category.name - row.description = product_category.description[0] if isinstance(product_category.description, tuple) else product_category.description - row.id_access_level_required = product_category.id_access_level_required[0] if isinstance(product_category.id_access_level_required, tuple) else product_category.id_access_level_required - row.active = product_category.active - row.display_order = product_category.display_order - """ - row.guid = product_category.guid - row.created_on = product_category.created_on - row.created_by = product_category.created_by - """ - return row - def to_json(self): - return { - 'id_category': self.id_category, - 'code': self.code, - 'name': self.name, - 'description': self.description, - 'id_access_level_required': self.id_access_level_required, - 'active': self.active, - 'display_order': self.display_order, - 'guid': self.guid, - } - """ - 'created_on': self.created_on, - 'created_by': self.created_by - """ - class DataStore_Store_Product_Category(DataStore_Store_Base): def __init__(self): @@ -120,8 +59,8 @@ class DataStore_Store_Product_Category(DataStore_Store_Base): rows = [] id_category_new = 0 for category in categories: - # row = Row_Shop_Product_Category_Temp.from_product_category(category) - row = category.to_temporary_record() + row = Product_Category_Temp.from_product_category(category) + # row = category.to_temporary_record() # id_tmp = if row.id_category == '': id_category_new -= 1 @@ -147,7 +86,7 @@ class DataStore_Store_Product_Category(DataStore_Store_Base): cursor.close() print('cursor closed') """ - DataStore_Store_Base.upload_bulk(rows, Product_Category.__tablename__, 1000) + DataStore_Store_Base.upload_bulk(Product_Category_Temp.__tablename__, rows, 1000) argument_dict_list = { 'a_id_user': user.id_user, diff --git a/datastores/datastore_store_product_permutation.py b/datastores/datastore_store_product_permutation.py index 65b32361..15121ae8 100644 --- a/datastores/datastore_store_product_permutation.py +++ b/datastores/datastore_store_product_permutation.py @@ -12,21 +12,10 @@ Datastore for Store Product Permutations # internal import lib.argument_validation as av -from business_objects.store.basket import Basket, Basket_Item -from business_objects.store.product_category import Product_Category_Container, Product_Category -from business_objects.store.currency import Currency -from business_objects.store.image import Image -from business_objects.store.delivery_option import Delivery_Option -from business_objects.store.delivery_region import Delivery_Region -from business_objects.store.discount import Discount -from business_objects.store.order import Order -from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product -from business_objects.sql_error import SQL_Error -from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters -from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.store_base import Store_Base +from business_objects.store.product_permutation import Product_Permutation, Product_Permutation_Temp from datastores.datastore_store_base import DataStore_Store_Base -# from helpers.helper_db_mysql import Helper_DB_MySQL +from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! from extensions import db # external @@ -43,35 +32,72 @@ from datetime import datetime # db = SQLAlchemy() + class DataStore_Store_Product_Permutation(DataStore_Store_Base): def __init__(self): super().__init__() - def save_permutations(self, comment, permutations): - _m = 'DataStore_Store_Base.save_permutations' + @classmethod + def save_permutations(cls, comment, permutations): + _m = 'DataStore_Store_Product_Permutation.save_permutations' av.val_str(comment, 'comment', _m) - av.val_list(permutations, 'list_permutations', _m, Product_Permutation, 1) + # av.val_list(permutations, 'list_permutations', _m, Product_Permutation, 1) - guid = Helper_DB_MySQL.create_guid() + guid = Helper_DB_MySQL.create_guid_str() now = datetime.now() - user = self.get_user_session() + user = cls.get_user_session() + rows = [] for permutation in permutations: - setattr(permutation, 'guid', guid) - setattr(permutation, 'created_on', now) - setattr(permutation, 'created_by', user.id_user) + # row = permutation.to_temporary_record() + row = Product_Permutation_Temp.from_product_permutation(permutation) + row.guid = guid + rows.append(row) - cursor = self.db.cursor() + print(f'rows: {rows}') + + """ + cursor = db.cursor() + print('cursor created') cursor.executemany( - 'INSERT INTO Shop_Product_Permutation_Temp (id_permutation, id_product, description, cost_local, id_currency_cost, profit_local_min, latency_manufacture, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, id_recurrence_interval, count_recurrence_interval, id_stripe_product, active, display_order, guid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', - permutations + '''INSERT INTO Shop_Product_Permutation_Temp ( + id_permutation, + id_product, + description, + cost_local, + id_currency_cost, + profit_local_min, + latency_manufacture_days, + id_unit_measurement_quantity, + count_unit_measurement_quantity, + quantity_min, + quantity_max, + quantity_stock, + is_subscription, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, + id_stripe_product, + does_expire_faster_once_unsealed, + id_unit_measurement_interval_expiration_unsealed, + count_interval_expiration_unsealed, + active, + guid + ) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''', + rows ) - self.db.commit() - + print('cursor executed') + db.commit() + print('cursor committed') + cursor.close() + print('cursor closed') + """ + DataStore_Store_Base.upload_bulk(Product_Permutation_Temp.__tablename__, rows, 1000) + print('bulk uploaded') + argument_dict_list = { 'a_id_user': user.id_user, 'a_comment': comment, 'a_guid': guid } - self.db_procedure_execute('p_shop_save_permutation', argument_dict_list) - - cursor.close() + cls.db_procedure_execute('p_shop_save_product_permutation', argument_dict_list) + print('saved product permutations') diff --git a/datastores/datastore_store_product_variation.py b/datastores/datastore_store_product_variation.py index 6575a7e7..52859eb2 100644 --- a/datastores/datastore_store_product_variation.py +++ b/datastores/datastore_store_product_variation.py @@ -25,7 +25,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container from datastores.datastore_store_base import DataStore_Store_Base # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! @@ -80,7 +80,7 @@ class DataStore_Store_Product_Variation(DataStore_Store_Base): result_set = cursor.fetchall() # Product_Variations - variations = Product_Variation_List() + variations = Product_Variation_Container() for row in result_set: new_variation = Product_Variation.from_DB_variation(row) variations.add_product_variation(new_variation) diff --git a/datastores/datastore_store_stock_item.py b/datastores/datastore_store_stock_item.py index 53318b99..b89e1c8b 100644 --- a/datastores/datastore_store_stock_item.py +++ b/datastores/datastore_store_stock_item.py @@ -25,7 +25,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container from datastores.datastore_store_base import DataStore_Store_Base # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! diff --git a/datastores/datastore_store_stripe.py b/datastores/datastore_store_stripe.py index 6cc1942c..27db528a 100644 --- a/datastores/datastore_store_stripe.py +++ b/datastores/datastore_store_stripe.py @@ -25,7 +25,7 @@ from business_objects.store.product import Product, Product_Permutation, Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List +from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_Container from datastores.datastore_store_base import DataStore_Store_Base # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! diff --git a/datastores/datastore_user.py b/datastores/datastore_user.py index afbfe550..5628d1e4 100644 --- a/datastores/datastore_user.py +++ b/datastores/datastore_user.py @@ -13,19 +13,9 @@ Datastore for Users # internal # from routes import bp_home import lib.argument_validation as av -from business_objects.store.basket import Basket, Basket_Item -from business_objects.store.product_category import Product_Category_Container, Product_Category -from business_objects.store.currency import Currency -from business_objects.store.image import Image -from business_objects.store.delivery_option import Delivery_Option -from business_objects.store.delivery_region import Delivery_Region -from business_objects.store.discount import Discount -from business_objects.store.order import Order -from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product from business_objects.sql_error import SQL_Error from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters from business_objects.user import User, User_Filters, User_Permission_Evaluation -from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List from datastores.datastore_base import DataStore_Base from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! diff --git a/forms/__pycache__/access_level.cpython-312.pyc b/forms/__pycache__/access_level.cpython-312.pyc new file mode 100644 index 00000000..40a47abc Binary files /dev/null and b/forms/__pycache__/access_level.cpython-312.pyc differ diff --git a/forms/__pycache__/base.cpython-312.pyc b/forms/__pycache__/base.cpython-312.pyc index af6d106b..378d2077 100644 Binary files a/forms/__pycache__/base.cpython-312.pyc and b/forms/__pycache__/base.cpython-312.pyc differ diff --git a/forms/__pycache__/forms.cpython-312.pyc b/forms/__pycache__/forms.cpython-312.pyc index b45e6575..023f70b9 100644 Binary files a/forms/__pycache__/forms.cpython-312.pyc and b/forms/__pycache__/forms.cpython-312.pyc differ diff --git a/forms/__pycache__/unit_measurement.cpython-312.pyc b/forms/__pycache__/unit_measurement.cpython-312.pyc new file mode 100644 index 00000000..0907c0d3 Binary files /dev/null and b/forms/__pycache__/unit_measurement.cpython-312.pyc differ diff --git a/forms/access_level.py b/forms/access_level.py new file mode 100644 index 00000000..c9136e88 --- /dev/null +++ b/forms/access_level.py @@ -0,0 +1,37 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Backend +Feature: Forms - Access Level Filters data input + +Description: +Defines Flask-WTF forms for handling access level filter input. +""" + +# internal +from business_objects.base import Base +from forms.base import Form_Base +import lib.argument_validation as av +# external +from flask_wtf import FlaskForm +from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField +from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional +from flask_wtf.recaptcha import RecaptchaField +from abc import ABCMeta, abstractmethod + + +class Filters_Access_Level(Form_Base): + active = BooleanField("Active only?") + def __repr__(self): + return f'{self.__class__.__name__}(active={self.active.data})' + @classmethod + def from_json(cls, json): + form = Filters_Access_Level() + form.active.data = av.input_bool(json[Base.FLAG_ACTIVE], Base.FLAG_ACTIVE, f'{cls.__name__}.from_json') + return form + def to_json(self): + return { + Base.FLAG_ACTIVE: 1 if av.input_bool(self.active.data, Base.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') else 0, + } \ No newline at end of file diff --git a/forms/base.py b/forms/base.py index 823a370b..7e69481a 100644 --- a/forms/base.py +++ b/forms/base.py @@ -21,10 +21,12 @@ class Form_Base_Meta(type(FlaskForm), ABCMeta): class Form_Base(FlaskForm, metaclass=Form_Base_Meta): + """ @classmethod @abstractmethod def from_filters(cls, filters): pass + """ @abstractmethod def __repr__(self): pass @@ -43,4 +45,20 @@ class Form_Base(FlaskForm, metaclass=Form_Base_Meta): form_filters.is_not_empty.data = av.input_bool(data_form['is_not_empty'], 'is_not_empty', 'filter_category') form_filters.active.data = av.input_bool(data_form['active'], 'active', 'filter_category') return form_filters - """ \ No newline at end of file + """ + +''' +class Filters_Stored_Procedure_Base(Form_Base): + """ + @abstractmethod + def __repr__(self): + pass + @classmethod + @abstractmethod + def from_json(cls, json): + pass + """ + @abstractmethod + def to_json(self): + pass +''' \ No newline at end of file diff --git a/forms/forms.py b/forms/forms.py index 34b8b0af..d733ff65 100644 --- a/forms/forms.py +++ b/forms/forms.py @@ -126,13 +126,6 @@ class Form_Supplier(FlaskForm): # class Form_Supplier_Purchase_Order(FlaskForm): -class Form_Filters_Permutation(FlaskForm): - id_category = SelectField('Category', validators=[Optional()], choices=[]) - id_product = SelectField('Product', validators=[Optional()], choices=[]) - is_out_of_stock = BooleanField('Out of stock only?') - quantity_min = FloatField('Min stock') - quantity_max = FloatField('Max stock') - # submit = SubmitField('Submit') class Form_Filters_Stock_Item(FlaskForm): id_category = SelectField('Category', validators=[Optional()], choices=[]) diff --git a/forms/store/__pycache__/product_category.cpython-312.pyc b/forms/store/__pycache__/product_category.cpython-312.pyc index 6c5b475b..e7d8f538 100644 Binary files a/forms/store/__pycache__/product_category.cpython-312.pyc and b/forms/store/__pycache__/product_category.cpython-312.pyc differ diff --git a/forms/store/__pycache__/product_permutation.cpython-312.pyc b/forms/store/__pycache__/product_permutation.cpython-312.pyc new file mode 100644 index 00000000..f9227a54 Binary files /dev/null and b/forms/store/__pycache__/product_permutation.cpython-312.pyc differ diff --git a/forms/store/product_category.py b/forms/store/product_category.py index 79b96a9f..c254ab65 100644 --- a/forms/store/product_category.py +++ b/forms/store/product_category.py @@ -28,12 +28,14 @@ from abc import ABCMeta, abstractmethod class Filters_Product_Category(Form_Base): is_not_empty = BooleanField('Not empty only?') active = BooleanField("Active only?") + """ @classmethod def from_filters(cls, filters): form = Filters_Product_Category() form.is_not_empty.data = filters.is_not_empty form.active.data = filters.active return form + """ def __repr__(self): return f'Filters_Product_Category(is_not_empty={self.is_not_empty.data}, active={self.active.data})' @classmethod diff --git a/forms/store/product_permutation.py b/forms/store/product_permutation.py new file mode 100644 index 00000000..06267c8f --- /dev/null +++ b/forms/store/product_permutation.py @@ -0,0 +1,65 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Backend +Feature: Forms - Product Category Filters data input + +Description: +Defines Flask-WTF forms for handling product category filter input. +""" + +# internal +from business_objects.store.store_base import Store_Base +# from business_objects.store.product_category import Filters_Product_Category +# from models.model_view_store import Model_View_Store # circular +# from helpers.DEPRECATED.helper_abc import Interface_ABC +from forms.base import Form_Base +import lib.argument_validation as av +# external +from flask_wtf import FlaskForm +from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField +from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional +from flask_wtf.recaptcha import RecaptchaField +from abc import ABCMeta, abstractmethod + + +class Filters_Product_Permutation(Form_Base): + id_category = SelectField('Category', validators=[Optional()], choices=[]) + id_product = SelectField('Product', validators=[Optional()], choices=[]) + is_out_of_stock = BooleanField('Out of stock only?') + quantity_min = FloatField('Min stock') + quantity_max = FloatField('Max stock') + # submit = SubmitField('Submit') + """ + @classmethod + def from_filters(cls, filters): + form = Filters_Product_Permutation() + form.id_category.choices = Store_Base.convert_list_objects_to_list_options(filters.categories) + form.id_product.choices = Store_Base.convert_list_objects_to_list_options(filters.products) + form.is_out_of_stock.data = filters.is_out_of_stock + form.quantity_min.data = filters.quantity_min + form.quantity_max.data = filters.quantity_max + return form + """ + def __repr__(self): + return f''' + Filters_Product_Permutation( + id_category={self.id_category.data}, + id_product={self.id_product.data}, + is_out_of_stock={self.is_out_of_stock.data}, + quantity_min={self.quantity_min.data}, + quantity_max={self.quantity_max.data}) + ''' + @classmethod + def from_json(cls, json): + form = Filters_Product_Permutation() + form.id_category.choices = [(json[Store_Base.ATTR_ID_PRODUCT_CATEGORY], json[Store_Base.ATTR_ID_PRODUCT_CATEGORY])] + form.id_category.data = json[Store_Base.ATTR_ID_PRODUCT_CATEGORY] + form.id_product.choices = [(json[Store_Base.ATTR_ID_PRODUCT], json[Store_Base.ATTR_ID_PRODUCT])] + form.id_product.data = json[Store_Base.ATTR_ID_PRODUCT] + form.is_out_of_stock.data = av.input_bool(json[Store_Base.FLAG_IS_OUT_OF_STOCK], 'is_out_of_stock', 'Filters_Product_Permutation') + form.quantity_min.data = json[Store_Base.FLAG_QUANTITY_MIN] + form.quantity_max.data = json[Store_Base.FLAG_QUANTITY_MAX] + return form \ No newline at end of file diff --git a/forms/unit_measurement.py b/forms/unit_measurement.py new file mode 100644 index 00000000..9f69daa4 --- /dev/null +++ b/forms/unit_measurement.py @@ -0,0 +1,42 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Backend +Feature: Forms - Unit of Measurement Filters data input + +Description: +Defines Flask-WTF forms for handling unit of measurement filter input. +""" + +# internal +from business_objects.store.store_base import Store_Base +from forms.base import Form_Base +import lib.argument_validation as av +# external +from flask_wtf import FlaskForm +from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField +from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional +from flask_wtf.recaptcha import RecaptchaField +from abc import ABCMeta, abstractmethod + + +class Filters_Unit_Measurement(Form_Base): + active = BooleanField("Active only?") + @classmethod + def from_filters(cls, filters): + form = Filters_Unit_Measurement() + form.active.data = filters.active + return form + def __repr__(self): + return f'Filters_Unit_Measurement(active={self.active.data})' + @classmethod + def from_json(cls, json): + form = Filters_Unit_Measurement() + form.active.data = av.input_bool(json[Store_Base.FLAG_ACTIVE], 'active', 'Filters_Unit_Measurement') + return form + def to_json(self): + return { + Store_Base.FLAG_ACTIVE: av.input_bool(self.active.data, Store_Base.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json'), + } \ No newline at end of file diff --git a/models/__pycache__/model_view_base.cpython-312.pyc b/models/__pycache__/model_view_base.cpython-312.pyc index bf75e6bc..8dd81654 100644 Binary files a/models/__pycache__/model_view_base.cpython-312.pyc and b/models/__pycache__/model_view_base.cpython-312.pyc differ diff --git a/models/__pycache__/model_view_store.cpython-312.pyc b/models/__pycache__/model_view_store.cpython-312.pyc index b611bf85..82faaa32 100644 Binary files a/models/__pycache__/model_view_store.cpython-312.pyc and b/models/__pycache__/model_view_store.cpython-312.pyc differ diff --git a/models/__pycache__/model_view_store_product_category.cpython-312.pyc b/models/__pycache__/model_view_store_product_category.cpython-312.pyc index ef762ed1..7683d6e5 100644 Binary files a/models/__pycache__/model_view_store_product_category.cpython-312.pyc and b/models/__pycache__/model_view_store_product_category.cpython-312.pyc differ diff --git a/models/__pycache__/model_view_store_product_permutation.cpython-312.pyc b/models/__pycache__/model_view_store_product_permutation.cpython-312.pyc index 949949a5..1457b6a8 100644 Binary files a/models/__pycache__/model_view_store_product_permutation.cpython-312.pyc and b/models/__pycache__/model_view_store_product_permutation.cpython-312.pyc differ diff --git a/models/model_view_base.py b/models/model_view_base.py index 39c5235f..5c77cefc 100644 --- a/models/model_view_base.py +++ b/models/model_view_base.py @@ -23,7 +23,8 @@ from datastores.datastore_base import DataStore_Base from datastores.datastore_user import DataStore_User from business_objects.store.store_base import Store_Base from business_objects.store.product_category import Product_Category -from business_objects.store.access_level import Filters_Access_Level +from forms.access_level import Filters_Access_Level +from forms.unit_measurement import Filters_Unit_Measurement from business_objects.user import User, User_Filters # external from abc import ABC, abstractmethod @@ -56,6 +57,7 @@ class Model_View_Base(BaseModel, ABC): FLAG_COMMENT: ClassVar[str] = 'comment' FLAG_CONTAINER: ClassVar[str] = 'container' FLAG_CONTAINER_INPUT: ClassVar[str] = FLAG_CONTAINER + '-input' + FLAG_CURRENCY: ClassVar[str] = 'currency' FLAG_DELETE: ClassVar[str] = 'delete' FLAG_DESCRIPTION: ClassVar[str] = Store_Base.FLAG_DESCRIPTION FLAG_DETAIL: ClassVar[str] = 'detail' @@ -70,10 +72,12 @@ class Model_View_Base(BaseModel, ABC): FLAG_HAMBURGER: ClassVar[str] = 'hamburger' FLAG_IMAGE_LOGO: ClassVar[str] = 'image-logo' FLAG_INITIALISED: ClassVar[str] = 'initialised' - FLAG_KEY_PRIMARY: ClassVar[str] = Store_Base.FLAG_KEY_PRIMARY + # FLAG_KEY_PRIMARY: ClassVar[str] = Store_Base.FLAG_KEY_PRIMARY FLAG_MESSAGE: ClassVar[str] = 'Message' FLAG_MODAL: ClassVar[str] = 'modal' FLAG_NAME: ClassVar[str] = Store_Base.FLAG_NAME + FLAG_NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME_ATTR_OPTION_TEXT + FLAG_NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.FLAG_NAME_ATTR_OPTION_VALUE FLAG_NAV_ADMIN_HOME: ClassVar[str] = 'navAdminHome' FLAG_NAV_ADMIN_STORE_STRIPE_PRICES: ClassVar[str] = 'navAdminStoreStripePrices' FLAG_NAV_ADMIN_STORE_STRIPE_PRODUCTS: ClassVar[str] = 'navAdminStoreStripeProducts' @@ -289,17 +293,45 @@ class Model_View_Base(BaseModel, ABC): return False """ - def get_many_access_level(self, filters): + def get_many_access_level(self, filters=None): _m = 'Model_View_Store.get_many_access_level' - av.val_instance(filters, 'filters', _m, Filters_Access_Level) - + # av.val_instance(filters, 'filters', _m, Filters_Access_Level) access_levels, errors = DataStore_Base.get_many_access_level(filters) - return access_levels + def get_many_unit_measurement(self, filters=None): + _m = 'Model_View_Store.get_many_unit_measurement' + # av.val_instance(filters, 'filters', _m, Filters_Unit_Measurement) + units_measurement, errors = DataStore_Base.get_many_unit_measurement(filters) + return units_measurement + + @staticmethod + def convert_list_objects_to_json(list_objects): + return [obj.to_json() for obj in list_objects] @staticmethod def convert_list_objects_to_list_options(list_objects): return Store_Base.convert_list_objects_to_list_options(list_objects) @staticmethod + def convert_list_objects_to_dict_by_attribute_key(list_objects, key): + return {getattr(obj, key): obj for obj in list_objects} + @staticmethod + def convert_list_objects_to_dict_json_by_attribute_key(list_objects, key): + return {getattr(obj, key): obj.to_json() for obj in list_objects} + @staticmethod + def convert_list_objects_to_dict_by_attribute_key_default(list_objects): + if len(list_objects) == 0: + return {} + obj_class = list_objects[0].__class__ + return Model_View_Base.convert_list_objects_to_dict_by_attribute_key(list_objects, getattr(obj_class, obj_class.FLAG_NAME_ATTR_OPTION_VALUE)) + @staticmethod + def convert_list_objects_to_dict_json_by_attribute_key_default(list_objects): + if len(list_objects) == 0: + return {} + obj_class = list_objects[0].__class__ + return Model_View_Base.convert_list_objects_to_dict_json_by_attribute_key(list_objects, getattr(obj_class, obj_class.FLAG_NAME_ATTR_OPTION_VALUE)) + @staticmethod + def convert_dict_values_to_json(dict): + return {key: dict[key].to_json() for key in dict.keys()} + @staticmethod def join_with_linebreaks(strs): str_multiline = '' for str in strs: diff --git a/models/model_view_store.py b/models/model_view_store.py index 9b19b447..70349e59 100644 --- a/models/model_view_store.py +++ b/models/model_view_store.py @@ -17,19 +17,19 @@ Parent data model for store views # IMPORTS # internal # from context import models -from models.model_view_base import Model_View_Base from business_objects.store.store_base import Store_Base from business_objects.store.product import Product, Filters_Product, Product_Permutation # Product_Image_Filters, # from business_objects.store.product_category import Filters_Product_Category from business_objects.store.image import Resolution_Level_Enum -import lib.argument_validation as av +from business_objects.store.basket import Basket_Item, Basket +from business_objects.store.product_category import Product_Category +from business_objects.store.product_variation import Product_Variation_Filters, Product_Variation from datastores.datastore_store_base import DataStore_Store_Base from datastores.datastore_user import DataStore_User from datastores.datastore_store_basket import DataStore_Store_Basket from forms.forms import Form_Basket_Edit, Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency -from business_objects.store.basket import Basket_Item, Basket -from business_objects.store.product_category import Product_Category -from business_objects.store.product_variation import Product_Variation_Filters, Product_Variation +import lib.argument_validation as av +from models.model_view_base import Model_View_Base # external from flask import send_file, jsonify from flask_sqlalchemy import SQLAlchemy @@ -37,40 +37,66 @@ import locale from typing import ClassVar from abc import abstractmethod -# VARIABLE INSTANTIATION - -# CLASSES class Model_View_Store(Model_View_Base): # Global constants ATTR_FORM_TYPE: ClassVar[str] = 'form-type' - ATTR_ID_CATEGORY: ClassVar[str] = Product.ATTR_ID_PRODUCT_CATEGORY - # ATTR_ID_PRODUCT_CATEGORY : ClassVar[str] = 'id-product-category' ATTR_ID_PRODUCT : ClassVar[str] = Product.ATTR_ID_PRODUCT # 'id-product' - ATTR_ID_PERMUTATION : ClassVar[str] = Product.ATTR_ID_PRODUCT_PERMUTATION # 'id-permutation' - ATTR_ID_VARIATION : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION # 'id-variation' - ATTR_ID_VARIATION_TYPE : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION_TYPE # 'id-variation-type' - FLAG_BUTTON_BASKET_ADD : ClassVar[str] = Model_View_Base.FLAG_SUBMIT + '.buttonAdd2Basket' + ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = Product.ATTR_ID_PRODUCT_CATEGORY + ATTR_ID_PRODUCT_PERMUTATION : ClassVar[str] = Product.ATTR_ID_PRODUCT_PERMUTATION # 'id-permutation' + ATTR_ID_PRODUCT_VARIATION : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION # 'id-variation' + ATTR_ID_PRODUCT_VARIATION_TYPE : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION_TYPE # 'id-variation-type' + FLAG_BUTTON_BASKET_ADD : ClassVar[str] = Model_View_Base.FLAG_SUBMIT + '.buttonAddToBasket' FLAG_BUTTON_BUY_NOW : ClassVar[str] = 'buttonBuyNow' - FLAG_COST_LOCAL_VAT_INCL: ClassVar[str] = 'cost-local-VAT-incl' - FLAG_CURRENCY: ClassVar[str] = 'currency' + FLAG_COST_LOCAL: ClassVar[str] = Product_Permutation.FLAG_COST_LOCAL + # FLAG_COST_LOCAL_VAT_INCL: ClassVar[str] = 'cost-local-VAT-incl' + FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP: ClassVar[str] = Product_Permutation.FLAG_COUNT_UNIT_MEASUREMENT_PER_QUANTITY_STEP + FLAG_CURRENCY_COST: ClassVar[str] = Product_Permutation.FLAG_CURRENCY_COST FLAG_DATE_CONSUMED: ClassVar[str] = 'date-consumed' FLAG_DATE_EXPIRATION: ClassVar[str] = 'date-expiration' FLAG_DATE_PURCHASED: ClassVar[str] = 'date-purchased' FLAG_DATE_RECEIVED: ClassVar[str] = 'date-received' FLAG_DATE_UNSEALED: ClassVar[str] = 'date-unsealed' + FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_DOES_EXPIRE_FASTER_ONCE_UNSEALED + FLAG_HAS_VARIATIONS: ClassVar[str] = Product_Permutation.FLAG_HAS_VARIATIONS + FLAG_ID_STRIPE_PRODUCT: ClassVar[str] = Product_Permutation.FLAG_ID_STRIPE_PRODUCT FLAG_IS_NOT_EMPTY: ClassVar[str] = Store_Base.FLAG_IS_NOT_EMPTY FLAG_IS_OUT_OF_STOCK: ClassVar[str] = 'is-out-of-stock' + FLAG_IS_SUBSCRIPTION: ClassVar[str] = Product_Permutation.FLAG_IS_SUBSCRIPTION + FLAG_LATENCY_MANUFACTURE_DAYS: ClassVar[str] = Product_Permutation.FLAG_LATENCY_MANUFACTURE_DAYS FLAG_LOCATION_STORAGE: ClassVar[str] = 'storage-location' - FLAG_PRODUCT: ClassVar[str] = 'product' - FLAG_PRODUCT_CATEGORY: ClassVar[str] = 'category' + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_NAME_PLURAL_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.FLAG_NAME_PLURAL_UNIT_MEASUREMENT_QUANTITY + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.FLAG_NAME_SINGULAR_UNIT_MEASUREMENT_QUANTITY + FLAG_PRODUCT: ClassVar[str] = Store_Base.FLAG_PRODUCT + FLAG_PRODUCT_CATEGORY: ClassVar[str] = Store_Base.FLAG_PRODUCT_CATEGORY + FLAG_PRODUCT_PERMUTATION: ClassVar[str] = Store_Base.FLAG_PRODUCT_PERMUTATION + FLAG_PRODUCT_VARIATION: ClassVar[str] = Store_Base.FLAG_PRODUCT_VARIATION + FLAG_PRODUCT_VARIATIONS: ClassVar[str] = Store_Base.FLAG_PRODUCT_VARIATIONS + FLAG_PRODUCT_VARIATION_TYPE: ClassVar[str] = Store_Base.FLAG_PRODUCT_VARIATION_TYPE + FLAG_QUANTITY: ClassVar[str] = 'quantity' FLAG_QUANTITY_MAX: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MAX # 'quantity-max' FLAG_QUANTITY_MIN: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MIN # 'quantity-min' FLAG_QUANTITY_STOCK: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_STOCK # 'quantity-stock' FLAG_PLANT_STORAGE: ClassVar[str] = 'plant-storage' FLAG_PRODUCT_CATEGORY: ClassVar[str] = 'category' + FLAG_PROFIT_LOCAL_MIN: ClassVar[str] = Product_Permutation.FLAG_PROFIT_LOCAL_MIN FLAG_REGION_STORAGE: ClassVar[str] = 'region-storage' - FLAG_VARIATIONS: ClassVar[str] = 'variations' + FLAG_SYMBOL_CURRENCY_COST: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_CURRENCY_COST + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX_UNIT_MEASUREMENT_QUANTITY + FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_SYMBOL_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.FLAG_SYMBOL_UNIT_MEASUREMENT_QUANTITY + FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED: ClassVar[str] = Product_Permutation.FLAG_UNIT_MEASUREMENT_INTERVAL_EXPIRATION_UNSEALED + FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE: ClassVar[str] = Product_Permutation.FLAG_UNIT_MEASUREMENT_INTERVAL_RECURRENCE + FLAG_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.FLAG_UNIT_MEASUREMENT_QUANTITY HASH_PAGE_STORE_BASKET : ClassVar[str] = '/store/basket' HASH_STORE_BASKET_ADD : ClassVar[str] = '/store/basket_add' HASH_STORE_BASKET_DELETE : ClassVar[str] = '/store/basket_delete' @@ -78,10 +104,10 @@ class Model_View_Store(Model_View_Base): HASH_STORE_BASKET_LOAD : ClassVar[str] = '/store/basket_load' HASH_GET_STORE_PRODUCT: ClassVar[str] = '/store/product_get' HASH_GET_STORE_PRODUCT_CATEGORY: ClassVar[str] = '/store/category_get' - HASH_SAVE_STORE_PRODUCT: ClassVar[str] = '/store/product_save' + HASH_SAVE_STORE_PRODUCT: ClassVar[str] = '/store/save_product' HASH_GET_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_get' - HASH_SAVE_STORE_PRODUCT_CATEGORY: ClassVar[str] = '/store/category_save' - HASH_SAVE_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_save' + HASH_SAVE_STORE_PRODUCT_CATEGORY: ClassVar[str] = '/store/save_category' + HASH_SAVE_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/save_permutation' HASH_STORE_SET_CURRENCY : ClassVar[str] = '/store/set_currency' HASH_STORE_SET_DELIVERY_REGION : ClassVar[str] = '/store/set_delivery_region' HASH_STORE_SET_IS_INCLUDED_VAT : ClassVar[str] = '/store/set_is_included_VAT' @@ -91,13 +117,14 @@ class Model_View_Store(Model_View_Base): ID_BUTTON_CHECKOUT : ClassVar[str] = 'buttonCheckout' ID_BUTTON_BASKET_ADD : ClassVar[str] = 'buttonBasketAdd' ID_BUTTON_BUY_NOW : ClassVar[str] = 'buttonBuyNow' - ID_CATEGORY_DEFAULT: ClassVar[str] = 1 + ID_PRODUCT_CATEGORY_DEFAULT: ClassVar[str] = 1 ID_CURRENCY : ClassVar[str] = Form_Currency.id_id_currency # 'id_currency' ID_CURRENCY_DEFAULT : ClassVar[str] = 1 ID_LABEL_BASKET_EMPTY : ClassVar[str] = 'basketEmpty' ID_REGION_DELIVERY : ClassVar[str] = Form_Delivery_Region.id_id_region_delivery # 'id_region_delivery' ID_REGION_DELIVERY_DEFAULT : ClassVar[str] = 1 IS_INCLUDED_VAT_DEFAULT : ClassVar[str] = True + """ KEY_BASKET : ClassVar[str] = Basket.KEY_BASKET # 'basket' # KEY_CODE_CURRENCY : ClassVar[str] = 'code_currency' # KEY_FORM : ClassVar[str] = 'form' @@ -107,11 +134,10 @@ class Model_View_Store(Model_View_Base): KEY_ID_REGION_DELIVERY : ClassVar[str] = Basket.KEY_ID_REGION_DELIVERY # 'id_region_delivery' KEY_IS_INCLUDED_VAT : ClassVar[str] = Basket.KEY_IS_INCLUDED_VAT # 'is_included_VAT' KEY_ITEMS : ClassVar[str] = Basket.KEY_ITEMS # 'items' - KEY_NAME_VARIATION : ClassVar[str] = Product_Variation.KEY_NAME_VARIATION - KEY_NAME_VARIATION_TYPE : ClassVar[str] = Product_Variation.KEY_NAME_VARIATION_TYPE KEY_PRICE : ClassVar[str] = 'price' KEY_QUANTITY : ClassVar[str] = 'quantity' KEY_VALUE_DEFAULT : ClassVar[str] = 'default' + """ TYPE_FORM_BASKET_ADD : ClassVar[str] = 'Form_Basket_Add' TYPE_FORM_BASKET_EDIT : ClassVar[str] = 'Form_Basket_Edit' # development variables @@ -136,7 +162,7 @@ class Model_View_Store(Model_View_Base): print(f'{_m}\nstarting') # av.val_str(id_user, 'id_user', _m) # return super().__new__(cls, *args, **kwargs) - # cls.FLAG_BUTTON_BASKET_ADD = cls.FLAG_BUTTON_SUBMIT + '.buttonAdd2Basket' + # cls.FLAG_BUTTON_BASKET_ADD = cls.FLAG_BUTTON_SUBMIT + '.buttonAddToBasket' return super().__new__(cls, db, info_user, app) # Model_View_Store, cls """ @property @@ -160,7 +186,7 @@ class Model_View_Store(Model_View_Base): self.is_included_VAT = is_included_VAT self.show_delivery_option = True self.form_is_included_VAT = Form_Is_Included_VAT() - regions, currencies = self.get_regions_and_currencies() + regions, currencies = self.get_many_region_and_currency() self.form_currency = Form_Currency(id_currency=self.id_currency) self.form_currency.id_currency.choices = [(currency.id_currency, f'{currency.code} - {currency.name}') for currency in currencies] self.form_currency.id_currency.data = str(self.id_currency) if len(currencies) > 0 else None @@ -410,12 +436,18 @@ class Model_View_Store(Model_View_Base): # validation conducted by server return DataStore_User().get_many_user_order(self.info_user['sub'], ids_order, n_order_max, id_checkout_session) - def get_regions_and_currencies(self): - regions, currencies = DataStore_Store_Base().get_regions_and_currencies() + def get_many_currency(self): + currencies = DataStore_Store_Base().get_many_currency() + return currencies + def get_many_region(self): + regions = DataStore_Store_Base().get_many_region() + return regions + def get_many_region_and_currency(self): + regions, currencies = DataStore_Store_Base().get_many_region_and_currency() return regions, currencies def get_many_product_variation(self, variation_filters = None): if variation_filters is None: variation_filters = Product_Variation_Filters.get_default() - variations, errors = DataStore_Store_Base().get_many_product_variation(variation_filters) - return variations, errors \ No newline at end of file + variation_types, variations, errors = DataStore_Store_Base().get_many_product_variation(variation_filters) + return variation_types, variations, errors \ No newline at end of file diff --git a/models/model_view_store_product_category.py b/models/model_view_store_product_category.py index 34645d5d..bfc47126 100644 --- a/models/model_view_store_product_category.py +++ b/models/model_view_store_product_category.py @@ -14,13 +14,13 @@ Data model for store permutations view from models.model_view_store import Model_View_Store # from datastores.datastore_store_base import DataStore_Store_Base from datastores.datastore_store_product_category import DataStore_Store_Product_Category -from business_objects.store.access_level import Filters_Access_Level from business_objects.store.product_category import Product_Category_Container # , Filters_Product_Category -from forms.forms import Form_Filters_Permutation +from forms.access_level import Filters_Access_Level +# from forms.store.product_permutation import Filters_Product_Permutation from forms.store.product_category import Filters_Product_Category # from routes import bp_home from business_objects.store.product import Product, Filters_Product, Product_Permutation -from business_objects.store.product_variation import Product_Variation_List +from business_objects.store.product_variation import Product_Variation_Container import lib.argument_validation as av # external diff --git a/models/model_view_store_product_permutation.py b/models/model_view_store_product_permutation.py index 011b3244..fcbbceef 100644 --- a/models/model_view_store_product_permutation.py +++ b/models/model_view_store_product_permutation.py @@ -14,10 +14,10 @@ Data model for store permutations view from models.model_view_store import Model_View_Store from datastores.datastore_store_product_permutation import DataStore_Store_Product_Permutation from business_objects.store.product_category import Product_Category_Container -from forms.forms import Form_Filters_Permutation +from forms.store.product_permutation import Filters_Product_Permutation # from routes import bp_home from business_objects.store.product import Product, Filters_Product, Product_Permutation -from business_objects.store.product_variation import Product_Variation_List +from business_objects.store.product_variation import Product_Variation_Container import lib.argument_validation as av # external @@ -30,51 +30,67 @@ class Model_View_Store_Product_Permutation(Model_View_Store): ID_FILTER_IS_OUT_OF_STOCK: ClassVar[str] = 'is_out_of_stock' ID_FILTER_QUANTITY_MIN: ClassVar[str] = 'quantity_min' ID_FILTER_QUANTITY_MAX: ClassVar[str] = 'quantity_max' - # ID_Form_Filters_Permutation: ClassVar[str] = 'Form_Filters_Permutation' + # ID_Filters_Product_Permutation: ClassVar[str] = 'Filters_Product_Permutation' KEY_PERMUTATIONS: ClassVar[str] = 'permutations' - category_list: Product_Category_Container = None # (str) - filters_product: Filters_Product - form_filters: Form_Filters_Permutation = None + category_list: Product_Category_Container = None + category_list_filters: Product_Category_Container = None + currencies: list = None + currency_options: list = None + filters_product: Filters_Product = None + form_filters: Filters_Product_Permutation + list_options_product: list = None permutation_blank: Product_Permutation = None - variations: Product_Variation_List = None - + units_measurement: list = None + units_measurement_time: list = None + # variation_container: Product_Variation_Container = None + variations: list = None + variation_types: list = None + @property def title(self): return 'Product Permutations' - def __init__(self, filters_product, hash_page_current=Model_View_Store.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS): + def __init__(self, form_filters, hash_page_current=Model_View_Store.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS): _m = 'Model_View_Store_Permutation.__init__' print(f'{_m}\nstarting...') - super().__init__(hash_page_current=hash_page_current, filters_product=filters_product) - # BaseModel.__init__(self, app=app, filters_product=filters_product, **kwargs) - self.form_filters = Form_Filters_Permutation() + super().__init__(hash_page_current=hash_page_current, form_filters=form_filters) + # self.form_filters = Filters_Product_Permutation() + filters_product = Filters_Product.from_form_filters_product_permutation(self.form_filters) datastore_store = DataStore_Store_Product_Permutation() self.category_list, errors = datastore_store.get_many_product(filters_product) - category_list_filters, errors_filters = datastore_store.get_many_product( + self.category_list_filters, errors_filters = datastore_store.get_many_product( Filters_Product( - # self.info_user['sub'], - True, False, '', - True, False, '', - True, False, '', - False, False, '', - # False, False, False, '', - # False, False, False, '', - # False, False, '', - filters_product.get_products_quantity_stock_below_min + get_all_product_category = True, + get_inactive_product_category = False, + ids_product_category = '', + get_all_product = True, + get_inactive_product = False, + ids_product = '', + get_all_permutation = True, + get_inactive_permutation = False, + ids_permutation = '', + get_all_image = False, + get_inactive_image = False, + ids_image = '', + get_products_quantity_stock_below_min = filters_product.get_products_quantity_stock_below_min ) ) - print(f'category_list_filters: {category_list_filters.categories}') - self.form_filters.id_category.choices = [('0', 'All')] + [(str(category.id_category), category.name) for category in category_list_filters.categories] + print(f'category filters: {self.category_list_filters.categories}') + self.form_filters.id_category.choices = [('0', 'All')] + [(str(category.id_category), category.name) for category in self.category_list_filters.categories] print(f'category options: {self.form_filters.id_category.choices}') - product_list = category_list_filters.to_product_option_list() - print(f'product_list: {product_list}') - self.form_filters.id_product.choices = [('0', 'All')] + [(str(product['value']), product['text']) for product in product_list] + self.list_options_product = self.category_list_filters.to_product_option_list() + print(f'product options: {self.list_options_product}') + self.form_filters.id_product.choices = [('0', 'All')] + [(str(product['value']), product['text']) for product in self.list_options_product] self.permutation_blank = Product_Permutation() print(f'category options: {self.form_filters.id_category.choices}') - variations, errors = self.get_many_product_variation() - self.variations = variations + self.variation_types, self.variations, errors = self.get_many_product_variation() + self.units_measurement = self.get_many_unit_measurement() + self.units_measurement_time = [unit_measurement for unit_measurement in self.units_measurement if unit_measurement.is_unit_of_time] + self.currencies = self.get_many_currency() + self.currency_options = [currency.to_json_option() for currency in self.currencies] - def save_permutations(self, comment, list_permutations): + @staticmethod + def save_permutations(comment, list_permutations): _m = 'Model_View_Store_Permutation.save_permutations' - DataStore_Store_Product_Permutation().save_permutations(comment, list_permutations) \ No newline at end of file + DataStore_Store_Product_Permutation.save_permutations(comment, list_permutations) \ No newline at end of file diff --git a/routes.py b/routes.py deleted file mode 100644 index d93a97ad..00000000 --- a/routes.py +++ /dev/null @@ -1,54 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Backend -Feature: Controller - Webpage routing - -Description: -Defines the routes and view functions for each page. -Manages the interaction between the frontend and backend. -""" - -from flask import render_template, url_for, Blueprint -from app import app -from app.forms import Form_Contact -# from forms import MyForm -# from app import MyForm -from model_view_contact import Model_View_Contact - -""" -@app.route('/', methods=['GET']) -def home(): - return render_template('_home.html', title='Home') - -@app.route('/store', methods=['GET']) -def store_home(): - return render_template('_store_home.html', title='Store Home') - -@app.route('/contact', methods=['GET', 'POST']) -def contact(): - form = Form_Contact() - if form.validate_on_submit(): - # Handle form submission - email = form.sender_email.data - CC = form.sender_CC.data - name = form.sender_name.data - msg = form.sender_message.data - # return render_template('contact.html', form=form) - # return render_template('_contact.html', title='Contact Us') - return render_template('contact.html', model=Model_View_Contact(form)) - -@app.route('/about') -def about(): - return render_template('about.html') - -@app.route('/contact', methods=['GET', 'POST']) -def contact(): - form = MyForm() - if form.validate_on_submit(): - # Handle form submission - pass - return render_template('contact.html', form=form) -""" \ No newline at end of file diff --git a/routing/__pycache__/core.cpython-312.pyc b/routing/__pycache__/core.cpython-312.pyc deleted file mode 100644 index d4671612..00000000 Binary files a/routing/__pycache__/core.cpython-312.pyc and /dev/null differ diff --git a/routing/store/__pycache__/product_permutation.cpython-312.pyc b/routing/store/__pycache__/product_permutation.cpython-312.pyc deleted file mode 100644 index be337c63..00000000 Binary files a/routing/store/__pycache__/product_permutation.cpython-312.pyc and /dev/null differ diff --git a/routing/store/__pycache__/stock_item.cpython-312.pyc b/routing/store/__pycache__/stock_item.cpython-312.pyc deleted file mode 100644 index 5f520ad9..00000000 Binary files a/routing/store/__pycache__/stock_item.cpython-312.pyc and /dev/null differ diff --git a/routing/store/product_permutation.py b/routing/store/product_permutation.py deleted file mode 100644 index 55b45281..00000000 --- a/routing/store/product_permutation.py +++ /dev/null @@ -1,90 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: App Routing -Feature: Store Product Permutation Routes - -Description: -Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles. -""" - - -# internal -from business_objects.store.product import Product, Filters_Product, Product_Permutation -from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters -from forms.forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item -from models.model_view_base import Model_View_Base -from models.model_view_store import Model_View_Store -from models.model_view_store_supplier import Model_View_Store_Supplier -from models.model_view_store_product_category import Model_View_Store_Product_Category -from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation -from models.model_view_store_stock_items import Model_View_Store_Stock_Items -from helpers.helper_app import Helper_App -import lib.argument_validation as av -# external -from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app -from extensions import db, oauth -from urllib.parse import quote_plus, urlencode -from authlib.integrations.flask_client import OAuth -from authlib.integrations.base_client import OAuthError -from urllib.parse import quote, urlparse, parse_qs - - -routes_store_product_permutation = Blueprint('routes_store_product_permutation', __name__) - - -@routes_store_product_permutation.route('/store/permutations', methods=['GET']) -def permutation(): - filters = Filters_Product.get_default() - model = Model_View_Store_Product_Permutation(filters_product=filters) - return render_template('pages/store/_product_permutations.html', model = model) - -@routes_store_product_permutation.route('/store/permutation_filter', methods=['POST']) -def permutation_filter(): - data = Helper_App.get_request_data(request) - form_filters = None - try: - form_filters = get_Form_Filters_Permutation(data) - if not form_filters.validate_on_submit(): - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Form invalid.\n{form_filters.errors}'}) - # ToDo: manually validate category, product - filters_form = Filters_Product.from_form(form_filters) - model = Model_View_Store_Product_Permutation(filters_product=filters_form) - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model.category_list.to_permutation_row_list()}) - except Exception as e: - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'}) - -def get_Form_Filters_Permutation(data_request): - data_form = data_request[Model_View_Store_Product_Permutation.KEY_FORM] - form_filters = Form_Filters_Permutation(**data_form) - form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post') - return form_filters - -@routes_store_product_permutation.route('/store/permutation_save', methods=['POST']) -def permutation_save(): - data = Helper_App.get_request_data(request) - form_filters = None - try: - form_filters = get_Form_Filters_Permutation(data) - if not form_filters.validate_on_submit(): - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Filters form invalid.\n{form_filters.errors}'}) - - permutations = data[Model_View_Store_Product_Permutation.KEY_PERMUTATIONS] - if len(permutations) == 0: - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'No permutations.'}) - objsPermutation = [] - for permutation in permutations: - objsPermutation.append(Product_Permutation.from_json(permutation)) - - # ToDo: manually validate category, product - filters_form = Filters_Product.from_form(form_filters) - model_save = Model_View_Store_Product_Permutation(filters_product=filters_form) - model_save.save_permutations(data.comment, objsPermutation) - - model_return = Model_View_Store_Product_Permutation(filters_product=filters_form) - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model_return.category_list.to_permutation_row_list()}) - except Exception as e: - return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.STATUS_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'}) - \ No newline at end of file diff --git a/static/MySQL/0000_combine.sql b/static/MySQL/0000_combine.sql index 4be14818..0d110991 100644 --- a/static/MySQL/0000_combine.sql +++ b/static/MySQL/0000_combine.sql @@ -146,8 +146,8 @@ DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; DROP TABLE IF EXISTS Shop_Product_Permutation; -DROP TABLE IF EXISTS Shop_Recurrence_Interval_Audit; -DROP TABLE IF EXISTS Shop_Recurrence_Interval; +DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; +DROP TABLE IF EXISTS Shop_Interval_Recurrence; DROP TABLE IF EXISTS Shop_Product_Audit; DROP TABLE IF EXISTS Shop_Product; @@ -221,9 +221,14 @@ DROP TABLE IF EXISTS Shop_Product_Change_Set; DROP PROCEDURE IF EXISTS p_split; DROP PROCEDURE IF EXISTS p_clear_split_temp; +DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; + DROP PROCEDURE IF EXISTS p_shop_user_eval; DROP PROCEDURE IF EXISTS p_clear_shop_user_eval_temp; +DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; +DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; + DROP PROCEDURE IF EXISTS p_shop_get_many_region; DROP PROCEDURE IF EXISTS p_shop_get_many_currency; @@ -312,6 +317,9 @@ CREATE TABLE IF NOT EXISTS Shop_Access_Level ( FOREIGN KEY (id_change_set) REFERENCES Shop_User_Change_Set(id_change_set) ); + + + # Access Level Audits @@ -923,6 +931,7 @@ CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( name_singular VARCHAR(255) NOT NULL, name_plural VARCHAR(256) NOT NULL, symbol VARCHAR(50) NOT NULL, + symbol_is_suffix_not_prefix BIT NOT NULL DEFAULT 1, is_base_unit BIT NOT NULL DEFAULT 0, is_unit_of_distance BIT NOT NULL DEFAULT 0, is_unit_of_mass BIT NOT NULL DEFAULT 0, @@ -1051,6 +1060,8 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( # Categories Temp +-- DROP TABLE Shop_Product_Category_Temp; + SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Temp'; CREATE TABLE IF NOT EXISTS Shop_Product_Category_Temp ( @@ -1060,10 +1071,8 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Category_Temp ( , description VARCHAR(4000) NULL , active BIT NOT NULL , display_order INT NOT NULL - , id_access_level_required INT NOT NULL + , id_access_level_required INT NOT NULL DEFAULT 1 , guid BINARY(36) NOT NULL - , created_on TIMESTAMP NOT NULL - , created_by INT NOT NULL ); # Products @@ -1092,11 +1101,11 @@ CREATE TABLE IF NOT EXISTS Shop_Product ( quantity_step FLOAT, quantity_stock FLOAT, is_subscription BIT, - id_recurrence_interval INT, - CONSTRAINT FK_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, */ id_access_level_required INT NOT NULL, CONSTRAINT FK_Shop_Product_id_access_level_required @@ -1172,26 +1181,30 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( id_currency_cost INT NOT NULL, profit_local_min FLOAT NOT NULL, -- id_currency_profit_min INT NOT NULL, - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, + id_unit_measurement_quantity INT NOT NULL, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_quantity + FOREIGN KEY (id_unit_measurement_quantity) + REFERENCES Shop_Unit_Measurement(id_unit_measurement), + count_unit_measurement_per_quantity_step FLOAT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_id_interval_recurrence - FOREIGN KEY (id_interval_recurrence) + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) REFERENCES Shop_Unit_Measurement(id_unit_measurement), /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_recurrence - CHECK (id_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), + CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence + CHECK (id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), */ count_interval_recurrence INT, id_stripe_product VARCHAR(100) NULL, does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_id_interval_expiration_unsealed - FOREIGN KEY (id_interval_expiration_unsealed) + id_unit_measurement_interval_expiration_unsealed INT, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_expiration_unsealed + FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) REFERENCES Shop_Unit_Measurement(id_unit_measurement), /* CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_expiration_unsealed @@ -1248,28 +1261,30 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Temp ( cost_local FLOAT NOT NULL, id_currency_cost INT NOT NULL, profit_local_min FLOAT NOT NULL, - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, + id_unit_measurement_quantity INT NOT NULL, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_quantity + FOREIGN KEY (id_unit_measurement_quantity) + REFERENCES Shop_Unit_Measurement(id_unit_measurement), + count_unit_measurement_per_quantity_step FLOAT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, + quantity_stock FLOAT NULL, is_subscription BIT NOT NULL, - id_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_Temp_id_interval_recurrence - FOREIGN KEY (id_interval_recurrence) + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) REFERENCES Shop_Unit_Measurement(id_unit_measurement), count_interval_recurrence INT, id_stripe_product VARCHAR(100) NULL, does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_Temp_id_interval_expiration_unsealed - FOREIGN KEY (id_interval_expiration_unsealed) + id_unit_measurement_interval_expiration_unsealed INT, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_expiration + FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) REFERENCES Shop_Unit_Measurement(id_unit_measurement), count_interval_expiration_unsealed INT, active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on TIMESTAMP, - created_by INT, + -- display_order INT NOT NULL, guid BINARY(36) ); @@ -3622,11 +3637,11 @@ BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -3696,13 +3711,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set @@ -3759,16 +3774,16 @@ BEGIN END IF; IF (NOT ( - NEW.id_interval_recurrence IS NULL - OR NEW.id_interval_recurrence NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) + NEW.id_unit_measurement_interval_recurrence IS NULL + OR NEW.id_unit_measurement_interval_recurrence NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Recurrence interval ID must be a unit of time.'; END IF; IF (NOT ( - NEW.id_interval_expiration_unsealed IS NULL - OR NEW.id_interval_expiration_unsealed NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) + NEW.id_unit_measurement_interval_expiration_unsealed IS NULL + OR NEW.id_unit_measurement_interval_expiration_unsealed NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Unsealed expiration interval ID must be a unit of time.'; @@ -3807,11 +3822,11 @@ BEGIN SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) UNION + /* # Changed profit_local_min SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) UNION - /* # Changed id_currency_profit_min SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) @@ -3823,36 +3838,40 @@ BEGIN WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - # Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + # Changed latency_manufacture_days + SELECT NEW.id_permutation, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days + UNION + # Changed id_unit_measurement_quantity + SELECT NEW.id_permutation, 'id_unit_measurement_quantity', CONVERT(OLD.id_unit_measurement_quantity, CHAR), CONVERT(NEW.id_unit_measurement_quantity, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_quantity <=> NEW.id_unit_measurement_quantity + UNION + # Changed count_unit_measurement_per_quantity_step + SELECT NEW.id_permutation, 'count_unit_measurement_per_quantity_step', CONVERT(OLD.count_unit_measurement_per_quantity_step, CHAR), CONVERT(NEW.count_unit_measurement_per_quantity_step, CHAR), NEW.id_change_set + WHERE NOT OLD.count_unit_measurement_per_quantity_step <=> NEW.count_unit_measurement_per_quantity_step UNION # Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_min <=> NEW.quantity_min UNION # Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_max <=> NEW.quantity_max UNION - # Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION # Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock UNION # Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_interval_recurrence - SELECT NEW.id_product, 'id_interval_recurrence', CONVERT(OLD.id_interval_recurrence, CHAR), CONVERT(NEW.id_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_interval_recurrence <=> NEW.id_interval_recurrence + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_permutation, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION # Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product @@ -3860,24 +3879,26 @@ BEGIN WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) UNION # Changed does_expire_faster_once_unsealed - SELECT NEW.id_product, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set WHERE NOT OLD.does_expire_faster_once_unsealed <=> NEW.does_expire_faster_once_unsealed UNION - # Changed id_interval_expiration_unsealed - SELECT NEW.id_product, 'id_interval_expiration_unsealed', CONVERT(OLD.id_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_interval_expiration_unsealed, CHAR), NEW.id_change_set - WHERE NOT OLD.id_interval_expiration_unsealed <=> NEW.id_interval_expiration_unsealed + # Changed id_unit_measurement_interval_expiration_unsealed + SELECT NEW.id_permutation, 'id_unit_measurement_interval_expiration_unsealed', CONVERT(OLD.id_unit_measurement_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_unit_measurement_interval_expiration_unsealed, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_expiration_unsealed <=> NEW.id_unit_measurement_interval_expiration_unsealed UNION # Changed count_interval_expiration_unsealed - SELECT NEW.id_product, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set WHERE NOT OLD.count_interval_expiration_unsealed <=> NEW.count_interval_expiration_unsealed UNION # Changed active SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set WHERE NOT (OLD.active <=> NEW.active) - UNION + /* + UNION # Changed display_order SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set WHERE NOT (OLD.display_order <=> NEW.display_order) + */ ; END // DELIMITER ;; @@ -5938,6 +5959,36 @@ FROM Shop_User_Eval_Temp; */ +DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; + +DELIMITER // + +CREATE FUNCTION fn_shop_get_product_permutation_name(id_product_permutation INT) +RETURNS VARCHAR(4000) +DETERMINISTIC +BEGIN + DECLARE name VARCHAR(4000); + + SET name := ( + SELECT + CONCAT( + P.name + , CASE WHEN P.has_variations = 1 THEN + CONCAT(' - ', GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ')) + ELSE '' END + ) + FROM Shop_Product_Permutation PP + INNER JOIN Shop_Product P ON PP.id_product = P.id_product + INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation + INNER JOIN Shop_Product_Variation V ON PPVL.id_variation = V.id_variation + INNER JOIN Shop_Product_Variation_Type VT ON V.id_type = VT.id_type + ); + + RETURN name; +END // + +DELIMITER ; + @@ -6732,6 +6783,51 @@ FROM Shop_User_Eval_Temp; +/* + +CALL p_shop_get_many_access_level ( + 0 # a_get_inactive_access_level +) + +*/ + + +-- Clear previous proc +DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; + + +DELIMITER // +CREATE PROCEDURE p_shop_get_many_access_level ( + IN a_get_inactive_access_level BIT +) +BEGIN + SET a_get_inactive_access_level = IFNULL(a_get_inactive_access_level, 0); + + SELECT + AL.id_access_level, + AL.code, + AL.name, + AL.active, + AL.priority, + AL.display_order + FROM Shop_Access_Level AL + WHERE + a_get_inactive_access_level = 1 + OR AL.active = 1 + ORDER BY AL.display_order + ; +END // +DELIMITER ;; + + +/* +CALL p_shop_get_many_access_level ( + 0 # a_get_inactive_access_level +); +*/ + + + /* CALL p_shop_get_many_region ( @@ -6803,9 +6899,10 @@ BEGIN C.id_currency, C.code, C.name, + C.symbol, C.factor_from_GBP, - C.active, - C.display_order + C.display_order, + C.active FROM Shop_Currency C WHERE a_get_inactive_currency OR C.active @@ -6821,8 +6918,47 @@ CALL p_shop_get_many_currency ( ); */ +-- Clear previous proc +DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; +DELIMITER // +CREATE PROCEDURE p_shop_get_many_unit_measurement ( + IN a_get_inactive_unit_measurement BIT +) +BEGIN + SET a_get_inactive_unit_measurement := IFNULL(a_get_inactive_unit_measurement, 0); + + SELECT + UM.id_unit_measurement, + UM.name_singular, + UM.name_plural, + UM.symbol, + UM.symbol_is_suffix_not_prefix, + UM.is_base_unit, + UM.is_unit_of_distance, + UM.is_unit_of_mass, + UM.is_unit_of_time, + UM.is_unit_of_volume, + UM.active + FROM Shop_Unit_Measurement UM + WHERE + a_get_inactive_unit_measurement = 1 + OR UM.active = 1 + ; +END // +DELIMITER ;; + + +/* +CALL p_shop_get_many_unit_measurement ( + 0 # a_get_inactive_unit_measurement +); + +select * +from shop_unit_measurement +*/ + -- Clear previous proc DROP PROCEDURE IF EXISTS p_save_category; @@ -6897,6 +7033,7 @@ BEGIN , code VARCHAR(50) NOT NULL , name VARCHAR(255) NOT NULL , description VARCHAR(4000) NULL + , id_access_level_required INT NOT NULL , active BIT NOT NULL , display_order INT NOT NULL , can_view BIT NULL @@ -6921,6 +7058,7 @@ BEGIN , code , name , description + , id_access_level_required , active , display_order , name_error @@ -6931,6 +7069,7 @@ BEGIN , IFNULL(PC_T.code, PC.code) AS code , IFNULL(PC_T.name, PC.code) AS name , IFNULL(PC_T.description, PC.description) AS description + , IFNULL(PC_T.id_access_level_required, PC.id_access_level_required) AS id_access_level_required , IFNULL(PC_T.active, PC.active) AS active , IFNULL(PC_T.display_order, PC.display_order) AS display_order , IFNULL(PC_T.name, IFNULL(PC.name, IFNULL(PC_T.code, IFNULL(PC.code, IFNULL(PC_T.id_category, '(No Product Category)'))))) AS name_error @@ -6940,9 +7079,6 @@ BEGIN WHERE PC_T.guid = a_guid ; - SELECT * - FROM tmp_Category; - -- Validation -- Missing mandatory fields -- code @@ -7045,6 +7181,7 @@ BEGIN , PC.code = t_C.code , PC.name = t_C.name , PC.description = t_C.description + , PC.id_access_level_required = t_C.id_access_level_required , PC.active = t_C.active , PC.display_order = t_C.display_order , PC.id_change_set = v_id_change_set @@ -7055,6 +7192,7 @@ BEGIN code , name , description + , id_access_level_required , active , display_order , created_by @@ -7065,6 +7203,7 @@ BEGIN t_C.code AS code , t_C.name AS name , t_C.description AS description + , t_C.id_access_level_required AS id_access_level_required , t_C.active AS active , t_C.display_order AS display_order , a_id_user AS created_by @@ -7680,10 +7819,10 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; DROP TEMPORARY TABLE IF EXISTS tmp_Product; DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Copy; + DROP TEMPORARY TABLE IF EXISTS tmp_Image; + DROP TEMPORARY TABLE IF EXISTS tmp_Product; + DROP TEMPORARY TABLE IF EXISTS tmp_Product_2; + DROP TEMPORARY TABLE IF EXISTS tmp_Product_Copy; CREATE TEMPORARY TABLE tmp_Category ( @@ -7693,23 +7832,23 @@ BEGIN ); CREATE TEMPORARY TABLE tmp_Product ( - -- id_category INT NOT NULL, + id_category INT NOT NULL, id_product INT NOT NULL, active BIT NOT NULL, - display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - -- id_category INT NOT NULL, - id_product INT NOT NULL, - id_permutation INT NULL, - active BIT NOT NULL, display_order INT NOT NULL, can_view BIT, can_edit BIT, can_admin BIT ); + CREATE TEMPORARY TABLE tmp_Permutation ( + id_permutation INT NULL + -- id_category INT NOT NULL, + , id_product INT NOT NULL + , active BIT NOT NULL + -- , display_order INT NOT NULL + ); + CREATE TEMPORARY TABLE tmp_Image ( id_image INT NOT NULL, -- id_product INT NOT NULL, @@ -7760,13 +7899,13 @@ BEGIN ; INSERT INTO tmp_Product ( - -- id_category, + id_category, id_product, active, display_order ) SELECT - -- P.id_category, + P.id_category, P.id_product, P.active, P.display_order @@ -7786,18 +7925,18 @@ BEGIN ; INSERT INTO tmp_Permutation ( + id_permutation -- id_category, - id_product, - id_permutation, - active, - display_order + , id_product + , active + -- , display_order ) SELECT + PP.id_permutation -- P.id_category, - PP.id_product, - PP.id_permutation, - PP.active, - PP.display_order + , PP.id_product + , PP.active + -- , RANK() OVER (ORDER BY VT.display_order, V.display_order) FROM Shop_Product_Permutation PP INNER JOIN tmp_Product t_P ON PP.id_product = t_P.id_product WHERE ( @@ -7817,12 +7956,10 @@ BEGIN ) ; - select 'nips'; - # Product Images - -- CREATE TEMPORARY TABLE tmp_Shop_Product_Copy SELECT * FROM tmp_Shop_Product; + -- CREATE TEMPORARY TABLE tmp_Product_Copy SELECT * FROM tmp_Product; - INSERT INTO tmp_Shop_Image ( + INSERT INTO tmp_Image ( -- id_product id_permutation , id_image @@ -7837,7 +7974,7 @@ BEGIN , t_P.id_permutation , t_P.product_has_variations , t_P.rank_permutation - FROM tmp_Shop_Product t_P + FROM tmp_Product t_P ) */ SELECT @@ -7848,49 +7985,26 @@ BEGIN , I.display_order -- , RANK() OVER (PARTITION BY IPP.id_product, IPP.id_permutation ORDER BY IPP.display_order_product_temp, IPP.display_order_image) FROM Shop_Product_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND NOT t_P.product_has_variations - /* - FROM ( - SELECT - -- t_P.id_product - I.id_permutation - , I.id_image - , I.active - , I.display_order AS display_order_image - -- , t_P.rank_permutation AS display_order_product_temp - FROM Shop_Product_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND NOT t_P.product_has_variations - - UNION - SELECT - -- t_P2_Copy.id_product - I.id_permutation - , I.id_image - , I.active - , I.display_order AS display_order_image - -- , t_P2.rank_permutation AS display_order_product_temp - FROM Shop_Product_Image I - INNER JOIN tmp_Shop_Product_Copy t_P_Copy - ON I.id_permutation = t_P_Copy.id_permutation - AND t_P_Copy.product_has_variations - ) IPP - */ - WHERE (a_get_all_image OR FIND_IN_SET(id_image, a_ids_image) > 0) - AND (a_get_inactive_image OR I.active) + INNER JOIN tmp_Permutation t_PP ON I.id_permutation = t_PP.id_permutation + INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product + WHERE + P.has_variations = 0 + AND ( + a_get_all_image = 1 OR + FIND_IN_SET(id_image, a_ids_image) > 0 + ) + AND ( + a_get_inactive_image = 1 + OR I.active = 1 + ) ; - select 'nips'; - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product LIMIT 1) THEN + IF EXISTS (SELECT * FROM tmp_Product LIMIT 1) THEN # SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); + SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_product)); + -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_permutation)); -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; -- select * from Shop_User_Eval_Temp; @@ -7908,18 +8022,18 @@ BEGIN t_P.can_admin = UE_T.can_admin ; -- select * from Shop_User_Eval_Temp; - -- select * from tmp_Shop_Product; + -- select * from tmp_Product; SET v_ids_product_invalid := ( - SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') - FROM tmp_Product P + SELECT GROUP_CONCAT(t_P.id_product SEPARATOR ',') + FROM tmp_Product t_P WHERE ISNULL(t_P.can_view) ); DELETE -- t_PC FROM tmp_Category t_PC WHERE t_PC.id_category IN ( - SELECT id_category + SELECT PC.id_category FROM Shop_Product_Category PC INNER JOIN Shop_Product P ON PC.id_category = P.id_category WHERE FIND_IN_SET(P.id_product, v_ids_product_invalid) > 0 @@ -7945,9 +8059,7 @@ BEGIN */ END IF; - select 'nips'; - - -- select * from tmp_Shop_Product; + -- select * from tmp_Product; -- Returns -- SET v_now := NOW(); @@ -7959,15 +8071,18 @@ BEGIN , PC.code , PC.name , PC.description + , PC.id_access_level_required + , AL.name AS name_access_level_required , PC.display_order , PC.active , MIN(t_P.can_view) AS can_view , MIN(t_P.can_edit) AS can_edit , MIN(t_P.can_admin) AS can_admin FROM tmp_Category t_C - INNER JOIN Shop_product_category PC - ON t_P.id_category = PC.id_category - -- GROUP BY t_P.id_category + INNER JOIN Shop_Product_Category PC ON t_C.id_category = PC.id_category + LEFT JOIN tmp_Product t_P ON t_C.id_category = t_P.id_product + INNER JOIN Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level + GROUP BY t_C.id_category -- , t_P.id_product ORDER BY PC.display_order ; @@ -7976,24 +8091,20 @@ BEGIN t_P.id_product, P.id_category, P.name, - P.description, P.has_variations, - P.latency_manufacture, - P.quantity_min, - P.quantity_max, - P.quantity_step, - P.quantity_stock, - P.id_stripe_product, - P.is_subscription, + P.id_access_level_required, + AL.name AS name_access_level_required, P.active, P.display_order, t_P.can_view, t_P.can_edit, t_P.can_admin - FROM tmp_Shop_Product t_P + FROM tmp_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - GROUP BY C.id_category, P.id_product - ORDER BY PC.display_order, P.display_order + INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category + INNER JOIN Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level + GROUP BY t_P.id_category, t_C.display_order, t_P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin + ORDER BY t_C.display_order, P.display_order ; # Product Permutations @@ -8001,47 +8112,73 @@ BEGIN t_PP.id_permutation, PP.id_product, P.id_category, + PP.description, PP.cost_local, PP.id_currency_cost, C.code AS code_currency_cost, C.symbol AS symbol_currency_cost, - PP.profit_local_min, - P.is_subscription, - UM.name_singular AS name_recurrence_interval, - UM.name_plural AS name_plural_recurrence_interval, + -- PP.profit_local_min, + PP.latency_manufacture_days, + PP.id_unit_measurement_quantity, + UM_Q.symbol AS symbol_unit_measurement_quantity, + UM_Q.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_quantity, + UM_Q.name_singular AS name_singular_unit_measurement_quantity, + UM_Q.name_plural AS name_plural_unit_measurement_quantity, + PP.count_unit_measurement_per_quantity_step, + PP.quantity_min, + PP.quantity_max, + PP.quantity_stock, + PP.is_subscription, + PP.id_unit_measurement_interval_recurrence, + UM_R.symbol AS symbol_unit_measurement_interval_recurrence, + UM_R.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence, + UM_R.name_singular AS name_singular_unit_measurement_interval_recurrence, + UM_R.name_plural AS name_plural_unit_measurement_interval_recurrence, PP.count_interval_recurrence, - t_PP.active, - t_PP.display_order, - IFNULL(t_PP.can_view, 0) AS can_view, - IFNULL(t_PP.can_edit, 0) AS can_edit, - IFNULL(t_PP.can_admin, 0) AS can_admin - FROM tmp_Shop_Product_Permutation t_PP + PP.id_stripe_product, + PP.does_expire_faster_once_unsealed, + PP.id_unit_measurement_interval_expiration_unsealed, + UM_X.symbol AS symbol_unit_measurement_interval_expiration_unsealed, + UM_X.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed, + UM_X.name_singular AS name_singular_unit_measurement_interval_expiration_unsealed, + UM_X.name_plural AS name_plural_unit_measurement_interval_expiration_unsealed, + PP.count_interval_expiration_unsealed, + NOT ISNULL(PPVL.id_permutation) AS has_variations, + PP.active, + -- PP.display_order, + IFNULL(t_P.can_view, 0) AS can_view, + IFNULL(t_P.can_edit, 0) AS can_edit, + IFNULL(t_P.can_admin, 0) AS can_admin + FROM tmp_Permutation t_PP INNER JOIN Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation + INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product INNER JOIN Shop_Product_Category PC ON P.id_category = PC.id_category - -- LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_interval_recurrence = UM.id_unit_measurement + LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation + LEFT JOIN Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement + LEFT JOIN Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement + LEFT JOIN Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement INNER JOIN Shop_Currency C ON PP.id_currency_cost = C.id_currency - GROUP BY C.id_category, P.id_product, PP.id_permutation - ORDER BY PC.display_order, P.display_order, PP.display_order + GROUP BY PC.id_category, P.id_product, PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin + ORDER BY PC.display_order, P.display_order -- , t_PP.display_order ; # Variations SELECT V.id_variation + , V.id_type , V.code AS code_variation , V.name AS name_variation + , V.display_order AS display_order_variation , V.active AS active_variation - , V.display_order - , V.id_type , VT.code AS code_variation_type , VT.name AS name_variation_type , VT.name_plural AS name_plural_variation_type + , VT.display_order AS display_order_variation_type , VT.active AS active_variation_type - , VT.display_order , t_P.id_product - , t_P.id_permutation - , t_P.id_category + , t_PP.id_permutation + , t_C.id_category FROM Shop_Variation V INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation @@ -8059,7 +8196,7 @@ BEGIN t_P.id_category, id_variation FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P + INNER JOIN tmp_Product t_P ON t_P.id_permutation = PPVL.id_permutation ORDER BY t_P.display_order ; @@ -8069,24 +8206,24 @@ BEGIN /* select * from tmp_Currency; select * from tmp_delivery_region; - select * from tmp_shop_product; + select * from tmp_product; */ # Images SELECT t_I.id_image, - t_P.id_product, + t_PP.id_product, t_I.id_permutation, - t_P.id_category, + t_C.id_category, I.url, I.active, I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Product_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_permutation = t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order + FROM tmp_Image t_I + INNER JOIN Shop_Product_Image I ON t_I.id_image = I.id_image + INNER JOIN tmp_Permutation t_PP ON t_I.id_permutation = t_PP.id_permutation + INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product + INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category + ORDER BY t_C.display_order, t_P.display_order, I.display_order ; # Errors @@ -8121,22 +8258,23 @@ BEGIN */ # select 'other outputs'; - # select * from tmp_Shop_Product; + # select * from tmp_Product; -- Clean up DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; + DROP TEMPORARY TABLE IF EXISTS tmp_Image; DROP TEMPORARY TABLE IF EXISTS tmp_Category; DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Copy; + DROP TEMPORARY TABLE IF EXISTS tmp_Product; + DROP TEMPORARY TABLE IF EXISTS tmp_Product_2; + DROP TEMPORARY TABLE IF EXISTS tmp_Product_Copy; END // DELIMITER ;; +/* CALL partsltd_prod.p_shop_get_many_product ( 1 #'auth0|6582b95c895d09a70ba10fef', # a_id_user @@ -8154,10 +8292,10 @@ CALL partsltd_prod.p_shop_get_many_product ( , '' # a_ids_image , 1 # a_get_products_quantity_stock_below_minimum ); -/* select * FROM Shop_User_Eval_Temp; +select * from Shop_Product_Category; select * from Shop_Product_Permutation; select * from shop_product_change_set; insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing'); @@ -8494,544 +8632,483 @@ CALL p_shop_user_eval ( */ - - -- Clear previous proc DROP PROCEDURE IF EXISTS p_shop_save_permutation; - -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; +DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; DELIMITER // -CREATE PROCEDURE p_shop_save_permutation ( +CREATE PROCEDURE p_shop_save_product_permutation ( IN a_guid VARCHAR(500), IN a_id_user INT, - IN a_id_order INT, - -- IN a_id_supplier_ordered INT, - IN a_id_currency_cost INT, - IN a_active BIT, IN a_comment VARCHAR(500) ) BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_id_error_type_no_permission INT; - DECLARE v_code_error_type_no_permission VARCHAR(50); - DECLARE v_guid_permission BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_manufacturing_purchase_order INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_ids_product VARCHAR(4000); - DECLARE v_ids_product_no_permission VARCHAR(4000); - -- DECLARE v_id_order_new INT; + + DECLARE v_code_type_error_bad_data VARCHAR(100); + DECLARE v_id_type_error_bad_data INT; + DECLARE v_id_permission_product INT; + DECLARE v_ids_product_permission LONGTEXT; DECLARE v_id_change_set INT; - DECLARE v_is_new_manufacturing_purchase_order BIT; + DECLARE v_id_access_level_edit INT; + DECLARE v_now TIMESTAMP; - SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_code_error_type_no_permission = 'NO_PERMISSION'; - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - SET v_guid_permission = UUID(); - -- SET v_id_user = CURRENT_USER(); - SET v_id_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_MANUFACTURING_PURCHASE_ORDER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - IF a_active IS NULL THEN - SET a_active = 0; - END IF; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL, - value_produced_total_local FLOAT NOT NULL, - quantity_used FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced FLOAT NULL, - latency_manufacture_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - # User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_user) OR NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = a_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', IFNULL(a_id_user, 'NULL'))) - ; - END IF; - END IF; - - # Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_order) OR ((a_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Manufacturing_Purchase_Order WHERE id_order = a_id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Manufacturing Purchase Order ID: ', IFNULL(a_id_order, 'NULL'))) - ; - END IF; - END IF; - - /* - # Supplier ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = a_id_supplier_ordered) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid supplier ID: ', IFNULL(a_id_supplier_ordered, 'NULL'))) - ; - END IF; - END IF; - */ - - # Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency_cost) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', IFNULL(a_id_currency, 'NULL'))) - ; - END IF; - END IF; - - # Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_comment) OR TRIM(a_comment) = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_manufacturing_purchase_order := CASE WHEN a_id_order <= 0 THEN 1 ELSE 0 END; - - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - value_produced_total_local, - latency_manufacture_days, - display_order, - active, - name_error + DECLARE exit handler for SQLEXCEPTION + BEGIN + -- Get diagnostic information + GET DIAGNOSTICS CONDITION 1 + @sqlstate = RETURNED_SQLSTATE + , @errno = MYSQL_ERRNO + , @text = MESSAGE_TEXT + ; + + -- Rollback the transaction + ROLLBACK; + + -- Select the error information + -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , guid BINARY(36) NOT NULL + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , code + , msg ) - /* - VALUES - (a_id_supplier, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - */ - SELECT - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - PP.cost_local * MPOPL_T.quantity_used AS cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - (PP.cost_local + PP.profit_local_min) * MPOPL_T.quantity_produced AS value_produced_total_local, - MPOPL_T.latency_manufacture_days, - MPOPL_T.display_order, - MPOPL_T.active, - CONCAT(PP.id_permutation, ' - ', IFNULL(P.name ,'')) AS name_error - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - INNER JOIN Shop_Product_Permutation PP ON MPOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE MPOPL_T.GUID = a_guid - -- GROUP BY MPOPL_T.id_order, name_error, MPOPL_T.id_link - /* - group by - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - value_produced_total_local, - MPOPL_T.latency_manufacture_days, - MPOPL_T.display_order, - MPOPL_T.active, - name_error - */ - -- GROUP BY id_link, P.id_product, PP.id_permutation - -- GROUP BY name_error, ID_LINK, cost_total_local, value_produced_total_local - ; - DELETE MPOPL_T - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = a_guid - ; + SELECT + a_guid + , NULL + , @errno + , @text + ; + SELECT * + FROM tmp_Msg_Error; + DROP TABLE IF EXISTS tmp_Msg_Error; + END; + + SET v_code_type_error_bad_data := 'BAD_DATA'; + SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); + SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); + + SET a_guid := IFNULL(a_guid, UUID()); + + DROP TABLE IF EXISTS tmp_Permutation; + + CREATE TEMPORARY TABLE tmp_Permutation ( + id_permutation INT NOT NULL + , id_product INT NOT NULL + , description VARCHAR(4000) NOT NULL + , cost_local FLOAT NOT NULL + , id_currency_cost INT NOT NULL + , profit_local_min FLOAT NOT NULL + , latency_manufacture_days INT NOT NULL + , id_unit_measurement_quantity INT NOT NULL + , count_unit_measurement_per_quantity_step FLOAT NOT NULL + , quantity_min FLOAT NOT NULL + , quantity_max FLOAT NOT NULL + , quantity_stock FLOAT NOT NULL + , is_subscription BIT NOT NULL + , id_unit_measurement_interval_recurrence INT + , count_interval_recurrence INT + , id_stripe_product VARCHAR(100) NULL + , does_expire_faster_once_unsealed BIT NOT NULL + , id_unit_measurement_interval_expiration_unsealed INT + , count_interval_expiration_unsealed INT + , active BIT NOT NULL DEFAULT 1 + , can_view BIT NULL + , can_edit BIT NULL + , can_admin BIT NULL + , name_error VARCHAR(255) NOT NULL + , is_new BIT NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , guid BINARY(36) NOT NULL + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + + -- Get data from Temp table + INSERT INTO tmp_Permutation ( + id_permutation + , id_product + , description + , cost_local + , id_currency_cost + , profit_local_min + , latency_manufacture_days + , id_unit_measurement_quantity + , count_unit_measurement_per_quantity_step + , quantity_min + , quantity_max + , quantity_stock + , is_subscription + , id_unit_measurement_interval_recurrence + , count_interval_recurrence + , id_stripe_product + , does_expire_faster_once_unsealed + , id_unit_measurement_interval_expiration_unsealed + , count_interval_expiration_unsealed + , active + , name_error + , is_new + ) + SELECT + PP_T.id_permutation + , IFNULL(PP_T.id_product, PP.id_product) AS id_product + , IFNULL(PP_T.description, PP.description) AS description + , IFNULL(PP_T.cost_local, PP.cost_local) AS cost_local + , IFNULL(PP_T.id_currency_cost, PP.id_currency_cost) AS a_id_currency_cost + , IFNULL(PP_T.profit_local_min, PP.profit_local_min) AS profit_local_min + , IFNULL(PP_T.latency_manufacture_days, PP.latency_manufacture_days) AS latency_manufacture_days + , IFNULL(PP_T.id_unit_measurement_quantity, PP.id_unit_measurement_quantity) AS id_unit_measurement_quantity + , IFNULL(PP_T.count_unit_measurement_per_quantity_step, PP.count_unit_measurement_per_quantity_step) AS count_unit_measurement_per_quantity_step + , IFNULL(PP_T.quantity_min, PP.quantity_min) AS quantity_min + , IFNULL(PP_T.quantity_max, PP.quantity_max) AS quantity_max + , IFNULL(PP_T.quantity_stock, PP.quantity_stock) AS quantity_stock + , IFNULL(PP_T.is_subscription, PP.is_subscription) AS is_subscription + , IFNULL(PP_T.id_unit_measurement_interval_recurrence, PP.id_unit_measurement_interval_recurrence) AS id_unit_measurement_interval_recurrence + , IFNULL(PP_T.count_interval_recurrence, PP.count_interval_recurrence) AS count_interval_recurrence + , IFNULL(PP_T.id_stripe_product, PP.id_stripe_product) AS id_stripe_product + , IFNULL(PP_T.does_expire_faster_once_unsealed, PP.does_expire_faster_once_unsealed) AS does_expire_faster_once_unsealed + , IFNULL(PP_T.id_unit_measurement_interval_expiration_unsealed, PP.id_unit_measurement_interval_expiration_unsealed) AS id_unit_measurement_interval_expiration_unsealed + , IFNULL(PP_T.count_interval_expiration_unsealed, PP.count_interval_expiration_unsealed) AS count_interval_expiration_unsealed + , IFNULL(PP_T.active, PP.active) AS active + , fn_shop_get_name_product_permutation(PP_T.id_permutation) + , CASE WHEN IFNULL(PP_T.id_category, 0) < 1 THEN 1 ELSE 0 END AS is_new + FROM Shop_Product_Permutation_Temp PP_T + LEFT JOIN Shop_Product_Permutation PP ON PP_T.id_category = PP.id_category + WHERE PP_T.guid = a_guid + ; + + -- Validation + -- Missing mandatory fields + -- id_product + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_product) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , id_product + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a product: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.id_product) + ; END IF; - - -- Invalid quantity used - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_used) - AND quantity_used < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity used property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ; - END IF; + -- cost_local + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.cost_local) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , cost_local + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a local cost: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.cost_local) + ; END IF; - - -- Invalid quantity produced - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_produced) - AND quantity_produced < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity produced property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ; - END IF; + -- profit_local_min + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.profit_local_min) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , profit_local_min + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a local minimum profit: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.profit_local_min) + ; + END IF; + -- latency_manufacture_days + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.latency_manufacture_days) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , latency_manufacture_days + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a manufacturing latency: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.latency_manufacture_days) + ; + END IF; + -- id_unit_measurement_quantity + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_unit_measurement_quantity) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , id_unit_measurement_quantity + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a unit measurement for stock quantities: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.id_unit_measurement_quantity) + ; + END IF; + -- count_unit_measurement_per_quantity_step + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , count_unit_measurement_per_quantity_step + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a count unit measurement per quantity step: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) + ; + END IF; + -- quantity_min + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_min) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , quantity_min + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a minimum quantity: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.quantity_min) + ; + END IF; + -- quantity_max + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_max) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , quantity_max + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a maximum quantity: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.quantity_max) + ; + END IF; + -- is_subscription + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.is_subscription) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , is_subscription + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have an is subscription?: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.is_subscription) + ; + END IF; + -- does_expire_faster_once_unsealed + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.does_expire_faster_once_unsealed) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , does_expire_faster_once_unsealed + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a does expire faster once unsealed: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.does_expire_faster_once_unsealed) + ; END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_MPOPLC.name_error SEPARATOR ', ')) - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ; - END IF; - END IF; - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_ids_product := ( - SELECT GROUP_CONCAT(G.id_product SEPARATOR ',') - FROM ( - SELECT DISTINCT PP.id_product - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPO - INNER JOIN Shop_Product_Permutation PP ON t_MPO.id_permutation = PP.id_permutation - ) G + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN -- (SELECT * FROM tmp_Product WHERE is_new = 0 LIMIT 1) THEN + SET v_ids_product_permission := ( + SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') + FROM Shop_Product P + INNER JOIN tmp_Permutation t_P + ON P.id_product = t_P.id_product + -- AND t_P.is_new = 0 ); - - CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_User_Eval_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_User_Eval_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_manufacturing_purchase_order - ; - END IF; - */ - SET v_ids_product_no_permission := ( - SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',') - FROM Shop_User_Eval_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - a_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - CONCAT('You do not have permission to edit the following product IDs: ', v_ids_product_no_permission) - ) - ; - END IF; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_manufacturing_purchase_order = 1 THEN 'new ' ELSE '' END, - 'Manufacturing Purchase Order - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); + IF NOT ISNULL(v_ids_product_permission) THEN + SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); + CALL p_shop_user_eval(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission); - IF (v_is_new_manufacturing_purchase_order = 1) THEN - INSERT INTO Shop_Manufacturing_Purchase_Order ( - -- id_supplier_ordered, - cost_total_local, - id_currency_cost, - value_produced_total_local, - created_by, - id_change_set, - active + UPDATE tmp_Permutation t_P + INNER JOIN Shop_Product P ON t_P.id_product = P.id_product + INNER JOIN Shop_User_Eval_Temp UE_T + ON P.id_product = UE_T.id_product + AND UE_T.GUID = a_guid + SET + t_P.can_view = UE_T.can_view + , t_P.can_edit = UE_T.can_edit + , t_P.can_admin = UE_T.can_admin + ; + + CALL p_clear_shop_user_eval_temp(a_guid); + + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.can_edit) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , code + , msg ) - SELECT - -- a_id_supplier_ordered, - SUM(t_MPOPL.cost_total_local), - a_id_currency_cost, - SUM(t_MPOPL.value_produced_total_local), - a_id_user, - v_id_change_set, - a_active - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have product edit permission: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.can_edit) ; - -- SET v_id_order_new - SET a_id_order := (SELECT id_order FROM Shop_Manufacturing_Purchase_Order ORDER BY id_order DESC LIMIT 1); - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - a_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - ELSE - UPDATE Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPO.id_order = t_MPOPL.id_order - SET - -- MPO.id_supplier_ordered = a_id_supplier_ordered, - MPO.cost_total_local = SUM(t_MPOPL.cost_total_local), - MPO.value_produced_total_local = SUM(t_MPOPL.value_produced_total_local), - MPO.id_currency = a_id_currency_cost, - MPO.id_change_set = v_id_change_set, - MPO.active = a_active - WHERE MPO.id_order = a_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL INNER JOIN Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link) THEN - UPDATE Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - SET - MPOPL.id_order = t_MPOPL.id_order, - MPOPL.id_permutation = t_MPOPL.id_permutation, - MPOPL.cost_total_local = t_MPOPL.cost_total_local, - MPOPL.value_produced_total_local = t_MPOPL.value_produced_total_local, - MPOPL.id_currency_cost = t_MPOPL.id_currency_cost, - MPOPL.quantity_used = t_MPOPL.quantity_used, - MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity, - MPOPL.quantity_produced = t_MPOPL.quantity_produced, - MPOPL.latency_manufacture_days = t_MPOPL.latency_manufacture_days, - MPOPL.display_order = t_MPOPL.display_order, - MPOPL.active = t_MPOPL.active, - MPOPL.id_change_set = v_id_change_set - ; - ELSE - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.id_link < 0 - ; - END IF; END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; END IF; END IF; - -- Returns - # SET v_now = NOW(); + SET v_now := CURRENT_TIMESTAMP(); - # Manufacturing Purchase Orders - SELECT * - FROM Shop_Manufacturing_Purchase_Order - WHERE - id_order = a_id_order - -- GUID = a_guid - ; + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + START TRANSACTION; + + IF NOT ISNULL(v_ids_product_permission) THEN + INSERT INTO Shop_Product_Change_Set ( comment ) + VALUES ( a_comment ) + ; + + SET v_id_change_set := LAST_INSERT_ID(); + + UPDATE Shop_Product_Permutation PP + INNER JOIN tmp_Permutation t_P ON PP.id_permutation = t_P.id_permutation + SET + PP.id_permutation = t_P.id_permutation + , PP.id_product = t_P.id_product + , PP.description = t_P.description + , PP.cost_local = t_P.cost_local + , PP.id_currency_cost = t_P.id_currency_cost + , PP.profit_local_min = t_P.profit_local_min + , PP.latency_manufacture_days = t_P.latency_manufacture_days + , PP.id_unit_measurement_quantity = t_P.id_unit_measurement_quantity + , PP.count_unit_measurement_per_quantity_step = t_P.count_unit_measurement_per_quantity_step + , PP.quantity_min = t_P.quantity_min + , PP.quantity_max = t_P.quantity_max + , PP.quantity_stock = t_P.quantity_stock + , PP.is_subscription = t_P.is_subscription + , PP.id_unit_measurement_interval_recurrence = t_P.id_unit_measurement_interval_recurrence + , PP.count_interval_recurrence = t_P.count_interval_recurrence + , PP.id_stripe_product = t_P.id_stripe_product + , PP.does_expire_faster_once_unsealed = t_P.does_expire_faster_once_unsealed + , PP.id_unit_measurement_interval_expiration_unsealed = t_P.id_unit_measurement_interval_expiration_unsealed + , PP.count_interval_expiration_unsealed = t_P.count_interval_expiration_unsealed + , PP.active = t_P.active + , PP.id_change_set = v_id_change_set + ; + END IF; + + INSERT INTO Shop_Product_Permutation ( + id_product + , description + , cost_local + , id_currency_cost + , profit_local_min + , latency_manufacture_days + , id_unit_measurement_quantity + , count_unit_measurement_per_quantity_step + , quantity_min + , quantity_max + , quantity_stock + , is_subscription + , id_unit_measurement_interval_recurrence + , count_interval_recurrence + , id_stripe_product + , does_expire_faster_once_unsealed + , id_unit_measurement_interval_expiration_unsealed + , count_interval_expiration_unsealed + , active + , display_order + , created_by + , created_on + ) + SELECT + t_P.id_product AS id_product + , t_P.description AS description + , t_P.cost_local AS cost_local + , t_P.id_currency_cost AS id_currency_cost + , t_P.profit_local_min AS profit_local_min + , t_P.latency_manufacture_days AS latency_manufacture_days + , t_P.id_unit_measurement_quantity AS id_unit_measurement_quantity + , t_P.count_unit_measurement_per_quantity_step AS count_unit_measurement_per_quantity_step + , t_P.quantity_min AS quantity_min + , t_P.quantity_max AS quantity_max + , t_P.quantity_stock AS quantity_stock + , t_P.is_subscription AS is_subscription + , t_P.id_unit_measurement_interval_recurrence AS id_unit_measurement_interval_recurrence + , t_P.count_interval_recurrence AS count_interval_recurrence + , t_P.id_stripe_product AS id_stripe_product + , t_P.does_expire_faster_once_unsealed AS does_expire_faster_once_unsealed + , t_P.id_unit_measurement_interval_expiration_unsealed AS id_unit_measurement_interval_expiration_unsealed + , t_P.count_interval_expiration_unsealed AS count_interval_expiration_unsealed + , t_P.active AS active + , a_id_user AS created_by + , v_now AS created_on + FROM tmp_Permutation t_P + WHERE + is_new = 1 + AND active = 1 + ; + + COMMIT; + END IF; - # Manufacturing Purchase Order Product Links - SELECT * - FROM Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - id_order = a_id_order - -- GUID = a_guid - ; + DELETE FROM Shop_Product_Category_Temp + WHERE GUID = a_guid; - # Errors - SELECT * - FROM tmp_Msg_Error - ; + SELECT * FROM tmp_Msg_Error; - # DROP TABLE tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE tmp_Msg_Error; + DROP TEMPORARY TABLE IF EXISTS tmp_Catgory; + DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; END // DELIMITER ;; @@ -9098,25 +9175,8 @@ DELETE FROM Shop_Manufacturing_Purchase_Order; */ - - -/* - -CALL p_shop_get_many_product_variation ( - '', # a_id_user - 1, # a_get_all_supplier - 0, # a_get_inactive_variation - 0, # a_get_first_variation_only - '', # a_ids_variation -); - -*/ - - --- Clear previous proc DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; - DELIMITER // CREATE PROCEDURE p_shop_get_many_product_variation ( IN a_id_user INT, @@ -9335,32 +9395,33 @@ BEGIN END IF; -- Returns - /* # Variation Types SELECT t_VT.id_type , VT.code , VT.name , VT.name_plural + , VT.display_order , VT.active FROM tmp_Variation_Type t_VT INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type ; - */ # Variations SELECT t_V.id_variation + , t_V.id_type , V.code AS code_variation , V.name AS name_variation - , V.active AS active_variation , V.display_order - , t_V.id_type + , V.active AS active_variation + /* , VT.code AS code_variation_type , VT.name AS name_variation_type , VT.name_plural AS name_plural_variation_type , VT.active AS active_variation_type , VT.display_order + */ FROM tmp_Variation t_V INNER JOIN Shop_Variation V ON t_V.id_variation = V.id_variation INNER JOIN tmp_Variation_Type t_VT ON V.id_type = t_VT.id_type @@ -9613,17 +9674,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, * - , latency_manufacture INT NOT NULL + , latency_manufacture_days INT NOT NULL , quantity_min FLOAT NOT NULL , quantity_max FLOAT NOT NULL , quantity_step FLOAT NOT NULL , quantity_stock FLOAT NOT NULL , is_subscription BIT NOT NULL - , id_recurrence_interval INT - , CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) - , count_recurrence_interval INT + , id_unit_measurement_interval_recurrence INT + , CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval) + , count_interval_recurrence INT , id_stripe_product VARCHAR(100) , product_has_variations INT NOT NULL , can_view BIT @@ -10797,15 +10858,15 @@ BEGIN CURRENCY.code AS code_currency_cost, CURRENCY.symbol AS symbol_currency_cost, PP.profit_local_min, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - UM.name_singular AS name_recurrence_interval, - UM.name_plural AS name_plural_recurrence_interval, + UM.name_singular AS name_interval_recurrence, + UM.name_plural AS name_plural_interval_recurrence, PP.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, @@ -10816,8 +10877,8 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_interval_recurrence = UM.id_unit_measurement + -- LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval + LEFT JOIN Shop_Unit_Measurement UM ON PP.id_unit_measurement_interval_recurrence = UM.id_unit_measurement INNER JOIN Shop_Currency CURRENCY ON PP.id_currency_cost = CURRENCY.id_currency ORDER BY t_P.rank_permutation ; @@ -11339,13 +11400,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency @@ -13967,17 +14028,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, */ - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, can_view BIT, @@ -14159,14 +14220,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -14191,14 +14252,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -15309,17 +15370,17 @@ BEGIN price_GBP_min FLOAT NOT NULL, */ /* - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, */ @@ -15449,14 +15510,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -15481,14 +15542,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -17130,17 +17191,17 @@ BEGIN price_GBP_min FLOAT NOT NULL, */ /* - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, */ @@ -17325,14 +17386,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -17357,14 +17418,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -17843,13 +17904,13 @@ VALUES # Unit of Measurement INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit + name_singular, name_plural, symbol, is_base_unit, is_unit_of_distance, is_unit_of_mass, is_unit_of_time, is_unit_of_volume ) VALUES - ('metre', 'metres', 'm', 1), - ('kilogram', 'kilograms', 'kg', 1), - ('item', 'items', 'x', 0), - ('hour', 'hours', 'h', 1) + ('metre', 'metres', 'm', 1, 1, 0, 0, 0), + ('kilogram', 'kilograms', 'kg', 1, 0, 1, 0, 0), + ('item', 'items', 'x', 0, 0, 0, 0, 0), + ('hour', 'hours', 'h', 1, 0, 0, 1, 0) ; /* @@ -17880,7 +17941,7 @@ VALUES /* # Recurrence Interval -INSERT INTO Shop_Recurrence_Interval ( +INSERT INTO Shop_Interval_Recurrence ( code, name, name_plural ) VALUES @@ -17951,18 +18012,19 @@ INSERT INTO Shop_Product_Permutation ( id_currency_cost, profit_local_min, # id_currency_profit_min, - latency_manufacture, - quantity_min, + latency_manufacture_days, + id_unit_measurement_quantity, + count_unit_measurement_per_quantity_step, + quantity_min, quantity_max, - quantity_step, quantity_stock, is_subscription, - id_interval_recurrence, + id_unit_measurement_interval_recurrence, count_interval_recurrence, -- id_access_level_required, id_stripe_product , does_expire_faster_once_unsealed - , id_interval_expiration_unsealed + , id_unit_measurement_interval_expiration_unsealed , count_interval_expiration_unsealed ) VALUES @@ -17976,9 +18038,10 @@ VALUES # 1, 14, 1, - 3, 1, + 3, 99, + 1, 0, NULL, NULL, @@ -17998,9 +18061,10 @@ VALUES # 1, 14, 1, - 3, 1, + 3, 99, + 1, 0, NULL, NULL, @@ -18020,9 +18084,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -18042,9 +18107,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -18064,9 +18130,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -18086,9 +18153,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -18537,8 +18605,8 @@ SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; /* # Recurrence Interval -SELECT * FROM Shop_Recurrence_Interval; -SELECT * FROM Shop_Recurrence_Interval_Audit; +SELECT * FROM Shop_Interval_Recurrence; +SELECT * FROM Shop_Interval_Recurrence_Audit; */ diff --git a/static/MySQL/0001_destroy.sql b/static/MySQL/0001_destroy.sql index 31a3994d..5b3f89e4 100644 --- a/static/MySQL/0001_destroy.sql +++ b/static/MySQL/0001_destroy.sql @@ -146,8 +146,8 @@ DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; DROP TABLE IF EXISTS Shop_Product_Permutation; -DROP TABLE IF EXISTS Shop_Recurrence_Interval_Audit; -DROP TABLE IF EXISTS Shop_Recurrence_Interval; +DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; +DROP TABLE IF EXISTS Shop_Interval_Recurrence; DROP TABLE IF EXISTS Shop_Product_Audit; DROP TABLE IF EXISTS Shop_Product; @@ -221,9 +221,14 @@ DROP TABLE IF EXISTS Shop_Product_Change_Set; DROP PROCEDURE IF EXISTS p_split; DROP PROCEDURE IF EXISTS p_clear_split_temp; +DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; + DROP PROCEDURE IF EXISTS p_shop_user_eval; DROP PROCEDURE IF EXISTS p_clear_shop_user_eval_temp; +DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; +DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; + DROP PROCEDURE IF EXISTS p_shop_get_many_region; DROP PROCEDURE IF EXISTS p_shop_get_many_currency; @@ -234,6 +239,7 @@ DROP PROCEDURE IF EXISTS p_shop_save_product; DROP PROCEDURE IF EXISTS p_shop_get_many_product; DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; DROP PROCEDURE IF EXISTS p_shop_save_permutation; +DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item; DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; diff --git a/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql b/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql index c8b62ba5..44c3eb0c 100644 --- a/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql +++ b/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql @@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( name_singular VARCHAR(255) NOT NULL, name_plural VARCHAR(256) NOT NULL, symbol VARCHAR(50) NOT NULL, + symbol_is_suffix_not_prefix BIT NOT NULL DEFAULT 1, is_base_unit BIT NOT NULL DEFAULT 0, is_unit_of_distance BIT NOT NULL DEFAULT 0, is_unit_of_mass BIT NOT NULL DEFAULT 0, diff --git a/static/MySQL/1203_tbl_Shop_Product.sql b/static/MySQL/1203_tbl_Shop_Product.sql index fce7bd2e..f0dc160a 100644 --- a/static/MySQL/1203_tbl_Shop_Product.sql +++ b/static/MySQL/1203_tbl_Shop_Product.sql @@ -25,11 +25,11 @@ CREATE TABLE IF NOT EXISTS Shop_Product ( quantity_step FLOAT, quantity_stock FLOAT, is_subscription BIT, - id_recurrence_interval INT, - CONSTRAINT FK_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, */ id_access_level_required INT NOT NULL, CONSTRAINT FK_Shop_Product_id_access_level_required diff --git a/static/MySQL/1206_tbl_Shop_Product_Permutation.sql b/static/MySQL/1206_tbl_Shop_Product_Permutation.sql index 3473bbba..49302982 100644 --- a/static/MySQL/1206_tbl_Shop_Product_Permutation.sql +++ b/static/MySQL/1206_tbl_Shop_Product_Permutation.sql @@ -18,26 +18,30 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( id_currency_cost INT NOT NULL, profit_local_min FLOAT NOT NULL, -- id_currency_profit_min INT NOT NULL, - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, + id_unit_measurement_quantity INT NOT NULL, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_quantity + FOREIGN KEY (id_unit_measurement_quantity) + REFERENCES Shop_Unit_Measurement(id_unit_measurement), + count_unit_measurement_per_quantity_step FLOAT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_id_interval_recurrence - FOREIGN KEY (id_interval_recurrence) + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) REFERENCES Shop_Unit_Measurement(id_unit_measurement), /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_recurrence - CHECK (id_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), + CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence + CHECK (id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), */ count_interval_recurrence INT, id_stripe_product VARCHAR(100) NULL, does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_id_interval_expiration_unsealed - FOREIGN KEY (id_interval_expiration_unsealed) + id_unit_measurement_interval_expiration_unsealed INT, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_expiration_unsealed + FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) REFERENCES Shop_Unit_Measurement(id_unit_measurement), /* CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_expiration_unsealed diff --git a/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql b/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql index ed763447..41f4a958 100644 --- a/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql +++ b/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql @@ -16,27 +16,29 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Temp ( cost_local FLOAT NOT NULL, id_currency_cost INT NOT NULL, profit_local_min FLOAT NOT NULL, - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, + id_unit_measurement_quantity INT NOT NULL, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_quantity + FOREIGN KEY (id_unit_measurement_quantity) + REFERENCES Shop_Unit_Measurement(id_unit_measurement), + count_unit_measurement_per_quantity_step FLOAT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, + quantity_stock FLOAT NULL, is_subscription BIT NOT NULL, - id_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_Temp_id_interval_recurrence - FOREIGN KEY (id_interval_recurrence) + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) REFERENCES Shop_Unit_Measurement(id_unit_measurement), count_interval_recurrence INT, id_stripe_product VARCHAR(100) NULL, does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_Temp_id_interval_expiration_unsealed - FOREIGN KEY (id_interval_expiration_unsealed) + id_unit_measurement_interval_expiration_unsealed INT, + CONSTRAINT FK_Shop_Product_Permutation_Temp_id_unit_expiration + FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) REFERENCES Shop_Unit_Measurement(id_unit_measurement), count_interval_expiration_unsealed INT, active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on TIMESTAMP, - created_by INT, + -- display_order INT NOT NULL, guid BINARY(36) ); diff --git a/static/MySQL/3203_tri_Shop_Product.sql b/static/MySQL/3203_tri_Shop_Product.sql index f94f065d..d302762d 100644 --- a/static/MySQL/3203_tri_Shop_Product.sql +++ b/static/MySQL/3203_tri_Shop_Product.sql @@ -62,11 +62,11 @@ BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -136,13 +136,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set diff --git a/static/MySQL/3206_tri_Shop_Product_Permutation.sql b/static/MySQL/3206_tri_Shop_Product_Permutation.sql index 4f1075a3..4ef35e7f 100644 --- a/static/MySQL/3206_tri_Shop_Product_Permutation.sql +++ b/static/MySQL/3206_tri_Shop_Product_Permutation.sql @@ -29,16 +29,16 @@ BEGIN END IF; IF (NOT ( - NEW.id_interval_recurrence IS NULL - OR NEW.id_interval_recurrence NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) + NEW.id_unit_measurement_interval_recurrence IS NULL + OR NEW.id_unit_measurement_interval_recurrence NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Recurrence interval ID must be a unit of time.'; END IF; IF (NOT ( - NEW.id_interval_expiration_unsealed IS NULL - OR NEW.id_interval_expiration_unsealed NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) + NEW.id_unit_measurement_interval_expiration_unsealed IS NULL + OR NEW.id_unit_measurement_interval_expiration_unsealed NOT IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) )) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Unsealed expiration interval ID must be a unit of time.'; @@ -77,11 +77,11 @@ BEGIN SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) UNION + /* # Changed profit_local_min SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) UNION - /* # Changed id_currency_profit_min SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) @@ -93,36 +93,40 @@ BEGIN WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - # Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + # Changed latency_manufacture_days + SELECT NEW.id_permutation, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days + UNION + # Changed id_unit_measurement_quantity + SELECT NEW.id_permutation, 'id_unit_measurement_quantity', CONVERT(OLD.id_unit_measurement_quantity, CHAR), CONVERT(NEW.id_unit_measurement_quantity, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_quantity <=> NEW.id_unit_measurement_quantity + UNION + # Changed count_unit_measurement_per_quantity_step + SELECT NEW.id_permutation, 'count_unit_measurement_per_quantity_step', CONVERT(OLD.count_unit_measurement_per_quantity_step, CHAR), CONVERT(NEW.count_unit_measurement_per_quantity_step, CHAR), NEW.id_change_set + WHERE NOT OLD.count_unit_measurement_per_quantity_step <=> NEW.count_unit_measurement_per_quantity_step UNION # Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_min <=> NEW.quantity_min UNION # Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_max <=> NEW.quantity_max UNION - # Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION # Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock UNION # Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_interval_recurrence - SELECT NEW.id_product, 'id_interval_recurrence', CONVERT(OLD.id_interval_recurrence, CHAR), CONVERT(NEW.id_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_interval_recurrence <=> NEW.id_interval_recurrence + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_permutation, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION # Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product @@ -130,24 +134,26 @@ BEGIN WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) UNION # Changed does_expire_faster_once_unsealed - SELECT NEW.id_product, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set WHERE NOT OLD.does_expire_faster_once_unsealed <=> NEW.does_expire_faster_once_unsealed UNION - # Changed id_interval_expiration_unsealed - SELECT NEW.id_product, 'id_interval_expiration_unsealed', CONVERT(OLD.id_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_interval_expiration_unsealed, CHAR), NEW.id_change_set - WHERE NOT OLD.id_interval_expiration_unsealed <=> NEW.id_interval_expiration_unsealed + # Changed id_unit_measurement_interval_expiration_unsealed + SELECT NEW.id_permutation, 'id_unit_measurement_interval_expiration_unsealed', CONVERT(OLD.id_unit_measurement_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_unit_measurement_interval_expiration_unsealed, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_expiration_unsealed <=> NEW.id_unit_measurement_interval_expiration_unsealed UNION # Changed count_interval_expiration_unsealed - SELECT NEW.id_product, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set + SELECT NEW.id_permutation, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set WHERE NOT OLD.count_interval_expiration_unsealed <=> NEW.count_interval_expiration_unsealed UNION # Changed active SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set WHERE NOT (OLD.active <=> NEW.active) - UNION + /* + UNION # Changed display_order SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set WHERE NOT (OLD.display_order <=> NEW.display_order) + */ ; END // DELIMITER ;; diff --git a/static/MySQL/6206_fn_shop_get_product_permutation_name.sql b/static/MySQL/6206_fn_shop_get_product_permutation_name.sql new file mode 100644 index 00000000..a5b8545a --- /dev/null +++ b/static/MySQL/6206_fn_shop_get_product_permutation_name.sql @@ -0,0 +1,33 @@ + +DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; + +DELIMITER // + +CREATE FUNCTION fn_shop_get_product_permutation_name(id_product_permutation INT) +RETURNS VARCHAR(4000) +DETERMINISTIC +BEGIN + DECLARE name VARCHAR(4000); + + SET name := ( + SELECT + CONCAT( + P.name + , CASE WHEN P.has_variations = 1 THEN + CONCAT(' - ', GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ')) + ELSE '' END + ) + FROM Shop_Product_Permutation PP + INNER JOIN Shop_Product P ON PP.id_product = P.id_product + INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation + INNER JOIN Shop_Variation V ON PPVL.id_variation = V.id_variation + INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type + WHERE PP.id_permutation = id_product_permutation + GROUP BY P.id_product, P.name, P.has_variations, VT.display_order, VT.name, V.display_order, V.name + LIMIT 1 + ); + + RETURN name; +END // + +DELIMITER ; diff --git a/static/MySQL/7003_p_shop_get_many_access_level.sql b/static/MySQL/7003_p_shop_get_many_access_level.sql index 9cd0b285..8959e2e7 100644 --- a/static/MySQL/7003_p_shop_get_many_access_level.sql +++ b/static/MySQL/7003_p_shop_get_many_access_level.sql @@ -16,19 +16,18 @@ DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; DELIMITER // CREATE PROCEDURE p_shop_get_many_access_level ( - IN a_id_user INT, IN a_get_inactive_access_level BIT ) BEGIN SET a_get_inactive_access_level = IFNULL(a_get_inactive_access_level, 0); SELECT - AL.id_access_level, - AL.code, - AL.name, - AL.active, - AL.priority, - AL.display_order + AL.id_access_level + , AL.code + , AL.name + , AL.active + , AL.priority + , AL.display_order FROM Shop_Access_Level AL WHERE a_get_inactive_access_level = 1 diff --git a/static/MySQL/7116_p_shop_get_many_currency.sql b/static/MySQL/7116_p_shop_get_many_currency.sql index 929eba44..29c99957 100644 --- a/static/MySQL/7116_p_shop_get_many_currency.sql +++ b/static/MySQL/7116_p_shop_get_many_currency.sql @@ -27,9 +27,10 @@ BEGIN C.id_currency, C.code, C.name, + C.symbol, C.factor_from_GBP, - C.active, - C.display_order + C.display_order, + C.active FROM Shop_Currency C WHERE a_get_inactive_currency OR C.active diff --git a/static/MySQL/7122_p_shop_get_many_unit_measurement.sql b/static/MySQL/7122_p_shop_get_many_unit_measurement.sql new file mode 100644 index 00000000..4beb7a25 --- /dev/null +++ b/static/MySQL/7122_p_shop_get_many_unit_measurement.sql @@ -0,0 +1,41 @@ + +-- Clear previous proc +DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; + + +DELIMITER // +CREATE PROCEDURE p_shop_get_many_unit_measurement ( + IN a_get_inactive_unit_measurement BIT +) +BEGIN + SET a_get_inactive_unit_measurement := IFNULL(a_get_inactive_unit_measurement, 0); + + SELECT + UM.id_unit_measurement, + UM.name_singular, + UM.name_plural, + UM.symbol, + UM.symbol_is_suffix_not_prefix, + UM.is_base_unit, + UM.is_unit_of_distance, + UM.is_unit_of_mass, + UM.is_unit_of_time, + UM.is_unit_of_volume, + UM.active + FROM Shop_Unit_Measurement UM + WHERE + a_get_inactive_unit_measurement = 1 + OR UM.active = 1 + ; +END // +DELIMITER ;; + + +/* +CALL p_shop_get_many_unit_measurement ( + 0 # a_get_inactive_unit_measurement +); + +select * +from shop_unit_measurement +*/ diff --git a/static/MySQL/7200_p_shop_save_product_category.sql b/static/MySQL/7200_p_shop_save_product_category.sql index 84cecf5b..abc3e0a2 100644 --- a/static/MySQL/7200_p_shop_save_product_category.sql +++ b/static/MySQL/7200_p_shop_save_product_category.sql @@ -1,7 +1,5 @@ - - -- Clear previous proc DROP PROCEDURE IF EXISTS p_save_category; DROP PROCEDURE IF EXISTS p_shop_save_category; diff --git a/static/MySQL/7204_p_shop_get_many_product.sql b/static/MySQL/7204_p_shop_get_many_product.sql index 6b20ac92..1d005268 100644 --- a/static/MySQL/7204_p_shop_get_many_product.sql +++ b/static/MySQL/7204_p_shop_get_many_product.sql @@ -95,11 +95,11 @@ BEGIN ); CREATE TEMPORARY TABLE tmp_Permutation ( - -- id_category INT NOT NULL, - id_product INT NOT NULL, - id_permutation INT NULL, - active BIT NOT NULL, - display_order INT NOT NULL + id_permutation INT NULL + -- id_category INT NOT NULL, + , id_product INT NOT NULL + , active BIT NOT NULL + -- , display_order INT NOT NULL ); CREATE TEMPORARY TABLE tmp_Image ( @@ -178,18 +178,18 @@ BEGIN ; INSERT INTO tmp_Permutation ( + id_permutation -- id_category, - id_product, - id_permutation, - active, - display_order + , id_product + , active + -- , display_order ) SELECT + PP.id_permutation -- P.id_category, - PP.id_product, - PP.id_permutation, - PP.active, - PP.display_order + , PP.id_product + , PP.active + -- , RANK() OVER (ORDER BY VT.display_order, V.display_order) FROM Shop_Product_Permutation PP INNER JOIN tmp_Product t_P ON PP.id_product = t_P.id_product WHERE ( @@ -370,19 +370,35 @@ BEGIN PP.id_currency_cost, C.code AS code_currency_cost, C.symbol AS symbol_currency_cost, - PP.profit_local_min, - PP.latency_manufacture, + -- PP.profit_local_min, + PP.latency_manufacture_days, + PP.id_unit_measurement_quantity, + UM_Q.symbol AS symbol_unit_measurement_quantity, + UM_Q.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_quantity, + UM_Q.name_singular AS name_singular_unit_measurement_quantity, + UM_Q.name_plural AS name_plural_unit_measurement_quantity, + PP.count_unit_measurement_per_quantity_step, PP.quantity_min, PP.quantity_max, - PP.quantity_step, PP.quantity_stock, - PP.id_stripe_product, PP.is_subscription, - UM.name_singular AS name_recurrence_interval, - UM.name_plural AS name_plural_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + UM_R.symbol AS symbol_unit_measurement_interval_recurrence, + UM_R.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence, + UM_R.name_singular AS name_singular_unit_measurement_interval_recurrence, + UM_R.name_plural AS name_plural_unit_measurement_interval_recurrence, PP.count_interval_recurrence, + PP.id_stripe_product, + PP.does_expire_faster_once_unsealed, + PP.id_unit_measurement_interval_expiration_unsealed, + UM_X.symbol AS symbol_unit_measurement_interval_expiration_unsealed, + UM_X.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed, + UM_X.name_singular AS name_singular_unit_measurement_interval_expiration_unsealed, + UM_X.name_plural AS name_plural_unit_measurement_interval_expiration_unsealed, + PP.count_interval_expiration_unsealed, + NOT ISNULL(PPVL.id_permutation) AS has_variations, PP.active, - PP.display_order, + -- PP.display_order, IFNULL(t_P.can_view, 0) AS can_view, IFNULL(t_P.can_edit, 0) AS can_edit, IFNULL(t_P.can_admin, 0) AS can_admin @@ -391,26 +407,28 @@ BEGIN INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product INNER JOIN Shop_Product_Category PC ON P.id_category = PC.id_category - -- LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_interval_recurrence = UM.id_unit_measurement + LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation + LEFT JOIN Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement + LEFT JOIN Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement + LEFT JOIN Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement INNER JOIN Shop_Currency C ON PP.id_currency_cost = C.id_currency GROUP BY PC.id_category, P.id_product, PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin - ORDER BY PC.display_order, P.display_order, PP.display_order + ORDER BY PC.display_order, P.display_order -- , t_PP.display_order ; # Variations SELECT V.id_variation + , V.id_type , V.code AS code_variation , V.name AS name_variation + , V.display_order AS display_order_variation , V.active AS active_variation - , V.display_order - , V.id_type , VT.code AS code_variation_type , VT.name AS name_variation_type , VT.name_plural AS name_plural_variation_type + , VT.display_order AS display_order_variation_type , VT.active AS active_variation_type - , VT.display_order , t_P.id_product , t_PP.id_permutation , t_C.id_category @@ -458,7 +476,7 @@ BEGIN INNER JOIN tmp_Permutation t_PP ON t_I.id_permutation = t_PP.id_permutation INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - ORDER BY t_C.display_order, t_P.display_order, t_PP.display_order, I.display_order + ORDER BY t_C.display_order, t_P.display_order, I.display_order ; # Errors @@ -514,7 +532,7 @@ DELIMITER ;; CALL partsltd_prod.p_shop_get_many_product ( 1 #'auth0|6582b95c895d09a70ba10fef', # a_id_user , 1 # a_get_all_product_category - , 1 # a_get_inactive_product_category + , 0 # a_get_inactive_product_category , '' # a_ids_product_category , 1 # a_get_all_product , 0 # a_get_inactive_product @@ -525,7 +543,7 @@ CALL partsltd_prod.p_shop_get_many_product ( , 1 # a_get_all_image , 0 # a_get_inactive_image , '' # a_ids_image - , 1 # a_get_products_quantity_stock_below_minimum + , 0 # a_get_products_quantity_stock_below_minimum ); select * FROM Shop_User_Eval_Temp; diff --git a/static/MySQL/7206_p_shop_save_permutation.sql b/static/MySQL/7206_p_shop_save_permutation.sql deleted file mode 100644 index b64dab31..00000000 --- a/static/MySQL/7206_p_shop_save_permutation.sql +++ /dev/null @@ -1,605 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_permutation; - -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_permutation ( - IN a_guid VARCHAR(500), - IN a_id_user INT, - IN a_id_order INT, - -- IN a_id_supplier_ordered INT, - IN a_id_currency_cost INT, - IN a_active BIT, - IN a_comment VARCHAR(500) -) -BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_id_error_type_no_permission INT; - DECLARE v_code_error_type_no_permission VARCHAR(50); - DECLARE v_guid_permission BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_manufacturing_purchase_order INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_ids_product VARCHAR(4000); - DECLARE v_ids_product_no_permission VARCHAR(4000); - -- DECLARE v_id_order_new INT; - DECLARE v_id_change_set INT; - DECLARE v_is_new_manufacturing_purchase_order BIT; - - SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_code_error_type_no_permission = 'NO_PERMISSION'; - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - SET v_guid_permission = UUID(); - -- SET v_id_user = CURRENT_USER(); - SET v_id_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_MANUFACTURING_PURCHASE_ORDER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - IF a_active IS NULL THEN - SET a_active = 0; - END IF; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL, - value_produced_total_local FLOAT NOT NULL, - quantity_used FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced FLOAT NULL, - latency_manufacture_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - # User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_user) OR NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = a_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', IFNULL(a_id_user, 'NULL'))) - ; - END IF; - END IF; - - # Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_order) OR ((a_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Manufacturing_Purchase_Order WHERE id_order = a_id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Manufacturing Purchase Order ID: ', IFNULL(a_id_order, 'NULL'))) - ; - END IF; - END IF; - - /* - # Supplier ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = a_id_supplier_ordered) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid supplier ID: ', IFNULL(a_id_supplier_ordered, 'NULL'))) - ; - END IF; - END IF; - */ - - # Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency_cost) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', IFNULL(a_id_currency, 'NULL'))) - ; - END IF; - END IF; - - # Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_comment) OR TRIM(a_comment) = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_manufacturing_purchase_order := CASE WHEN a_id_order <= 0 THEN 1 ELSE 0 END; - - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - value_produced_total_local, - latency_manufacture_days, - display_order, - active, - name_error - ) - /* - VALUES - (a_id_supplier, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - */ - SELECT - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - PP.cost_local * MPOPL_T.quantity_used AS cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - (PP.cost_local + PP.profit_local_min) * MPOPL_T.quantity_produced AS value_produced_total_local, - MPOPL_T.latency_manufacture_days, - MPOPL_T.display_order, - MPOPL_T.active, - CONCAT(PP.id_permutation, ' - ', IFNULL(P.name ,'')) AS name_error - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - INNER JOIN Shop_Product_Permutation PP ON MPOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE MPOPL_T.GUID = a_guid - -- GROUP BY MPOPL_T.id_order, name_error, MPOPL_T.id_link - /* - group by - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - value_produced_total_local, - MPOPL_T.latency_manufacture_days, - MPOPL_T.display_order, - MPOPL_T.active, - name_error - */ - -- GROUP BY id_link, P.id_product, PP.id_permutation - -- GROUP BY name_error, ID_LINK, cost_total_local, value_produced_total_local - ; - DELETE MPOPL_T - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = a_guid - ; - END IF; - - -- Invalid quantity used - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_used) - AND quantity_used < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity used property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ; - END IF; - END IF; - - -- Invalid quantity produced - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_produced) - AND quantity_produced < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity produced property for the following permutations: ', GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ; - END IF; - END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_MPOPLC.name_error SEPARATOR ', ')) - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ; - END IF; - END IF; - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_ids_product := ( - SELECT GROUP_CONCAT(G.id_product SEPARATOR ',') - FROM ( - SELECT DISTINCT PP.id_product - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPO - INNER JOIN Shop_Product_Permutation PP ON t_MPO.id_permutation = PP.id_permutation - ) G - ); - - CALL p_shop_user_eval(v_guid_permission, a_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_User_Eval_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_User_Eval_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_manufacturing_purchase_order - ; - END IF; - */ - SET v_ids_product_no_permission := ( - SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',') - FROM Shop_User_Eval_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - a_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - CONCAT('You do not have permission to edit the following product IDs: ', v_ids_product_no_permission) - ) - ; - END IF; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_manufacturing_purchase_order = 1 THEN 'new ' ELSE '' END, - 'Manufacturing Purchase Order - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); - - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_manufacturing_purchase_order = 1) THEN - INSERT INTO Shop_Manufacturing_Purchase_Order ( - -- id_supplier_ordered, - cost_total_local, - id_currency_cost, - value_produced_total_local, - created_by, - id_change_set, - active - ) - SELECT - -- a_id_supplier_ordered, - SUM(t_MPOPL.cost_total_local), - a_id_currency_cost, - SUM(t_MPOPL.value_produced_total_local), - a_id_user, - v_id_change_set, - a_active - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - -- SET v_id_order_new - SET a_id_order := (SELECT id_order FROM Shop_Manufacturing_Purchase_Order ORDER BY id_order DESC LIMIT 1); - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - a_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - ELSE - UPDATE Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPO.id_order = t_MPOPL.id_order - SET - -- MPO.id_supplier_ordered = a_id_supplier_ordered, - MPO.cost_total_local = SUM(t_MPOPL.cost_total_local), - MPO.value_produced_total_local = SUM(t_MPOPL.value_produced_total_local), - MPO.id_currency = a_id_currency_cost, - MPO.id_change_set = v_id_change_set, - MPO.active = a_active - WHERE MPO.id_order = a_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL INNER JOIN Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link) THEN - UPDATE Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - SET - MPOPL.id_order = t_MPOPL.id_order, - MPOPL.id_permutation = t_MPOPL.id_permutation, - MPOPL.cost_total_local = t_MPOPL.cost_total_local, - MPOPL.value_produced_total_local = t_MPOPL.value_produced_total_local, - MPOPL.id_currency_cost = t_MPOPL.id_currency_cost, - MPOPL.quantity_used = t_MPOPL.quantity_used, - MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity, - MPOPL.quantity_produced = t_MPOPL.quantity_produced, - MPOPL.latency_manufacture_days = t_MPOPL.latency_manufacture_days, - MPOPL.display_order = t_MPOPL.display_order, - MPOPL.active = t_MPOPL.active, - MPOPL.id_change_set = v_id_change_set - ; - ELSE - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.id_link < 0 - ; - END IF; - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - END IF; - - -- Returns - # SET v_now = NOW(); - - # Manufacturing Purchase Orders - SELECT * - FROM Shop_Manufacturing_Purchase_Order - WHERE - id_order = a_id_order - -- GUID = a_guid - ; - - # Manufacturing Purchase Order Product Links - SELECT * - FROM Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - id_order = a_id_order - -- GUID = a_guid - ; - - # Errors - SELECT * - FROM tmp_Msg_Error - ; - - # DROP TABLE tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ;; - - -/* - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture_days, - display_order, - active -) -VALUES - ( - 'NIPS', # guid - -1, # id_link, - -1, # id_order, - 1, # id_permutation, - 100, # cost_total_local, - 1, # id_currency_cost, - 1, # quantity_used, - 1, # id_unit_quantity, - 1, # quantity_produced, - 14, # latency_manufacture_days , - 1, # display_order - 1 # active - ) -; - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_manufacturing_purchase_order ( - 'NIPS', # a_guid - 'auth0|6582b95c895d09a70ba10fef', # a_id_user - -1, # a_id_order - 1, # a_id_currency_cost - 1, # a_active - 'Initial data' # a_comment -); - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - - -*/ - diff --git a/static/MySQL/7206_p_shop_save_product_permutation.sql b/static/MySQL/7206_p_shop_save_product_permutation.sql new file mode 100644 index 00000000..fa7dc476 --- /dev/null +++ b/static/MySQL/7206_p_shop_save_product_permutation.sql @@ -0,0 +1,561 @@ + + +-- Clear previous proc +DROP PROCEDURE IF EXISTS p_shop_save_permutation; +DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; + +DELIMITER // +CREATE PROCEDURE p_shop_save_product_permutation ( + IN a_id_user INT, + IN a_comment VARCHAR(500), + IN a_guid BINARY(36) +) +BEGIN + + DECLARE v_code_type_error_bad_data VARCHAR(100); + DECLARE v_id_type_error_bad_data INT; + DECLARE v_id_permission_product INT; + DECLARE v_ids_product_permission LONGTEXT; + DECLARE v_id_change_set INT; + DECLARE v_id_access_level_edit INT; + DECLARE v_now TIMESTAMP; + + DECLARE exit handler for SQLEXCEPTION + BEGIN + -- Get diagnostic information + GET DIAGNOSTICS CONDITION 1 + @sqlstate = RETURNED_SQLSTATE + , @errno = MYSQL_ERRNO + , @text = MESSAGE_TEXT + ; + + -- Rollback the transaction + ROLLBACK; + + -- Select the error information + -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , guid BINARY(36) NOT NULL + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , code + , msg + ) + SELECT + a_guid + , NULL + , @errno + , @text + ; + SELECT * + FROM tmp_Msg_Error; + DROP TABLE IF EXISTS tmp_Msg_Error; + END; + + SET v_code_type_error_bad_data := 'BAD_DATA'; + SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); + SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); + + SET a_guid := IFNULL(a_guid, UUID()); + + DROP TABLE IF EXISTS tmp_Permutation; + + CREATE TEMPORARY TABLE tmp_Permutation ( + id_permutation INT NOT NULL + , id_product INT NOT NULL + , description VARCHAR(4000) NOT NULL + , cost_local FLOAT NOT NULL + , id_currency_cost INT NOT NULL + , profit_local_min FLOAT NOT NULL + , latency_manufacture_days INT NOT NULL + , id_unit_measurement_quantity INT NOT NULL + , count_unit_measurement_per_quantity_step FLOAT NOT NULL + , quantity_min FLOAT NOT NULL + , quantity_max FLOAT NOT NULL + , quantity_stock FLOAT NOT NULL + , is_subscription BIT NOT NULL + , id_unit_measurement_interval_recurrence INT + , count_interval_recurrence INT + , id_stripe_product VARCHAR(100) NULL + , does_expire_faster_once_unsealed BIT NOT NULL + , id_unit_measurement_interval_expiration_unsealed INT + , count_interval_expiration_unsealed INT + , active BIT NOT NULL DEFAULT 1 + , can_view BIT NULL + , can_edit BIT NULL + , can_admin BIT NULL + , name_error VARCHAR(255) NOT NULL + , is_new BIT NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , guid BINARY(36) NOT NULL + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + + -- Get data from Temp table + INSERT INTO tmp_Permutation ( + id_permutation + , id_product + , description + , cost_local + , id_currency_cost + , profit_local_min + , latency_manufacture_days + , id_unit_measurement_quantity + , count_unit_measurement_per_quantity_step + , quantity_min + , quantity_max + , quantity_stock + , is_subscription + , id_unit_measurement_interval_recurrence + , count_interval_recurrence + , id_stripe_product + , does_expire_faster_once_unsealed + , id_unit_measurement_interval_expiration_unsealed + , count_interval_expiration_unsealed + , active + , name_error + , is_new + ) + SELECT + PP_T.id_permutation + , IFNULL(PP_T.id_product, PP.id_product) AS id_product + , IFNULL(PP_T.description, PP.description) AS description + , IFNULL(PP_T.cost_local, PP.cost_local) AS cost_local + , IFNULL(PP_T.id_currency_cost, PP.id_currency_cost) AS a_id_currency_cost + , IFNULL(PP_T.profit_local_min, PP.profit_local_min) AS profit_local_min + , IFNULL(PP_T.latency_manufacture_days, PP.latency_manufacture_days) AS latency_manufacture_days + , IFNULL(PP_T.id_unit_measurement_quantity, PP.id_unit_measurement_quantity) AS id_unit_measurement_quantity + , IFNULL(PP_T.count_unit_measurement_per_quantity_step, PP.count_unit_measurement_per_quantity_step) AS count_unit_measurement_per_quantity_step + , IFNULL(PP_T.quantity_min, PP.quantity_min) AS quantity_min + , IFNULL(PP_T.quantity_max, PP.quantity_max) AS quantity_max + , IFNULL(PP_T.quantity_stock, PP.quantity_stock) AS quantity_stock + , IFNULL(PP_T.is_subscription, PP.is_subscription) AS is_subscription + , IFNULL(PP_T.id_unit_measurement_interval_recurrence, PP.id_unit_measurement_interval_recurrence) AS id_unit_measurement_interval_recurrence + , IFNULL(PP_T.count_interval_recurrence, PP.count_interval_recurrence) AS count_interval_recurrence + , IFNULL(PP_T.id_stripe_product, PP.id_stripe_product) AS id_stripe_product + , IFNULL(PP_T.does_expire_faster_once_unsealed, PP.does_expire_faster_once_unsealed) AS does_expire_faster_once_unsealed + , IFNULL(PP_T.id_unit_measurement_interval_expiration_unsealed, PP.id_unit_measurement_interval_expiration_unsealed) AS id_unit_measurement_interval_expiration_unsealed + , IFNULL(PP_T.count_interval_expiration_unsealed, PP.count_interval_expiration_unsealed) AS count_interval_expiration_unsealed + , IFNULL(PP_T.active, PP.active) AS active + , fn_shop_get_product_permutation_name(PP_T.id_permutation) + , CASE WHEN IFNULL(PP_T.id_permutation, 0) < 1 THEN 1 ELSE 0 END AS is_new + FROM Shop_Product_Permutation_Temp PP_T + LEFT JOIN Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation + WHERE PP_T.guid = a_guid + ; + + -- Validation + -- Missing mandatory fields + -- id_product + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_product) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , id_product + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a product: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.id_product) + ; + END IF; + -- cost_local + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.cost_local) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , cost_local + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a local cost: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.cost_local) + ; + END IF; + -- profit_local_min + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.profit_local_min) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , profit_local_min + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a local minimum profit: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.profit_local_min) + ; + END IF; + -- latency_manufacture_days + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.latency_manufacture_days) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , latency_manufacture_days + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a manufacturing latency: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.latency_manufacture_days) + ; + END IF; + -- id_unit_measurement_quantity + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_unit_measurement_quantity) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , id_unit_measurement_quantity + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a unit measurement for stock quantities: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.id_unit_measurement_quantity) + ; + END IF; + -- count_unit_measurement_per_quantity_step + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , count_unit_measurement_per_quantity_step + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a count unit measurement per quantity step: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) + ; + END IF; + -- quantity_min + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_min) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , quantity_min + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a minimum quantity: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.quantity_min) + ; + END IF; + -- quantity_max + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_max) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , quantity_max + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a maximum quantity: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.quantity_max) + ; + END IF; + -- is_subscription + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.is_subscription) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , is_subscription + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have an is subscription?: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.is_subscription) + ; + END IF; + -- does_expire_faster_once_unsealed + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.does_expire_faster_once_unsealed) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , does_expire_faster_once_unsealed + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have a does expire faster once unsealed: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.does_expire_faster_once_unsealed) + ; + END IF; + + -- Permissions + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN -- (SELECT * FROM tmp_Product WHERE is_new = 0 LIMIT 1) THEN + SET v_ids_product_permission := ( + SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') + FROM Shop_Product P + INNER JOIN tmp_Permutation t_P + ON P.id_product = t_P.id_product + -- AND t_P.is_new = 0 + ); + IF NOT ISNULL(v_ids_product_permission) THEN + SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); + + CALL p_shop_user_eval(a_guid, a_id_user, FALSE, v_id_permission_product, v_id_access_level_edit, v_ids_product_permission); + + UPDATE tmp_Permutation t_P + INNER JOIN Shop_Product P ON t_P.id_product = P.id_product + INNER JOIN Shop_User_Eval_Temp UE_T + ON P.id_product = UE_T.id_product + AND UE_T.GUID = a_guid + SET + t_P.can_view = UE_T.can_view + , t_P.can_edit = UE_T.can_edit + , t_P.can_admin = UE_T.can_admin + ; + + CALL p_clear_shop_user_eval_temp(a_guid); + + IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.can_edit) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + guid + , id_type + , code + , msg + ) + SELECT + a_guid AS GUID + , v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following product permutation(s) do not have product edit permission: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')) AS msg + FROM tmp_Permutation t_P + WHERE ISNULL(t_P.can_edit) + ; + END IF; + END IF; + END IF; + + SET v_now := CURRENT_TIMESTAMP(); + + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + START TRANSACTION; + + IF NOT ISNULL(v_ids_product_permission) THEN + INSERT INTO Shop_Product_Change_Set ( comment ) + VALUES ( a_comment ) + ; + + SET v_id_change_set := LAST_INSERT_ID(); + + UPDATE Shop_Product_Permutation PP + INNER JOIN tmp_Permutation t_P ON PP.id_permutation = t_P.id_permutation + SET + PP.id_product = t_P.id_product + , PP.description = t_P.description + , PP.cost_local = t_P.cost_local + , PP.id_currency_cost = t_P.id_currency_cost + , PP.profit_local_min = t_P.profit_local_min + , PP.latency_manufacture_days = t_P.latency_manufacture_days + , PP.id_unit_measurement_quantity = t_P.id_unit_measurement_quantity + , PP.count_unit_measurement_per_quantity_step = t_P.count_unit_measurement_per_quantity_step + , PP.quantity_min = t_P.quantity_min + , PP.quantity_max = t_P.quantity_max + , PP.quantity_stock = t_P.quantity_stock + , PP.is_subscription = t_P.is_subscription + , PP.id_unit_measurement_interval_recurrence = t_P.id_unit_measurement_interval_recurrence + , PP.count_interval_recurrence = t_P.count_interval_recurrence + , PP.id_stripe_product = t_P.id_stripe_product + , PP.does_expire_faster_once_unsealed = t_P.does_expire_faster_once_unsealed + , PP.id_unit_measurement_interval_expiration_unsealed = t_P.id_unit_measurement_interval_expiration_unsealed + , PP.count_interval_expiration_unsealed = t_P.count_interval_expiration_unsealed + , PP.active = t_P.active + , PP.id_change_set = v_id_change_set + ; + END IF; + + INSERT INTO Shop_Product_Permutation ( + id_product + , description + , cost_local + , id_currency_cost + , profit_local_min + , latency_manufacture_days + , id_unit_measurement_quantity + , count_unit_measurement_per_quantity_step + , quantity_min + , quantity_max + , quantity_stock + , is_subscription + , id_unit_measurement_interval_recurrence + , count_interval_recurrence + , id_stripe_product + , does_expire_faster_once_unsealed + , id_unit_measurement_interval_expiration_unsealed + , count_interval_expiration_unsealed + , active + , created_by + , created_on + ) + SELECT + t_P.id_product AS id_product + , t_P.description AS description + , t_P.cost_local AS cost_local + , t_P.id_currency_cost AS id_currency_cost + , t_P.profit_local_min AS profit_local_min + , t_P.latency_manufacture_days AS latency_manufacture_days + , t_P.id_unit_measurement_quantity AS id_unit_measurement_quantity + , t_P.count_unit_measurement_per_quantity_step AS count_unit_measurement_per_quantity_step + , t_P.quantity_min AS quantity_min + , t_P.quantity_max AS quantity_max + , t_P.quantity_stock AS quantity_stock + , t_P.is_subscription AS is_subscription + , t_P.id_unit_measurement_interval_recurrence AS id_unit_measurement_interval_recurrence + , t_P.count_interval_recurrence AS count_interval_recurrence + , t_P.id_stripe_product AS id_stripe_product + , t_P.does_expire_faster_once_unsealed AS does_expire_faster_once_unsealed + , t_P.id_unit_measurement_interval_expiration_unsealed AS id_unit_measurement_interval_expiration_unsealed + , t_P.count_interval_expiration_unsealed AS count_interval_expiration_unsealed + , t_P.active AS active + , a_id_user AS created_by + , v_now AS created_on + FROM tmp_Permutation t_P + WHERE + is_new = 1 + AND active = 1 + ; + + DELETE FROM Shop_Product_Permutation_Temp + WHERE GUID = a_guid; + + COMMIT; + END IF; + + SELECT * FROM tmp_Msg_Error; + + DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; + DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; +END // +DELIMITER ;; + + +/* + +DELETE FROM Shop_Product_Permutation_Temp +WHERE id_permutation = 1 +; + +INSERT INTO Shop_Product_Permutation_Temp ( + id_permutation, + id_product, + description, + cost_local, + id_currency_cost, + profit_local_min, + latency_manufacture_days, + id_unit_measurement_quantity, + count_unit_measurement_per_quantity_step, + quantity_min, + quantity_max, + quantity_stock, + is_subscription, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, + id_stripe_product, + does_expire_faster_once_unsealed, + id_unit_measurement_interval_expiration_unsealed, + count_interval_expiration_unsealed, + active, + guid +) +VALUES + ( + 1 -- id_permutation, + , 1 -- id_product, + , 'Good Reddy Teddy' -- description, + , 5.0 -- cost_local, + , 1 -- id_currency_cost, + , 3.0 -- profit_local_min, + , 14 -- latency_manufacture_days, + , 1 -- id_unit_measurement_quantity, + , 1.0 -- count_unit_measurement_quantity, + , 3.0 -- quantity_min, + , 99.0 -- quantity_max, + , 1.0 -- quantity_stock, + , False -- is_subscription, + , null -- id_unit_measurement_interval_recurrence, + , null -- count_interval_recurrence, + , null -- id_stripe_product, + , False -- does_expire_faster_once_unsealed, + , null -- id_unit_measurement_interval_expiration_unsealed, + , null -- count_interval_expiration_unsealed, + , True -- active, + , 'NIPS' -- guid + ) +; + +select 'Shop_Product_Permutation_Temp before call'; +SELECT * FROM Shop_Product_Permutation_Temp; + +SELECT 'Shop_Product_Permutation before call' AS result_name; +select * FROM Shop_Product_Permutation; + +CALL p_shop_save_product_permutation ( + 1, -- 'auth0|6582b95c895d09a70ba10fef', # a_id_user + 'Initial data', # a_comment + 'NIPS' # a_guid +); + +SELECT 'Shop_Product_Permutation_Temp after call' AS result_name; +select * FROM Shop_Product_Permutation_Temp; + +SELECT 'Shop_Product_Permutation after call' AS result_name; +select * FROM Shop_Product_Permutation; + + +DELETE FROM Shop_Product_Permutation_Temp +WHERE id_permutation = 1; + + +*/ + diff --git a/static/MySQL/7210_p_shop_get_many_product_variation.sql b/static/MySQL/7210_p_shop_get_many_product_variation.sql index 04af5d47..95db8753 100644 --- a/static/MySQL/7210_p_shop_get_many_product_variation.sql +++ b/static/MySQL/7210_p_shop_get_many_product_variation.sql @@ -1,23 +1,6 @@ - - -/* - -CALL p_shop_get_many_product_variation ( - '', # a_id_user - 1, # a_get_all_supplier - 0, # a_get_inactive_variation - 0, # a_get_first_variation_only - '', # a_ids_variation -); - -*/ - - --- Clear previous proc DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; - DELIMITER // CREATE PROCEDURE p_shop_get_many_product_variation ( IN a_id_user INT, @@ -236,32 +219,33 @@ BEGIN END IF; -- Returns - /* # Variation Types SELECT t_VT.id_type , VT.code , VT.name , VT.name_plural + , VT.display_order , VT.active FROM tmp_Variation_Type t_VT INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type ; - */ # Variations SELECT t_V.id_variation + , t_V.id_type , V.code AS code_variation , V.name AS name_variation - , V.active AS active_variation , V.display_order - , t_V.id_type + , V.active AS active_variation + /* , VT.code AS code_variation_type , VT.name AS name_variation_type , VT.name_plural AS name_plural_variation_type , VT.active AS active_variation_type , VT.display_order + */ FROM tmp_Variation t_V INNER JOIN Shop_Variation V ON t_V.id_variation = V.id_variation INNER JOIN tmp_Variation_Type t_VT ON V.id_type = t_VT.id_type diff --git a/static/MySQL/7219_p_shop_get_many_stock_item.sql b/static/MySQL/7219_p_shop_get_many_stock_item.sql index 8a649694..35936cf1 100644 --- a/static/MySQL/7219_p_shop_get_many_stock_item.sql +++ b/static/MySQL/7219_p_shop_get_many_stock_item.sql @@ -166,17 +166,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, * - , latency_manufacture INT NOT NULL + , latency_manufacture_days INT NOT NULL , quantity_min FLOAT NOT NULL , quantity_max FLOAT NOT NULL , quantity_step FLOAT NOT NULL , quantity_stock FLOAT NOT NULL , is_subscription BIT NOT NULL - , id_recurrence_interval INT - , CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) - , count_recurrence_interval INT + , id_unit_measurement_interval_recurrence INT + , CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval) + , count_interval_recurrence INT , id_stripe_product VARCHAR(100) , product_has_variations INT NOT NULL , can_view BIT diff --git a/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql b/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql index d732910f..b1135907 100644 --- a/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql +++ b/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql @@ -480,15 +480,15 @@ BEGIN CURRENCY.code AS code_currency_cost, CURRENCY.symbol AS symbol_currency_cost, PP.profit_local_min, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - UM.name_singular AS name_recurrence_interval, - UM.name_plural AS name_plural_recurrence_interval, + UM.name_singular AS name_interval_recurrence, + UM.name_plural AS name_plural_interval_recurrence, PP.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, @@ -499,8 +499,8 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_interval_recurrence = UM.id_unit_measurement + -- LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval + LEFT JOIN Shop_Unit_Measurement UM ON PP.id_unit_measurement_interval_recurrence = UM.id_unit_measurement INNER JOIN Shop_Currency CURRENCY ON PP.id_currency_cost = CURRENCY.id_currency ORDER BY t_P.rank_permutation ; @@ -764,36 +764,20 @@ DELIMITER ;; /* -CALL partsltd_prod.p_shop_get_many_product ( - 1, #'auth0|6582b95c895d09a70ba10fef', # a_id_user - 1, # a_get_all_category - 1, # a_get_inactive_category - 0, # a_get_first_category_only - '', # a_ids_category - 1, # a_get_all_product - 0, # a_get_inactive_product - 0, # a_get_first_product_only - '', # a_ids_product - 1, # a_get_all_product_permutation - 0, # a_get_inactive_permutation - 0, # a_get_first_permutation_only - '', # a_ids_permutation - 1, # a_get_all_image - 0, # a_get_inactive_image - 0, # a_get_first_image_only - '', # a_ids_image - 1, # a_get_all_delivery_region - 0, # a_get_inactive_delivery_region - 0, # a_get_first_delivery_region_only - '', # a_ids_delivery_region - 1, # a_get_all_currency - 0, # a_get_inactive_currency - 0, # a_get_first_currency_only - '', # a_ids_currency - 1, # a_get_all_discount - 0, # a_get_inactive_discount - '', # a_ids_discount - 1 # a_get_products_quantity_stock_below_minimum +CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_region ( + IN a_id_user INT, + IN a_get_all_product_permutation BIT, + IN a_get_inactive_permutation BIT, + IN a_ids_permutation VARCHAR(4000), + IN a_get_all_delivery_region BIT, + IN a_get_inactive_delivery_region BIT, + IN a_ids_delivery_region VARCHAR(4000), + IN a_get_all_currency BIT, + IN a_get_inactive_currency BIT, + IN a_ids_currency VARCHAR(4000), + IN a_get_all_discount BIT, + IN a_get_inactive_discount BIT, + IN a_ids_discount VARCHAR(4000) ); select * FROM Shop_User_Eval_Temp; diff --git a/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql b/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql index 4502cc41..bf44f939 100644 --- a/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql +++ b/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql @@ -195,13 +195,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency diff --git a/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql b/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql index 64756059..f1bbf4cb 100644 --- a/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql +++ b/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql @@ -196,17 +196,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, */ - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, can_view BIT, @@ -388,14 +388,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -420,14 +420,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql b/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql index 25432aa5..a78eb37a 100644 --- a/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql +++ b/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql @@ -168,17 +168,17 @@ BEGIN price_GBP_min FLOAT NOT NULL, */ /* - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, */ @@ -308,14 +308,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -340,14 +340,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql b/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql index deb220fe..6097a4d7 100644 --- a/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql +++ b/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql @@ -203,17 +203,17 @@ BEGIN price_GBP_min FLOAT NOT NULL, */ /* - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, */ @@ -398,14 +398,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, * - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -430,14 +430,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, * - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/MySQL/9000_populate.sql b/static/MySQL/9000_populate.sql index da7abdd9..0b035493 100644 --- a/static/MySQL/9000_populate.sql +++ b/static/MySQL/9000_populate.sql @@ -140,13 +140,13 @@ VALUES # Unit of Measurement INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit + name_singular, name_plural, symbol, is_base_unit, is_unit_of_distance, is_unit_of_mass, is_unit_of_time, is_unit_of_volume ) VALUES - ('metre', 'metres', 'm', 1), - ('kilogram', 'kilograms', 'kg', 1), - ('item', 'items', 'x', 0), - ('hour', 'hours', 'h', 1) + ('metre', 'metres', 'm', 1, 1, 0, 0, 0), + ('kilogram', 'kilograms', 'kg', 1, 0, 1, 0, 0), + ('item', 'items', 'x', 0, 0, 0, 0, 0), + ('hour', 'hours', 'h', 1, 0, 0, 1, 0) ; /* @@ -177,7 +177,7 @@ VALUES /* # Recurrence Interval -INSERT INTO Shop_Recurrence_Interval ( +INSERT INTO Shop_Interval_Recurrence ( code, name, name_plural ) VALUES @@ -248,18 +248,19 @@ INSERT INTO Shop_Product_Permutation ( id_currency_cost, profit_local_min, # id_currency_profit_min, - latency_manufacture, - quantity_min, + latency_manufacture_days, + id_unit_measurement_quantity, + count_unit_measurement_per_quantity_step, + quantity_min, quantity_max, - quantity_step, quantity_stock, is_subscription, - id_interval_recurrence, + id_unit_measurement_interval_recurrence, count_interval_recurrence, -- id_access_level_required, id_stripe_product , does_expire_faster_once_unsealed - , id_interval_expiration_unsealed + , id_unit_measurement_interval_expiration_unsealed , count_interval_expiration_unsealed ) VALUES @@ -273,9 +274,10 @@ VALUES # 1, 14, 1, - 3, 1, + 3, 99, + 1, 0, NULL, NULL, @@ -295,9 +297,10 @@ VALUES # 1, 14, 1, - 3, 1, + 3, 99, + 1, 0, NULL, NULL, @@ -317,9 +320,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -339,9 +343,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -361,9 +366,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, @@ -383,9 +389,10 @@ VALUES # 1, 14, 1, - 2, 1, + 2, 99, + 1, 0, NULL, NULL, diff --git a/static/MySQL/9001_view.sql b/static/MySQL/9001_view.sql index 644de0f7..291e0c58 100644 --- a/static/MySQL/9001_view.sql +++ b/static/MySQL/9001_view.sql @@ -68,8 +68,8 @@ SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; /* # Recurrence Interval -SELECT * FROM Shop_Recurrence_Interval; -SELECT * FROM Shop_Recurrence_Interval_Audit; +SELECT * FROM Shop_Interval_Recurrence; +SELECT * FROM Shop_Interval_Recurrence_Audit; */ diff --git a/static/MySQL/deprecated/000_init_tables_product.sql b/static/MySQL/deprecated/000_init_tables_product.sql index 12ab4c35..8df93a55 100644 --- a/static/MySQL/deprecated/000_init_tables_product.sql +++ b/static/MySQL/deprecated/000_init_tables_product.sql @@ -36,8 +36,8 @@ DROP TABLE IF EXISTS Shop_Variation_Type; DROP TABLE IF EXISTS Shop_Product_Audit; DROP TABLE IF EXISTS Shop_Product; -DROP TABLE IF EXISTS Shop_Recurrence_Interval_Audit; -DROP TABLE IF EXISTS Shop_Recurrence_Interval; +DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; +DROP TABLE IF EXISTS Shop_Interval_Recurrence; DROP TABLE IF EXISTS Shop_Product_Category_Audit; DROP TABLE IF EXISTS Shop_Product_Category; @@ -342,7 +342,7 @@ SELECT * FROM Shop_Product_Category_Audit; # Recurrence Interval -CREATE TABLE Shop_Recurrence_Interval ( +CREATE TABLE Shop_Interval_Recurrence ( id_interval INT NOT NULL AUTO_INCREMENT PRIMARY KEY, code VARCHAR(50), name VARCHAR(255), @@ -350,14 +350,14 @@ CREATE TABLE Shop_Recurrence_Interval ( created_on TIMESTAMP, created_by INT, id_change_set INT, - CONSTRAINT FK_Shop_Recurrence_Interval_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); DELIMITER // -CREATE TRIGGER before_insert_Shop_Recurrence_Interval -BEFORE INSERT ON Shop_Recurrence_Interval +CREATE TRIGGER before_insert_Shop_Interval_Recurrence +BEFORE INSERT ON Shop_Interval_Recurrence FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); @@ -365,28 +365,28 @@ BEGIN END // DELIMITER ;; -CREATE TABLE Shop_Recurrence_Interval_Audit ( +CREATE TABLE Shop_Interval_Recurrence_Audit ( id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id_interval INT NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_interval + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval FOREIGN KEY (id_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) + REFERENCES Shop_Interval_Recurrence(id_interval) ON UPDATE RESTRICT, name_field VARCHAR(50), value_prev VARCHAR(256), value_new VARCHAR(256), id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); DELIMITER // -CREATE TRIGGER before_update_Shop_Recurrence_Interval -BEFORE UPDATE ON Shop_Recurrence_Interval +CREATE TRIGGER before_update_Shop_Interval_Recurrence +BEFORE UPDATE ON Shop_Interval_Recurrence FOR EACH ROW BEGIN - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, @@ -408,7 +408,7 @@ BEGIN END // DELIMITER ;; -INSERT INTO Shop_Recurrence_Interval ( +INSERT INTO Shop_Interval_Recurrence ( code, name, name_plural ) VALUES @@ -417,8 +417,8 @@ VALUES ('YEAR', 'Year', 'Years') ; -SELECT * FROM Shop_Recurrence_Interval; -SELECT * FROM Shop_Recurrence_Interval_Audit; +SELECT * FROM Shop_Interval_Recurrence; +SELECT * FROM Shop_Interval_Recurrence_Audit; @@ -439,11 +439,11 @@ CREATE TABLE Shop_Product ( quantity_step FLOAT NOT NULL DEFAULT 1, quantity_stock FLOAT NOT NULL DEFAULT 0, is_subscription BIT NOT NULL DEFAULT 0, - id_recurrence_interval INT, - CONSTRAINT FK_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), id_stripe_price VARCHAR(100), active BIT NOT NULL DEFAULT 1, @@ -534,13 +534,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set diff --git a/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql b/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql index e75895d3..0f0906b5 100644 --- a/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql +++ b/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql @@ -3,9 +3,9 @@ -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( id_interval INT NOT NULL AUTO_INCREMENT PRIMARY KEY, code VARCHAR(50), name VARCHAR(255), @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( created_on TIMESTAMP, created_by INT, id_change_set INT, - CONSTRAINT FK_Shop_Recurrence_Interval_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); diff --git a/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql b/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql index c38c8110..d84813f4 100644 --- a/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql +++ b/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql @@ -3,20 +3,20 @@ -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval_Audit'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval_Audit ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, id_interval INT NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_interval + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval FOREIGN KEY (id_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) + REFERENCES Shop_Interval_Recurrence(id_interval) ON UPDATE RESTRICT, name_field VARCHAR(50), value_prev VARCHAR(256), value_new VARCHAR(256), id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); diff --git a/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql b/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql index d3088c7d..32f479ae 100644 --- a/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql +++ b/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql @@ -4,13 +4,13 @@ -DROP TRIGGER IF EXISTS before_insert_Shop_Recurrence_Interval; -DROP TRIGGER IF EXISTS before_update_Shop_Recurrence_Interval; +DROP TRIGGER IF EXISTS before_insert_Shop_Interval_Recurrence; +DROP TRIGGER IF EXISTS before_update_Shop_Interval_Recurrence; DELIMITER // -CREATE TRIGGER before_insert_Shop_Recurrence_Interval -BEFORE INSERT ON Shop_Recurrence_Interval +CREATE TRIGGER before_insert_Shop_Interval_Recurrence +BEFORE INSERT ON Shop_Interval_Recurrence FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); @@ -20,8 +20,8 @@ DELIMITER ;; DELIMITER // -CREATE TRIGGER before_update_Shop_Recurrence_Interval -BEFORE UPDATE ON Shop_Recurrence_Interval +CREATE TRIGGER before_update_Shop_Interval_Recurrence +BEFORE UPDATE ON Shop_Interval_Recurrence FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -29,7 +29,7 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, diff --git a/static/MySQL/deprecated/706_p_shop_get_product.sql b/static/MySQL/deprecated/706_p_shop_get_product.sql index 15fd3d94..7c034293 100644 --- a/static/MySQL/deprecated/706_p_shop_get_product.sql +++ b/static/MySQL/deprecated/706_p_shop_get_product.sql @@ -309,14 +309,14 @@ BEGIN P.quantity_stock, P.id_stripe_product, P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - P.count_recurrence_interval + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + P.count_interval_recurrence FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - LEFT JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval WHERE ISNULL(t_P.id_permutation) ORDER BY t_P.display_order ; @@ -336,17 +336,17 @@ BEGIN P.quantity_stock, P.id_stripe_product, P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - P.count_recurrence_interval + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + P.count_interval_recurrence FROM tmp_Shop_Product t_P INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation AND PP.active INNER JOIN Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval WHERE NOT ISNULL(t_P.id_permutation) ORDER BY t_P.display_order ; diff --git a/static/MySQL/deprecated/dump.sql b/static/MySQL/deprecated/dump.sql index 63450d0f..86b1b6de 100644 --- a/static/MySQL/deprecated/dump.sql +++ b/static/MySQL/deprecated/dump.sql @@ -1964,11 +1964,11 @@ DELIMITER ;;; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -2038,13 +2038,13 @@ DELIMITER ;;; SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_access_level_required SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set @@ -2674,14 +2674,14 @@ CREATE TABLE `shop_product_permutation` ( `id_currency_cost_manufacturing` int NOT NULL, `profit_local_min` float NOT NULL, `id_currency_profit_min` int NOT NULL, - `latency_manufacture` int NOT NULL, + `latency_manufacture_days` int NOT NULL, `quantity_min` float NOT NULL, `quantity_max` float NOT NULL, `quantity_step` float NOT NULL, `quantity_stock` float NOT NULL, `is_subscription` bit(1) NOT NULL, - `id_recurrence_interval` int DEFAULT NULL, - `count_recurrence_interval` int DEFAULT NULL, + `id_unit_measurement_interval_recurrence` int DEFAULT NULL, + `count_interval_recurrence` int DEFAULT NULL, `id_access_level_required` int NOT NULL, `id_stripe_product` varchar(100) DEFAULT NULL, `active` bit(1) NOT NULL DEFAULT b'1', @@ -2691,11 +2691,11 @@ CREATE TABLE `shop_product_permutation` ( `id_change_set` int DEFAULT NULL, PRIMARY KEY (`id_permutation`), KEY `FK_Shop_Product_Variation_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Permutation_id_recurrence_interval` (`id_recurrence_interval`), + KEY `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` (`id_unit_measurement_interval_recurrence`), KEY `FK_Shop_Product_Permutation_id_access_level_required` (`id_access_level_required`), KEY `FK_Shop_Product_Variation_Link_id_change_set` (`id_change_set`), CONSTRAINT `FK_Shop_Product_Permutation_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_Permutation_id_recurrence_interval` FOREIGN KEY (`id_recurrence_interval`) REFERENCES `shop_recurrence_interval` (`id_interval`), + CONSTRAINT `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` FOREIGN KEY (`id_unit_measurement_interval_recurrence`) REFERENCES `shop_interval_recurrence` (`id_interval`), CONSTRAINT `FK_Shop_Product_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), CONSTRAINT `FK_Shop_Product_Variation_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; @@ -2794,9 +2794,9 @@ DELIMITER ;;; WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - # Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + # Changed latency_manufacture_days + SELECT NEW.id_product, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days UNION # Changed quantity_min SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set @@ -2818,13 +2818,13 @@ DELIMITER ;;; SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set @@ -3012,13 +3012,13 @@ LOCK TABLES `shop_product_permutation_variation_link_audit` WRITE; UNLOCK TABLES; -- --- Table structure for table `shop_recurrence_interval` +-- Table structure for table `shop_interval_recurrence` -- -DROP TABLE IF EXISTS `shop_recurrence_interval`; +DROP TABLE IF EXISTS `shop_interval_recurrence`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_recurrence_interval` ( +CREATE TABLE `shop_interval_recurrence` ( `id_interval` int NOT NULL AUTO_INCREMENT, `code` varchar(50) DEFAULT NULL, `name` varchar(255) DEFAULT NULL, @@ -3028,19 +3028,19 @@ CREATE TABLE `shop_recurrence_interval` ( `created_by` varchar(100) DEFAULT NULL, `id_change_set` int DEFAULT NULL, PRIMARY KEY (`id_interval`), - KEY `FK_Shop_Recurrence_Interval_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) + KEY `FK_Shop_Interval_Recurrence_id_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Dumping data for table `shop_recurrence_interval` +-- Dumping data for table `shop_interval_recurrence` -- -LOCK TABLES `shop_recurrence_interval` WRITE; -/*!40000 ALTER TABLE `shop_recurrence_interval` DISABLE KEYS */; -INSERT INTO `shop_recurrence_interval` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_recurrence_interval` ENABLE KEYS */; +LOCK TABLES `shop_interval_recurrence` WRITE; +/*!40000 ALTER TABLE `shop_interval_recurrence` DISABLE KEYS */; +INSERT INTO `shop_interval_recurrence` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); +/*!40000 ALTER TABLE `shop_interval_recurrence` ENABLE KEYS */; UNLOCK TABLES; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3051,7 +3051,7 @@ UNLOCK TABLES; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Recurrence_Interval` BEFORE INSERT ON `shop_recurrence_interval` FOR EACH ROW BEGIN +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Interval_Recurrence` BEFORE INSERT ON `shop_interval_recurrence` FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END */;; @@ -3069,13 +3069,13 @@ DELIMITER ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Recurrence_Interval` BEFORE UPDATE ON `shop_recurrence_interval` FOR EACH ROW BEGIN +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Interval_Recurrence` BEFORE UPDATE ON `shop_interval_recurrence` FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, @@ -3106,13 +3106,13 @@ DELIMITER ;; /*!50003 SET collation_connection = @saved_col_connection */ ; -- --- Table structure for table `shop_recurrence_interval_audit` +-- Table structure for table `shop_interval_recurrence_audit` -- -DROP TABLE IF EXISTS `shop_recurrence_interval_audit`; +DROP TABLE IF EXISTS `shop_interval_recurrence_audit`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_recurrence_interval_audit` ( +CREATE TABLE `shop_interval_recurrence_audit` ( `id_audit` int NOT NULL AUTO_INCREMENT, `id_interval` int NOT NULL, `name_field` varchar(50) DEFAULT NULL, @@ -3120,20 +3120,20 @@ CREATE TABLE `shop_recurrence_interval_audit` ( `value_new` varchar(256) DEFAULT NULL, `id_change_set` int NOT NULL, PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Recurrence_Interval_Audit_id_interval` (`id_interval`), - KEY `FK_Shop_Recurrence_Interval_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_recurrence_interval` (`id_interval`) ON UPDATE RESTRICT + KEY `FK_Shop_Interval_Recurrence_Audit_id_interval` (`id_interval`), + KEY `FK_Shop_Interval_Recurrence_Audit_id_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_interval_recurrence` (`id_interval`) ON UPDATE RESTRICT ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Dumping data for table `shop_recurrence_interval_audit` +-- Dumping data for table `shop_interval_recurrence_audit` -- -LOCK TABLES `shop_recurrence_interval_audit` WRITE; -/*!40000 ALTER TABLE `shop_recurrence_interval_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_recurrence_interval_audit` ENABLE KEYS */; +LOCK TABLES `shop_interval_recurrence_audit` WRITE; +/*!40000 ALTER TABLE `shop_interval_recurrence_audit` DISABLE KEYS */; +/*!40000 ALTER TABLE `shop_interval_recurrence_audit` ENABLE KEYS */; UNLOCK TABLES; -- @@ -6110,17 +6110,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, */ - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, can_view BIT, @@ -6224,14 +6224,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations ) @@ -6254,14 +6254,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations FROM Shop_Product P @@ -6705,16 +6705,16 @@ BEGIN t_P.description, P.has_variations, P.id_category, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - t_P.count_recurrence_interval, + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + t_P.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, t_P.display_order_permutation, @@ -6724,8 +6724,8 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - LEFT JOIN Shop_Recurrence_Interval RI - ON t_P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI + ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval ORDER BY t_P.rank_permutation ; @@ -7206,13 +7206,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency diff --git a/static/MySQL/deprecated/dump2.sql b/static/MySQL/deprecated/dump2.sql index 450d859c..3fb5cd83 100644 --- a/static/MySQL/deprecated/dump2.sql +++ b/static/MySQL/deprecated/dump2.sql @@ -1964,11 +1964,11 @@ DELIMITER ;;; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -2038,13 +2038,13 @@ DELIMITER ;;; SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_access_level_required SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set @@ -2674,14 +2674,14 @@ CREATE TABLE `shop_product_permutation` ( `id_currency_cost_manufacturing` int NOT NULL, `profit_local_min` float NOT NULL, `id_currency_profit_min` int NOT NULL, - `latency_manufacture` int NOT NULL, + `latency_manufacture_days` int NOT NULL, `quantity_min` float NOT NULL, `quantity_max` float NOT NULL, `quantity_step` float NOT NULL, `quantity_stock` float NOT NULL, `is_subscription` bit(1) NOT NULL, - `id_recurrence_interval` int DEFAULT NULL, - `count_recurrence_interval` int DEFAULT NULL, + `id_unit_measurement_interval_recurrence` int DEFAULT NULL, + `count_interval_recurrence` int DEFAULT NULL, `id_access_level_required` int NOT NULL, `id_stripe_product` varchar(100) DEFAULT NULL, `active` bit(1) NOT NULL DEFAULT b'1', @@ -2691,11 +2691,11 @@ CREATE TABLE `shop_product_permutation` ( `id_change_set` int DEFAULT NULL, PRIMARY KEY (`id_permutation`), KEY `FK_Shop_Product_Variation_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Permutation_id_recurrence_interval` (`id_recurrence_interval`), + KEY `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` (`id_unit_measurement_interval_recurrence`), KEY `FK_Shop_Product_Permutation_id_access_level_required` (`id_access_level_required`), KEY `FK_Shop_Product_Variation_Link_id_change_set` (`id_change_set`), CONSTRAINT `FK_Shop_Product_Permutation_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_Permutation_id_recurrence_interval` FOREIGN KEY (`id_recurrence_interval`) REFERENCES `shop_recurrence_interval` (`id_interval`), + CONSTRAINT `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` FOREIGN KEY (`id_unit_measurement_interval_recurrence`) REFERENCES `shop_interval_recurrence` (`id_interval`), CONSTRAINT `FK_Shop_Product_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), CONSTRAINT `FK_Shop_Product_Variation_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; @@ -2794,9 +2794,9 @@ DELIMITER ;;; WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - # Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + # Changed latency_manufacture_days + SELECT NEW.id_product, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days UNION # Changed quantity_min SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set @@ -2818,13 +2818,13 @@ DELIMITER ;;; SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - # Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + # Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - # Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + # Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION # Changed id_stripe_product SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set @@ -3012,13 +3012,13 @@ LOCK TABLES `shop_product_permutation_variation_link_audit` WRITE; UNLOCK TABLES; -- --- Table structure for table `shop_recurrence_interval` +-- Table structure for table `shop_interval_recurrence` -- -DROP TABLE IF EXISTS `shop_recurrence_interval`; +DROP TABLE IF EXISTS `shop_interval_recurrence`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_recurrence_interval` ( +CREATE TABLE `shop_interval_recurrence` ( `id_interval` int NOT NULL AUTO_INCREMENT, `code` varchar(50) DEFAULT NULL, `name` varchar(255) DEFAULT NULL, @@ -3028,19 +3028,19 @@ CREATE TABLE `shop_recurrence_interval` ( `created_by` varchar(100) DEFAULT NULL, `id_change_set` int DEFAULT NULL, PRIMARY KEY (`id_interval`), - KEY `FK_Shop_Recurrence_Interval_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) + KEY `FK_Shop_Interval_Recurrence_id_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Dumping data for table `shop_recurrence_interval` +-- Dumping data for table `shop_interval_recurrence` -- -LOCK TABLES `shop_recurrence_interval` WRITE; -/*!40000 ALTER TABLE `shop_recurrence_interval` DISABLE KEYS */; -INSERT INTO `shop_recurrence_interval` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_recurrence_interval` ENABLE KEYS */; +LOCK TABLES `shop_interval_recurrence` WRITE; +/*!40000 ALTER TABLE `shop_interval_recurrence` DISABLE KEYS */; +INSERT INTO `shop_interval_recurrence` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); +/*!40000 ALTER TABLE `shop_interval_recurrence` ENABLE KEYS */; UNLOCK TABLES; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3051,7 +3051,7 @@ UNLOCK TABLES; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Recurrence_Interval` BEFORE INSERT ON `shop_recurrence_interval` FOR EACH ROW BEGIN +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Interval_Recurrence` BEFORE INSERT ON `shop_interval_recurrence` FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END */;; @@ -3069,13 +3069,13 @@ DELIMITER ;; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Recurrence_Interval` BEFORE UPDATE ON `shop_recurrence_interval` FOR EACH ROW BEGIN +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Interval_Recurrence` BEFORE UPDATE ON `shop_interval_recurrence` FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, @@ -3106,13 +3106,13 @@ DELIMITER ;; /*!50003 SET collation_connection = @saved_col_connection */ ; -- --- Table structure for table `shop_recurrence_interval_audit` +-- Table structure for table `shop_interval_recurrence_audit` -- -DROP TABLE IF EXISTS `shop_recurrence_interval_audit`; +DROP TABLE IF EXISTS `shop_interval_recurrence_audit`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_recurrence_interval_audit` ( +CREATE TABLE `shop_interval_recurrence_audit` ( `id_audit` int NOT NULL AUTO_INCREMENT, `id_interval` int NOT NULL, `name_field` varchar(50) DEFAULT NULL, @@ -3120,20 +3120,20 @@ CREATE TABLE `shop_recurrence_interval_audit` ( `value_new` varchar(256) DEFAULT NULL, `id_change_set` int NOT NULL, PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Recurrence_Interval_Audit_id_interval` (`id_interval`), - KEY `FK_Shop_Recurrence_Interval_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Recurrence_Interval_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_recurrence_interval` (`id_interval`) ON UPDATE RESTRICT + KEY `FK_Shop_Interval_Recurrence_Audit_id_interval` (`id_interval`), + KEY `FK_Shop_Interval_Recurrence_Audit_id_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), + CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_interval_recurrence` (`id_interval`) ON UPDATE RESTRICT ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Dumping data for table `shop_recurrence_interval_audit` +-- Dumping data for table `shop_interval_recurrence_audit` -- -LOCK TABLES `shop_recurrence_interval_audit` WRITE; -/*!40000 ALTER TABLE `shop_recurrence_interval_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_recurrence_interval_audit` ENABLE KEYS */; +LOCK TABLES `shop_interval_recurrence_audit` WRITE; +/*!40000 ALTER TABLE `shop_interval_recurrence_audit` DISABLE KEYS */; +/*!40000 ALTER TABLE `shop_interval_recurrence_audit` ENABLE KEYS */; UNLOCK TABLES; -- @@ -6110,17 +6110,17 @@ BEGIN price_GBP_full FLOAT NOT NULL, price_GBP_min FLOAT NOT NULL, */ - latency_manufacture INT NOT NULL, + latency_manufacture_days INT NOT NULL, quantity_min FLOAT NOT NULL, quantity_max FLOAT NOT NULL, quantity_step FLOAT NOT NULL, quantity_stock FLOAT NOT NULL, is_subscription BIT NOT NULL, - id_recurrence_interval INT, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INT, + id_unit_measurement_interval_recurrence INT, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INT, id_stripe_product VARCHAR(100), product_has_variations INT NOT NULL, can_view BIT, @@ -6224,14 +6224,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations ) @@ -6254,14 +6254,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations FROM Shop_Product P @@ -6705,16 +6705,16 @@ BEGIN t_P.description, P.has_variations, P.id_category, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - t_P.count_recurrence_interval, + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + t_P.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, t_P.display_order_permutation, @@ -6724,8 +6724,8 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - LEFT JOIN Shop_Recurrence_Interval RI - ON t_P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI + ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval ORDER BY t_P.rank_permutation ; @@ -7206,13 +7206,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency diff --git a/static/MySQL/temp.txt b/static/MySQL/temp.txt index cc5d1c8a..0e9a6c2c 100644 --- a/static/MySQL/temp.txt +++ b/static/MySQL/temp.txt @@ -153,16 +153,19 @@ 3427_tri_Shop_Customer_Sales_Order_Product_Link.sql 6000_p_split.sql 6001_p_clear_split_temp.sql +6206_fn_shop_get_product_permutation_name.sql 6500_p_shop_user_eval.sql 6501_p_clear_shop_user_eval_temp.sql +7003_p_shop_get_many_access_level.sql 7101_p_shop_get_many_region.sql 7116_p_shop_get_many_currency.sql +7122_p_shop_get_many_unit_measurement.sql 7200_p_shop_save_product_category.sql 7200_p_shop_save_product_category_test.sql 7203_p_shop_save_product.sql 7204_p_shop_get_many_product.sql 7205_p_shop_get_many_stripe_product_new.sql -7206_p_shop_save_permutation.sql +7206_p_shop_save_product_permutation.sql 7210_p_shop_get_many_product_variation.sql 7219_p_shop_get_many_stock_item.sql 7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql diff --git a/static/PostgreSQL/000_combine.sql b/static/PostgreSQL/000_combine.sql index 43cd95ef..98cb65d4 100644 --- a/static/PostgreSQL/000_combine.sql +++ b/static/PostgreSQL/000_combine.sql @@ -157,8 +157,8 @@ DROP TABLE IF EXISTS Shop_Delivery_Region; DROP TABLE IF EXISTS Shop_Region_Audit; DROP TABLE IF EXISTS Shop_Region; -DROP TABLE IF EXISTS Shop_Recurrence_Interval_Audit; -DROP TABLE IF EXISTS Shop_Recurrence_Interval; +DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; +DROP TABLE IF EXISTS Shop_Interval_Recurrence; DROP TABLE IF EXISTS Shop_Product_Category_Audit; DROP TABLE IF EXISTS Shop_Product_Category; @@ -503,9 +503,9 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( id_interval INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, code VARCHAR(50), name VARCHAR(255), @@ -514,7 +514,7 @@ CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( created_on TIMESTAMP, created_by INT, id_change_set INTEGER, - CONSTRAINT FK_Shop_Recurrence_Interval_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); @@ -523,20 +523,20 @@ CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval_Audit'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval_Audit ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, id_interval INTEGER NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_interval + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval FOREIGN KEY (id_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) + REFERENCES Shop_Interval_Recurrence(id_interval) ON UPDATE RESTRICT, name_field VARCHAR(50), value_prev VARCHAR(256), value_new VARCHAR(256), id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); @@ -760,11 +760,11 @@ CREATE TABLE IF NOT EXISTS Shop_Product ( quantity_step REAL, quantity_stock REAL, is_subscription BOOLEAN, - id_recurrence_interval INTEGER, - CONSTRAINT FK_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, */ id_access_level_required INTEGER NOT NULL, CONSTRAINT FK_Shop_Product_id_access_level_required @@ -911,17 +911,17 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( id_currency_cost INTEGER NOT NULL, profit_local_min REAL NOT NULL, -- id_currency_profit_min INTEGER NOT NULL, - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, /* id_access_level_required INTEGER NOT NULL, CONSTRAINT FK_Shop_Product_Permutation_id_access_level_required @@ -2814,7 +2814,7 @@ EXECUTE FUNCTION before_update_Shop_Product_Category(); -- Shop Recurrence Interval -CREATE OR REPLACE FUNCTION before_insert_Shop_Recurrence_Interval() +CREATE OR REPLACE FUNCTION before_insert_Shop_Interval_Recurrence() RETURNS TRIGGER AS $$ BEGIN NEW.created_on = CURRENT_TIMESTAMP; @@ -2824,13 +2824,13 @@ BEGIN END; $$ LANGUAGE plpgsql; -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Recurrence_Interval -BEFORE INSERT ON Shop_Recurrence_Interval +CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Interval_Recurrence +BEFORE INSERT ON Shop_Interval_Recurrence FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Recurrence_Interval(); +EXECUTE FUNCTION before_insert_Shop_Interval_Recurrence(); -CREATE OR REPLACE FUNCTION before_update_Shop_Recurrence_Interval() +CREATE OR REPLACE FUNCTION before_update_Shop_Interval_Recurrence() RETURNS TRIGGER AS $$ BEGIN IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN @@ -2838,7 +2838,7 @@ BEGIN USING ERRCODE = '45000'; END IF; - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, @@ -2866,10 +2866,10 @@ BEGIN END; $$ LANGUAGE plpgsql; -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Recurrence_Interval -BEFORE UPDATE ON Shop_Recurrence_Interval +CREATE OR REPLACE TRIGGER tri_before_update_Shop_Interval_Recurrence +BEFORE UPDATE ON Shop_Interval_Recurrence FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Recurrence_Interval(); +EXECUTE FUNCTION before_update_Shop_Interval_Recurrence(); -- Shop Delivery Region @@ -3197,11 +3197,11 @@ BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -3271,13 +3271,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - -- Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + -- Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - -- Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + -- Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION -- Changed id_stripe_product SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set @@ -3512,9 +3512,9 @@ BEGIN WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + -- Changed latency_manufacture_days + SELECT NEW.id_product, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days UNION -- Changed quantity_min SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set @@ -3536,13 +3536,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - -- Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + -- Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - -- Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + -- Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION -- Changed id_stripe_product SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set @@ -9749,19 +9749,19 @@ BEGIN price_GBP_full REAL NOT NULL, price_GBP_min REAL NOT NULL, */ - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, /* - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), */ - count_recurrence_interval INTEGER, + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations BOOLEAN NOT NULL, can_view BOOLEAN, @@ -9872,14 +9872,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations ) @@ -9905,14 +9905,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations FROM Shop_Product P @@ -10412,16 +10412,16 @@ BEGIN PP.cost_local, PP.id_currency_cost, PP.profit_local_min, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - t_P.count_recurrence_interval, + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + t_P.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, t_P.display_order_permutation, @@ -10431,7 +10431,7 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval ORDER BY t_P.rank_permutation ; RETURN NEXT result_products; @@ -11663,13 +11663,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency @@ -12162,17 +12162,17 @@ BEGIN price_GBP_full REAL NOT NULL, price_GBP_min REAL NOT NULL, */ - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, can_view BOOLEAN, @@ -12318,14 +12318,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -12350,14 +12350,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -12849,17 +12849,17 @@ BEGIN price_GBP_min REAL NOT NULL, */ /* - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, */ @@ -12953,14 +12953,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -12985,14 +12985,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -13731,17 +13731,17 @@ BEGIN price_GBP_min REAL NOT NULL, */ /* - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, */ @@ -13887,14 +13887,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -13919,14 +13919,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ @@ -14345,7 +14345,7 @@ VALUES ; -- Recurrence Interval -INSERT INTO Shop_Recurrence_Interval ( +INSERT INTO Shop_Interval_Recurrence ( code, name, name_plural ) VALUES @@ -14468,14 +14468,14 @@ INSERT INTO Shop_Product_Permutation ( id_currency_cost, profit_local_min, -- id_currency_profit_min, - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, -- id_access_level_required, id_stripe_product ) @@ -14956,8 +14956,8 @@ SELECT * FROM Shop_Product_Category; SELECT * FROM Shop_Product_Category_Audit; -- Recurrence Interval -SELECT * FROM Shop_Recurrence_Interval; -SELECT * FROM Shop_Recurrence_Interval_Audit; +SELECT * FROM Shop_Interval_Recurrence; +SELECT * FROM Shop_Interval_Recurrence_Audit; -- Region SELECT * FROM Shop_Region; diff --git a/static/PostgreSQL/001_destroy.sql b/static/PostgreSQL/001_destroy.sql index 74c16589..060a3a4f 100644 --- a/static/PostgreSQL/001_destroy.sql +++ b/static/PostgreSQL/001_destroy.sql @@ -157,8 +157,8 @@ DROP TABLE IF EXISTS Shop_Delivery_Region; DROP TABLE IF EXISTS Shop_Region_Audit; DROP TABLE IF EXISTS Shop_Region; -DROP TABLE IF EXISTS Shop_Recurrence_Interval_Audit; -DROP TABLE IF EXISTS Shop_Recurrence_Interval; +DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; +DROP TABLE IF EXISTS Shop_Interval_Recurrence; DROP TABLE IF EXISTS Shop_Product_Category_Audit; DROP TABLE IF EXISTS Shop_Product_Category; diff --git a/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql b/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql index 95d974ca..4075a57e 100644 --- a/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql +++ b/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql @@ -3,9 +3,9 @@ -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( id_interval INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, code VARCHAR(50), name VARCHAR(255), @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval ( created_on TIMESTAMP, created_by INT, id_change_set INTEGER, - CONSTRAINT FK_Shop_Recurrence_Interval_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); diff --git a/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql b/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql index d3192fc6..8ca9184b 100644 --- a/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql +++ b/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql @@ -3,20 +3,20 @@ -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Recurrence_Interval_Audit'; +SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; -CREATE TABLE IF NOT EXISTS Shop_Recurrence_Interval_Audit ( +CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, id_interval INTEGER NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_interval + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval FOREIGN KEY (id_interval) - REFERENCES Shop_Recurrence_Interval(id_interval) + REFERENCES Shop_Interval_Recurrence(id_interval) ON UPDATE RESTRICT, name_field VARCHAR(50), value_prev VARCHAR(256), value_new VARCHAR(256), id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Recurrence_Interval_Audit_id_change_set + CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set FOREIGN KEY (id_change_set) REFERENCES Shop_Product_Change_Set(id_change_set) ); diff --git a/static/PostgreSQL/110.8_tbl_Shop_Product.sql b/static/PostgreSQL/110.8_tbl_Shop_Product.sql index 67e3019d..ed44d554 100644 --- a/static/PostgreSQL/110.8_tbl_Shop_Product.sql +++ b/static/PostgreSQL/110.8_tbl_Shop_Product.sql @@ -25,11 +25,11 @@ CREATE TABLE IF NOT EXISTS Shop_Product ( quantity_step REAL, quantity_stock REAL, is_subscription BOOLEAN, - id_recurrence_interval INTEGER, - CONSTRAINT FK_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, */ id_access_level_required INTEGER NOT NULL, CONSTRAINT FK_Shop_Product_id_access_level_required diff --git a/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql b/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql index c64cd4f4..9b60cf1e 100644 --- a/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql +++ b/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql @@ -18,17 +18,17 @@ CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( id_currency_cost INTEGER NOT NULL, profit_local_min REAL NOT NULL, -- id_currency_profit_min INTEGER NOT NULL, - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, /* id_access_level_required INTEGER NOT NULL, CONSTRAINT FK_Shop_Product_Permutation_id_access_level_required diff --git a/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql b/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql index 127b00e3..0a82210f 100644 --- a/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql +++ b/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql @@ -1,7 +1,7 @@ -- Shop Recurrence Interval -CREATE OR REPLACE FUNCTION before_insert_Shop_Recurrence_Interval() +CREATE OR REPLACE FUNCTION before_insert_Shop_Interval_Recurrence() RETURNS TRIGGER AS $$ BEGIN NEW.created_on = CURRENT_TIMESTAMP; @@ -11,13 +11,13 @@ BEGIN END; $$ LANGUAGE plpgsql; -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Recurrence_Interval -BEFORE INSERT ON Shop_Recurrence_Interval +CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Interval_Recurrence +BEFORE INSERT ON Shop_Interval_Recurrence FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Recurrence_Interval(); +EXECUTE FUNCTION before_insert_Shop_Interval_Recurrence(); -CREATE OR REPLACE FUNCTION before_update_Shop_Recurrence_Interval() +CREATE OR REPLACE FUNCTION before_update_Shop_Interval_Recurrence() RETURNS TRIGGER AS $$ BEGIN IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN @@ -25,7 +25,7 @@ BEGIN USING ERRCODE = '45000'; END IF; - INSERT INTO Shop_Recurrence_Interval_Audit ( + INSERT INTO Shop_Interval_Recurrence_Audit ( id_interval, name_field, value_prev, @@ -53,7 +53,7 @@ BEGIN END; $$ LANGUAGE plpgsql; -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Recurrence_Interval -BEFORE UPDATE ON Shop_Recurrence_Interval +CREATE OR REPLACE TRIGGER tri_before_update_Shop_Interval_Recurrence +BEFORE UPDATE ON Shop_Interval_Recurrence FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Recurrence_Interval(); +EXECUTE FUNCTION before_update_Shop_Interval_Recurrence(); diff --git a/static/PostgreSQL/310.8_tri_Shop_Product.sql b/static/PostgreSQL/310.8_tri_Shop_Product.sql index 6a4c797f..4f25d19a 100644 --- a/static/PostgreSQL/310.8_tri_Shop_Product.sql +++ b/static/PostgreSQL/310.8_tri_Shop_Product.sql @@ -58,11 +58,11 @@ BEGIN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; END IF; - IF ISNULL(NEW.id_recurrence_interval) THEN + IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; END IF; - IF ISNULL(NEW.count_recurrence_interval) THEN + IF ISNULL(NEW.count_interval_recurrence) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; END IF; @@ -132,13 +132,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - -- Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + -- Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - -- Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + -- Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION -- Changed id_stripe_product SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set diff --git a/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql b/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql index cc511b34..78abd0aa 100644 --- a/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql +++ b/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql @@ -78,9 +78,9 @@ BEGIN WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) UNION */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture + -- Changed latency_manufacture_days + SELECT NEW.id_product, 'latency_manufacture_days', CONVERT(OLD.latency_manufacture_days, CHAR), CONVERT(NEW.latency_manufacture_days, CHAR), NEW.id_change_set + WHERE NOT OLD.latency_manufacture_days <=> NEW.latency_manufacture_days UNION -- Changed quantity_min SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set @@ -102,13 +102,13 @@ BEGIN SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set WHERE NOT OLD.is_subscription <=> NEW.is_subscription UNION - -- Changed id_recurrence_interval - SELECT NEW.id_product, 'id_recurrence_interval', CONVERT(OLD.id_recurrence_interval, CHAR), CONVERT(NEW.id_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.id_recurrence_interval <=> NEW.id_recurrence_interval + -- Changed id_unit_measurement_interval_recurrence + SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence UNION - -- Changed count_recurrence_interval - SELECT NEW.id_product, 'count_recurrence_interval', CONVERT(OLD.count_recurrence_interval, CHAR), CONVERT(NEW.count_recurrence_interval, CHAR), NEW.id_change_set - WHERE NOT OLD.count_recurrence_interval <=> NEW.count_recurrence_interval + -- Changed count_interval_recurrence + SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set + WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence UNION -- Changed id_stripe_product SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set diff --git a/static/PostgreSQL/600_p_shop_save_product.sql b/static/PostgreSQL/600_p_shop_save_product.sql index 659f298a..de30cd13 100644 --- a/static/PostgreSQL/600_p_shop_save_product.sql +++ b/static/PostgreSQL/600_p_shop_save_product.sql @@ -211,17 +211,17 @@ BEGIN P.id_stripe_product, P.id_stripe_price, P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - P.count_recurrence_interval, + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + P.count_interval_recurrence, tP.can_view, tP.can_edit, tP.can_admin FROM tmp_Shop_Product tP INNER JOIN Shop_Product P ON tP.id_product = P.id_product - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval ; -- Variations diff --git a/static/PostgreSQL/700_p_shop_get_many_product.sql b/static/PostgreSQL/700_p_shop_get_many_product.sql index 0ba000d9..bd9c39cf 100644 --- a/static/PostgreSQL/700_p_shop_get_many_product.sql +++ b/static/PostgreSQL/700_p_shop_get_many_product.sql @@ -203,19 +203,19 @@ BEGIN price_GBP_full REAL NOT NULL, price_GBP_min REAL NOT NULL, */ - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, /* - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), */ - count_recurrence_interval INTEGER, + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations BOOLEAN NOT NULL, can_view BOOLEAN, @@ -326,14 +326,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations ) @@ -359,14 +359,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations FROM Shop_Product P @@ -866,16 +866,16 @@ BEGIN PP.cost_local, PP.id_currency_cost, PP.profit_local_min, - t_P.latency_manufacture, + t_P.latency_manufacture_days, t_P.quantity_min, t_P.quantity_max, t_P.quantity_step, t_P.quantity_stock, t_P.id_stripe_product, t_P.is_subscription, - RI.name AS name_recurrence_interval, - RI.name_plural AS name_plural_recurrence_interval, - t_P.count_recurrence_interval, + RI.name AS name_interval_recurrence, + RI.name_plural AS name_plural_interval_recurrence, + t_P.count_interval_recurrence, t_P.display_order_category, t_P.display_order_product, t_P.display_order_permutation, @@ -885,7 +885,7 @@ BEGIN FROM tmp_Shop_Product t_P INNER JOIN Shop_Product P ON t_P.id_product = P.id_product INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_recurrence_interval = RI.id_interval + LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval ORDER BY t_P.rank_permutation ; RETURN NEXT result_products; diff --git a/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql b/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql index eedb5102..fff041f4 100644 --- a/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql +++ b/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql @@ -170,13 +170,13 @@ BEGIN P.id_stripe_product, P.is_subscription, LOWER(RI.code) AS name_recurring_interval, - P.count_recurrence_interval + P.count_interval_recurrence FROM tmp_Shop_Product_Currency_Link t_PCL INNER JOIN Shop_Product P ON t_PCL.id_product = P.id_product AND P.active - INNER JOIN Shop_Recurrence_Interval RI - ON P.id_recurrence_interval = RI.id_interval + INNER JOIN Shop_Interval_Recurrence RI + ON P.id_unit_measurement_interval_recurrence = RI.id_interval AND RI.active INNER JOIN Shop_Currency C ON t_PCL.id_currency = C.id_currency diff --git a/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql b/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql index 3de58a84..f29b480d 100644 --- a/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql +++ b/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql @@ -169,17 +169,17 @@ BEGIN price_GBP_full REAL NOT NULL, price_GBP_min REAL NOT NULL, */ - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, can_view BOOLEAN, @@ -325,14 +325,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -357,14 +357,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql b/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql index e88881f8..29c50208 100644 --- a/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql +++ b/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql @@ -147,17 +147,17 @@ BEGIN price_GBP_min REAL NOT NULL, */ /* - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, */ @@ -251,14 +251,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -283,14 +283,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql b/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql index 140f1e1c..89e21735 100644 --- a/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql +++ b/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql @@ -179,17 +179,17 @@ BEGIN price_GBP_min REAL NOT NULL, */ /* - latency_manufacture INTEGER NOT NULL, + latency_manufacture_days INTEGER NOT NULL, quantity_min REAL NOT NULL, quantity_max REAL NOT NULL, quantity_step REAL NOT NULL, quantity_stock REAL NOT NULL, is_subscription BOOLEAN NOT NULL, - id_recurrence_interval INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_recurrence_interval - FOREIGN KEY (id_recurrence_interval) - REFERENCES Shop_Recurrence_Interval(id_interval), - count_recurrence_interval INTEGER, + id_unit_measurement_interval_recurrence INTEGER, + CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence + FOREIGN KEY (id_unit_measurement_interval_recurrence) + REFERENCES Shop_Interval_Recurrence(id_interval), + count_interval_recurrence INTEGER, id_stripe_product VARCHAR(100), product_has_variations INTEGER NOT NULL, */ @@ -335,14 +335,14 @@ BEGIN price_GBP_VAT_excl, price_GBP_min, */ - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, id_stripe_product, product_has_variations */ @@ -367,14 +367,14 @@ BEGIN PP.price_GBP_VAT_excl, PP.price_GBP_min, */ - PP.latency_manufacture, + PP.latency_manufacture_days, PP.quantity_min, PP.quantity_max, PP.quantity_step, PP.quantity_stock, PP.is_subscription, - PP.id_recurrence_interval, - PP.count_recurrence_interval, + PP.id_unit_measurement_interval_recurrence, + PP.count_interval_recurrence, PP.id_stripe_product, P.has_variations */ diff --git a/static/PostgreSQL/900_populate.sql b/static/PostgreSQL/900_populate.sql index 18b7cdd5..d283d4ec 100644 --- a/static/PostgreSQL/900_populate.sql +++ b/static/PostgreSQL/900_populate.sql @@ -75,7 +75,7 @@ VALUES ; -- Recurrence Interval -INSERT INTO Shop_Recurrence_Interval ( +INSERT INTO Shop_Interval_Recurrence ( code, name, name_plural ) VALUES @@ -198,14 +198,14 @@ INSERT INTO Shop_Product_Permutation ( id_currency_cost, profit_local_min, -- id_currency_profit_min, - latency_manufacture, + latency_manufacture_days, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, - id_recurrence_interval, - count_recurrence_interval, + id_unit_measurement_interval_recurrence, + count_interval_recurrence, -- id_access_level_required, id_stripe_product ) diff --git a/static/PostgreSQL/901_view.sql b/static/PostgreSQL/901_view.sql index bccf70d5..68af54f2 100644 --- a/static/PostgreSQL/901_view.sql +++ b/static/PostgreSQL/901_view.sql @@ -31,8 +31,8 @@ SELECT * FROM Shop_Product_Category; SELECT * FROM Shop_Product_Category_Audit; -- Recurrence Interval -SELECT * FROM Shop_Recurrence_Interval; -SELECT * FROM Shop_Recurrence_Interval_Audit; +SELECT * FROM Shop_Interval_Recurrence; +SELECT * FROM Shop_Interval_Recurrence_Audit; -- Region SELECT * FROM Shop_Region; diff --git a/static/PostgreSQL/temp.txt b/static/PostgreSQL/temp.txt index be9b6d25..3a4d329e 100644 --- a/static/PostgreSQL/temp.txt +++ b/static/PostgreSQL/temp.txt @@ -11,8 +11,8 @@ 105_tbl_Shop_General_Audit.sql 106_tbl_Shop_Product_Category.sql 107_tbl_Shop_Product_Category_Audit.sql -108_tbl_Shop_Recurrence_Interval.sql -109_tbl_Shop_Recurrence_Interval_Audit.sql +108_tbl_Shop_Interval_Recurrence.sql +109_tbl_Shop_Interval_Recurrence_Audit.sql 110.0_tbl_Shop_Region.sql 110.1_tbl_Shop_Region_Audit.sql 110.2_tbl_Shop_Region_Branch.sql @@ -94,7 +94,7 @@ 303_tri_File_Type_Audit.sql 304_tri_Shop_General.sql 306_tri_Shop_Product_Category.sql -308_tri_Shop_Recurrence_Interval.sql +308_tri_Shop_Interval_Recurrence.sql 310.0_tri_Shop_Region.sql 310.2_tri_Shop_Region_Branch.sql 310.4_tri_Shop_Currency.sql diff --git a/static/css/components/table.css b/static/css/components/table.css new file mode 100644 index 00000000..89830f09 --- /dev/null +++ b/static/css/components/table.css @@ -0,0 +1,35 @@ + +thead, tbody { + padding-top: 0px !important; + padding-bottom: 0px !important; +} + +th { + +} +td { + font-size: min(12px, calc(1vh * 3)); +} + +th, td { + min-width: fit-content; +} +tr:not(:last-child) > td { + border-bottom: 1px dashed var(--c_purple_dark); +} +td > table > tbody > tr > td { + border: none !important; +} +tr { + min-height: 1px; + border-bottom: 1px solid var(--c_purple_dark); + border-top: 1px solid var(--c_purple_dark); + padding-bottom: 1vh; + background-color: transparent; +} + +/* +.row-new { + visibility: hidden; +} +*/ diff --git a/static/css/layouts/header.css b/static/css/layouts/header.css index e69de29b..fe4e207a 100644 --- a/static/css/layouts/header.css +++ b/static/css/layouts/header.css @@ -0,0 +1,15 @@ + + +button.collapsed { + display: block; + opacity: 0; +} + +form.filter button.save, form.filter button.button-cancel { + margin-top: 0; + margin-bottom: 0; +} +form.filter button.save, form.filter button.button-cancel { + margin-top: 0; + margin-bottom: 0; +} \ No newline at end of file diff --git a/static/css/layouts/table-main.css b/static/css/layouts/table-main.css new file mode 100644 index 00000000..dfc49c54 --- /dev/null +++ b/static/css/layouts/table-main.css @@ -0,0 +1,15 @@ +#tableMain { + overflow-x: auto; + padding: 1vh 2vh; + max-width: min(calc(1vh * 80), calc(1vw * 90)); + width: fit-content; + margin: 1vh 2vh; + align-items: normal; + justify-content: normal; +} + +#tableMain thead tr th, #tableMain tbody tr td { + width: 20vh; + min-width: 20vh; + padding: 0 0.5vh; +} \ No newline at end of file diff --git a/static/css/main.css b/static/css/main.css index 2cc9dcd2..83a8064e 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,5 +1,5 @@ -/* + /* Base styles * @import 'lib/reset.css'; @import 'lib/typography.css'; @@ -9,6 +9,7 @@ /* Layout styles * @import 'layouts/header.css'; @import 'layouts/footer.css'; +@import 'layouts/table-main.css'; /* Component styles * @import 'components/button.css'; @@ -21,6 +22,7 @@ /* Section styles * @import 'sections/store.css'; +*/ /* Page-specific styles * @import 'pages/page_admin.css'; @@ -31,15 +33,14 @@ @import 'pages/page_store_home.css'; @import 'pages/page_store_product_permutations.css'; @import 'pages/page_store_stock_items.css'; -* +*/ /* Theme styles * @import 'themes/light.css'; -/* Uncomment the line below to enable dark theme * -/* @import 'themes/dark.css'; * +/* Uncomment the line below to enable dark theme */ +/* @import 'themes/dark.css'; */ -*/ /* Custom styles */ /* Add any custom styles or overrides here */ @@ -234,10 +235,9 @@ h5 { text-align: center; width: 100%; align-self: center; - font-size: min(20px, calc(1vh * 6)); + font-size: min(16px, calc(1vh * 4)); } #pageBody > * > * { - width: 100%; align-self: center; padding-top: 1vh; padding-bottom: 1vh; @@ -374,6 +374,7 @@ img.header-logo { display: flex; flex-direction: column; align-items: center; + margin: auto 0; } .row { @@ -521,10 +522,10 @@ button:hover, input[type="submit"]:hover, #overlayHamburger .row *:hover { z-index: 999; } .overlay.expanded { - display: block !important; + display: block; } .collapsed { - display: none !important; + display: none; } #overlayHamburger { @@ -593,39 +594,5 @@ td.dirty { /* Tables */ #pageBody > *, button { - font-size: min(14px, calc(1vh * 5)) !important; -} -thead, tbody { - padding-top: 0px !important; - padding-bottom: 0px !important; -} - -th { - -} -td { - font-size: min(14px, calc(1vh * 5)); -} - -th, td { - min-width: fit-content; -} -tr:not(:last-child) > td { - border-bottom: 1px dashed var(--c_purple_dark); -} -td > table > tbody > tr > td { - border: none !important; -} -tr { - min-height: 1px; - border-bottom: 1px solid var(--c_purple_dark); - border-top: 1px solid var(--c_purple_dark); - padding-bottom: 1vh; - background-color: transparent; -} - -/* -.row-new { - visibility: hidden; -} -*/ + font-size: min(12px, calc(1vh * 3)); +} \ No newline at end of file diff --git a/static/css/pages/core/home.css b/static/css/pages/core/home.css index 1a67abe6..642e9327 100644 --- a/static/css/pages/core/home.css +++ b/static/css/pages/core/home.css @@ -1,4 +1,7 @@ +#pageBody > * > * { + width: 100%; +} #pageBody > * { height: 100%; } diff --git a/static/css/pages/store/product_categories.css b/static/css/pages/store/product_categories.css index 5872ca5b..6d2d635e 100644 --- a/static/css/pages/store/product_categories.css +++ b/static/css/pages/store/product_categories.css @@ -1,23 +1,58 @@ +#formFilters { + width: 50vh; +} -td.display-order, th.display-order { - width: 8% !important; +#formFilters .container { + max-width: fit-content; } -td.code, th.code { - width: 15% !important; + +#formFilters .container-input.filter.is_not_empty { + width: 10vh; +} + +#formFilters .container-input.filter.active { + width: 8vh; } -td.name, th.name { - width: 25% !important; + +#tableMain { + max-width: min(calc(1vh * 79), calc(1vw * 90)); } -td.description, th.description { - width: 35% !important; + +/* +#tableMain thead tr th, #tableMain tbody tr td { + margin-left: 1vh; + margin-right: 1vh; } -td.access_level, th.access_level { - width: 10% !important; +*/ + +#tableMain tbody tr td.display_order, #tableMain thead tr th.display_order { + width: 5vh; + min-width: 5vh; } -td.active, th.active { - width: 7% !important; +#tableMain tbody tr td.code, #tableMain thead tr th.code { + width: 10vh; + min-width: 10vh; } +#tableMain tbody tr td.name, #tableMain thead tr th.name { + width: 15vh; + min-width: 15vh; +} +#tableMain tbody tr td.description, #tableMain thead tr th.description { + width: 25vh; + min-width: 25vh; +} +#tableMain tbody tr td.access_level, #tableMain thead tr th.access_level { + width: 7vh; + min-width: 7vh; +} +#tableMain tbody tr td.active, #tableMain thead tr th.active { + width: 5vh; + min-width: 5vh; +} +/* +nips +*/ /* .row-new { @@ -26,15 +61,15 @@ td.active, th.active { */ textarea { - width: 95% !important; + width: 95%; } select { - width: 100% !important; + width: 100%; } input { - width: 90% !important; + width: 90%; } td > input, td > select, td > textarea, .container-input > input, .container-input > select, .container-input > textarea { diff --git a/static/css/pages/store/product_permutations.css b/static/css/pages/store/product_permutations.css index d7ef8140..8a5e45a4 100644 --- a/static/css/pages/store/product_permutations.css +++ b/static/css/pages/store/product_permutations.css @@ -1,28 +1,110 @@ +#formFilters { + width: 50vh; +} + +#formFilters .container { + max-width: fit-content; +} + -td.category, th.category { - width: 16% !important; +#tableMain { + max-width: 90vw; } -td.product, th.product { - width: 23% !important; +#tableMain thead tr th.category, #tableMain tbody tr td.category { + width: 8vh; + min-width: 8vh; } -td.variations, th.variations { - width: 19% !important; +#tableMain thead tr th.product, #tableMain tbody tr td.product { + width: 10vh; + min-width: 10vh; } -td.quantity-stock, th.quantity-stock { - width: 10% !important; +#tableMain thead tr th.product_variations.collapsed, #tableMain tbody tr td.product_variations.collapsed { + width: 10vh; + min-width: 10vh; + display: table-cell !important; } -td.quantity-min, th.quantity-min { - width: 10% !important; +#tableMain thead tr th.product_variations, #tableMain tbody tr td.product_variations { + width: 20vh; + min-width: 20vh; } -td.quantity-max, th.quantity-max { - width: 10% !important; +#tableMain tbody tr td.product_variations table thead tr th, #tableMain tbody tr td.product_variations table tbody tr td { + width: 8vh; + min-width: 8vh; } -td.cost-local-VAT-incl, th.cost-local-VAT-incl { - width: 6% !important; +#tableMain tbody tr td.product_variations table thead tr th:last-of-type, #tableMain tbody tr td.product_variations table tbody tr td:last-of-type { + width: 4vh; + min-width: 4vh; } -td.detail, th.detail { - width: 6% !important; +#tableMain thead tr th.description, #tableMain tbody tr td.description { +} +#tableMain thead tr th.quantity_stock, #tableMain tbody tr td.quantity_stock { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.quantity_min, #tableMain tbody tr td.quantity_min { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.quantity_max, #tableMain tbody tr td.quantity_max { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.count_unit_measurement_per_quantity_step, #tableMain tbody tr td.count_unit_measurement_per_quantity_step { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.id_unit_measurement_quantity, #tableMain tbody tr td.id_unit_measurement_quantity { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.is_subscription, #tableMain tbody tr td.is_subscription { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.count_interval_recurrence, #tableMain tbody tr td.count_interval_recurrence { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_unit_measurement_interval_recurrence, #tableMain tbody tr td.id_unit_measurement_interval_recurrence { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_stripe_product, #tableMain tbody tr td.id_stripe_product { + width: 10vh; + min-width: 10vh; +} +#tableMain thead tr th.does_expire_faster_once_unsealed, #tableMain tbody tr td.does_expire_faster_once_unsealed { + width: 7vh; + min-width: 7vh; +} +#tableMain thead tr th.count_interval_expiration_unsealed, #tableMain tbody tr td.count_interval_expiration_unsealed { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_unit_measurement_interval_expiration_unsealed, #tableMain tbody tr td.id_unit_measurement_interval_expiration_unsealed { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.cost_local, #tableMain tbody tr td.cost_local { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.id_currency_cost, #tableMain tbody tr td.id_currency_cost { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.profit_local_min, #tableMain tbody tr td.profit_local_min { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.latency_manufacture_days, #tableMain tbody tr td.latency_manufacture_days { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.active, #tableMain tbody tr td.active { + width: 6vh; + min-width: 6vh; } textarea { diff --git a/static/css/sections/store.css b/static/css/sections/store.css index 11a7d43d..2b9096a2 100644 --- a/static/css/sections/store.css +++ b/static/css/sections/store.css @@ -1,3 +1,4 @@ + .img-product { max-width: 20vh; max-height: 20vh; @@ -12,7 +13,7 @@ justify-self: left; } -.buttonAdd2Basket { +.buttonAddToBasket { background-color: var(--c_blue_pastel); color: var(--c_blue_dark); border-color: var(--c_blue_dark); diff --git a/static/dist/css/416.bundle.css b/static/dist/css/416.bundle.css new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/static/dist/css/416.bundle.css @@ -0,0 +1 @@ + diff --git a/static/dist/css/core_home.bundle.css b/static/dist/css/core_home.bundle.css index 281052e4..b80d8192 100644 --- a/static/dist/css/core_home.bundle.css +++ b/static/dist/css/core_home.bundle.css @@ -1,4 +1,7 @@ +#pageBody > * > * { + width: 100%; +} #pageBody > * { height: 100%; } diff --git a/static/dist/css/main.bundle.css b/static/dist/css/main.bundle.css index 7cebe8d8..c229ab4c 100644 --- a/static/dist/css/main.bundle.css +++ b/static/dist/css/main.bundle.css @@ -1,75 +1,5 @@ - - - - - - - - - - -#overlayConfirm { - position: absolute; - left: 25vw; - width: 50vw; - height: 50vh; -} -.img-product { - max-width: 20vh; - max-height: 20vh; - border-radius: 3vh; - justify-self: left; -} - -.img-thumbnail { - max-width: 10vh; - max-height: 10vh; - border-radius: 3vh; - justify-self: left; -} - -.buttonAdd2Basket { - background-color: var(--c_blue_pastel); - color: var(--c_blue_dark); - border-color: var(--c_blue_dark); -} - -#buttonCheckout, .buttonBuyNow { - background-color: var(--c_purple_pastel); - color: var(--c_purple_dark); - border-color: var(--c_purple_dark); -} - -.button-increment, .button-decrement { - border: 2px solid darkgrey; - background-color: lightgray; - margin: 1vh 1vh; - width: 2.5vh; - height: 2.5vh; - border-radius: 1.25vh; - font-size: 2vh; -} - -.container-input > input { - padding: 0vh 1vh; - border-radius: 0.5vh; - max-width: 7vh; -} - -#basket { - max-width: 100%; -} - - - -/* Right column */ -.rightcolumn { - min-width: fit-content; -} - -/* /* Base styles * @import 'lib/reset.css'; @import 'lib/typography.css'; @@ -79,6 +9,7 @@ /* Layout styles * @import 'layouts/header.css'; @import 'layouts/footer.css'; +@import 'layouts/table-main.css'; /* Component styles * @import 'components/button.css'; @@ -91,6 +22,7 @@ /* Section styles * @import 'sections/store.css'; +*/ /* Page-specific styles * @import 'pages/page_admin.css'; @@ -101,15 +33,14 @@ @import 'pages/page_store_home.css'; @import 'pages/page_store_product_permutations.css'; @import 'pages/page_store_stock_items.css'; -* +*/ /* Theme styles * @import 'themes/light.css'; -/* Uncomment the line below to enable dark theme * -/* @import 'themes/dark.css'; * +/* Uncomment the line below to enable dark theme */ +/* @import 'themes/dark.css'; */ -*/ /* Custom styles */ /* Add any custom styles or overrides here */ @@ -304,10 +235,9 @@ h5 { text-align: center; width: 100%; align-self: center; - font-size: min(20px, calc(1vh * 6)); + font-size: min(16px, calc(1vh * 4)); } #pageBody > * > * { - width: 100%; align-self: center; padding-top: 1vh; padding-bottom: 1vh; @@ -444,6 +374,7 @@ img.header-logo { display: flex; flex-direction: column; align-items: center; + margin: auto 0; } .row { @@ -591,10 +522,10 @@ button:hover, input[type="submit"]:hover, #overlayHamburger .row *:hover { z-index: 999; } .overlay.expanded { - display: block !important; + display: block; } .collapsed { - display: none !important; + display: none; } #overlayHamburger { @@ -663,8 +594,21 @@ td.dirty { /* Tables */ #pageBody > *, button { - font-size: min(14px, calc(1vh * 5)) !important; + font-size: min(12px, calc(1vh * 3)); } + + + + + + +#overlayConfirm { + position: absolute; + left: 25vw; + width: 50vw; + height: 50vh; +} + thead, tbody { padding-top: 0px !important; padding-bottom: 0px !important; @@ -674,7 +618,7 @@ th { } td { - font-size: min(14px, calc(1vh * 5)); + font-size: min(12px, calc(1vh * 3)); } th, td { @@ -700,3 +644,83 @@ tr { } */ + + +button.collapsed { + display: block; + opacity: 0; +} + +form.filter button.save, form.filter button.button-cancel { + margin-top: 0; + margin-bottom: 0; +} +form.filter button.save, form.filter button.button-cancel { + margin-top: 0; + margin-bottom: 0; +} + +#tableMain { + overflow-x: auto; + padding: 1vh 2vh; + max-width: min(calc(1vh * 80), calc(1vw * 90)); + width: fit-content; + margin: 1vh 2vh; + align-items: normal; + justify-content: normal; +} + +#tableMain thead tr th, #tableMain tbody tr td { + width: 20vh; + min-width: 20vh; + padding: 0 0.5vh; +} + + + + +:root { + --background-color: #ffffff; + --text-color: #333333; + --primary-color: #007bff; + --secondary-color: #6c757d; + --success-color: #28a745; + --danger-color: #dc3545; + --warning-color: #ffc107; + --info-color: #17a2b8; + --light-color: #f8f9fa; + --dark-color: #343a40; + --border-color: #dee2e6; + --shadow-color: rgba(0, 0, 0, 0.1); + + /* Header */ + --header-bg: #f8f9fa; + --header-text: #333333; + + /* Footer */ + --footer-bg: #f8f9fa; + --footer-text: #6c757d; + + /* Navigation */ + --nav-bg: #ffffff; + --nav-text: #333333; + --nav-hover-bg: #f1f3f5; + --nav-hover-text: #007bff; + + /* Buttons */ + --Button-primary-bg: #007bff; + --Button-primary-text: #ffffff; + --Button-secondary-bg: #6c757d; + --Button-secondary-text: #ffffff; + + /* Forms */ + --input-bg: #ffffff; + --input-border: #ced4da; + --input-text: #495057; + --input-focus-border: #80bdff; + + /* Cards */ + --card-bg: #ffffff; + --card-border: #dee2e6; + --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); +} diff --git a/static/dist/css/main.css b/static/dist/css/main.css index 7cebe8d8..c2b1ad45 100644 --- a/static/dist/css/main.css +++ b/static/dist/css/main.css @@ -30,7 +30,7 @@ justify-self: left; } -.buttonAdd2Basket { +.buttonAddToBasket { background-color: var(--c_blue_pastel); color: var(--c_blue_dark); border-color: var(--c_blue_dark); diff --git a/static/dist/css/store_home.bundle.css b/static/dist/css/store_home.bundle.css index 8b137891..1ca221b1 100644 --- a/static/dist/css/store_home.bundle.css +++ b/static/dist/css/store_home.bundle.css @@ -1 +1,54 @@ +.img-product { + max-width: 20vh; + max-height: 20vh; + border-radius: 3vh; + justify-self: left; +} + +.img-thumbnail { + max-width: 10vh; + max-height: 10vh; + border-radius: 3vh; + justify-self: left; +} + +.buttonAddToBasket { + background-color: var(--c_blue_pastel); + color: var(--c_blue_dark); + border-color: var(--c_blue_dark); +} + +#buttonCheckout, .buttonBuyNow { + background-color: var(--c_purple_pastel); + color: var(--c_purple_dark); + border-color: var(--c_purple_dark); +} + +.button-increment, .button-decrement { + border: 2px solid darkgrey; + background-color: lightgray; + margin: 1vh 1vh; + width: 2.5vh; + height: 2.5vh; + border-radius: 1.25vh; + font-size: 2vh; +} + +.container-input > input { + padding: 0vh 1vh; + border-radius: 0.5vh; + max-width: 7vh; +} + +#basket { + max-width: 100%; +} + + + +/* Right column */ +.rightcolumn { + min-width: fit-content; +} + diff --git a/static/dist/css/store_product_categories.bundle.css b/static/dist/css/store_product_categories.bundle.css index 619f1e43..e4d4fbd0 100644 --- a/static/dist/css/store_product_categories.bundle.css +++ b/static/dist/css/store_product_categories.bundle.css @@ -1,23 +1,111 @@ +.img-product { + max-width: 20vh; + max-height: 20vh; + border-radius: 3vh; + justify-self: left; +} + +.img-thumbnail { + max-width: 10vh; + max-height: 10vh; + border-radius: 3vh; + justify-self: left; +} + +.buttonAddToBasket { + background-color: var(--c_blue_pastel); + color: var(--c_blue_dark); + border-color: var(--c_blue_dark); +} + +#buttonCheckout, .buttonBuyNow { + background-color: var(--c_purple_pastel); + color: var(--c_purple_dark); + border-color: var(--c_purple_dark); +} + +.button-increment, .button-decrement { + border: 2px solid darkgrey; + background-color: lightgray; + margin: 1vh 1vh; + width: 2.5vh; + height: 2.5vh; + border-radius: 1.25vh; + font-size: 2vh; +} + +.container-input > input { + padding: 0vh 1vh; + border-radius: 0.5vh; + max-width: 7vh; +} + +#basket { + max-width: 100%; +} + -td.display-order, th.display-order { - width: 8% !important; + +/* Right column */ +.rightcolumn { + min-width: fit-content; } -td.code, th.code { - width: 15% !important; + +#formFilters { + width: 50vh; } -td.name, th.name { - width: 25% !important; + +#formFilters .container { + max-width: fit-content; } -td.description, th.description { - width: 35% !important; + +#formFilters .container-input.filter.is_not_empty { + width: 10vh; +} + +#formFilters .container-input.filter.active { + width: 8vh; } -td.access_level, th.access_level { - width: 10% !important; + +#tableMain { + max-width: min(calc(1vh * 79), calc(1vw * 90)); } -td.active, th.active { - width: 7% !important; + +/* +#tableMain thead tr th, #tableMain tbody tr td { + margin-left: 1vh; + margin-right: 1vh; } +*/ + +#tableMain tbody tr td.display_order, #tableMain thead tr th.display_order { + width: 5vh; + min-width: 5vh; +} +#tableMain tbody tr td.code, #tableMain thead tr th.code { + width: 10vh; + min-width: 10vh; +} +#tableMain tbody tr td.name, #tableMain thead tr th.name { + width: 15vh; + min-width: 15vh; +} +#tableMain tbody tr td.description, #tableMain thead tr th.description { + width: 25vh; + min-width: 25vh; +} +#tableMain tbody tr td.access_level, #tableMain thead tr th.access_level { + width: 7vh; + min-width: 7vh; +} +#tableMain tbody tr td.active, #tableMain thead tr th.active { + width: 5vh; + min-width: 5vh; +} +/* +nips +*/ /* .row-new { @@ -26,15 +114,15 @@ td.active, th.active { */ textarea { - width: 95% !important; + width: 95%; } select { - width: 100% !important; + width: 100%; } input { - width: 90% !important; + width: 90%; } td > input, td > select, td > textarea, .container-input > input, .container-input > select, .container-input > textarea { diff --git a/static/dist/css/store_product_permutations.bundle.css b/static/dist/css/store_product_permutations.bundle.css index 5fa4f30c..f5aac066 100644 --- a/static/dist/css/store_product_permutations.bundle.css +++ b/static/dist/css/store_product_permutations.bundle.css @@ -1,28 +1,163 @@ +.img-product { + max-width: 20vh; + max-height: 20vh; + border-radius: 3vh; + justify-self: left; +} + +.img-thumbnail { + max-width: 10vh; + max-height: 10vh; + border-radius: 3vh; + justify-self: left; +} + +.buttonAddToBasket { + background-color: var(--c_blue_pastel); + color: var(--c_blue_dark); + border-color: var(--c_blue_dark); +} + +#buttonCheckout, .buttonBuyNow { + background-color: var(--c_purple_pastel); + color: var(--c_purple_dark); + border-color: var(--c_purple_dark); +} + +.button-increment, .button-decrement { + border: 2px solid darkgrey; + background-color: lightgray; + margin: 1vh 1vh; + width: 2.5vh; + height: 2.5vh; + border-radius: 1.25vh; + font-size: 2vh; +} + +.container-input > input { + padding: 0vh 1vh; + border-radius: 0.5vh; + max-width: 7vh; +} + +#basket { + max-width: 100%; +} + -td.category, th.category { - width: 16% !important; + +/* Right column */ +.rightcolumn { + min-width: fit-content; } -td.product, th.product { - width: 23% !important; + +#formFilters { + width: 50vh; } -td.variations, th.variations { - width: 19% !important; + +#formFilters .container { + max-width: fit-content; } -td.quantity-stock, th.quantity-stock { - width: 10% !important; + + +#tableMain { + max-width: 90vw; } -td.quantity-min, th.quantity-min { - width: 10% !important; +#tableMain thead tr th.category, #tableMain tbody tr td.category { + width: 8vh; + min-width: 8vh; } -td.quantity-max, th.quantity-max { - width: 10% !important; +#tableMain thead tr th.product, #tableMain tbody tr td.product { + width: 10vh; + min-width: 10vh; } -td.cost-local-VAT-incl, th.cost-local-VAT-incl { - width: 6% !important; +#tableMain thead tr th.product_variations.collapsed, #tableMain tbody tr td.product_variations.collapsed { + width: 10vh; + min-width: 10vh; + display: table-cell !important; } -td.detail, th.detail { - width: 6% !important; +#tableMain thead tr th.product_variations, #tableMain tbody tr td.product_variations { + width: 20vh; + min-width: 20vh; +} +#tableMain tbody tr td.product_variations table thead tr th, #tableMain tbody tr td.product_variations table tbody tr td { + width: 8vh; + min-width: 8vh; +} +#tableMain tbody tr td.product_variations table thead tr th:last-of-type, #tableMain tbody tr td.product_variations table tbody tr td:last-of-type { + width: 4vh; + min-width: 4vh; +} +#tableMain thead tr th.description, #tableMain tbody tr td.description { +} +#tableMain thead tr th.quantity_stock, #tableMain tbody tr td.quantity_stock { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.quantity_min, #tableMain tbody tr td.quantity_min { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.quantity_max, #tableMain tbody tr td.quantity_max { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.count_unit_measurement_per_quantity_step, #tableMain tbody tr td.count_unit_measurement_per_quantity_step { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.id_unit_measurement_quantity, #tableMain tbody tr td.id_unit_measurement_quantity { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.is_subscription, #tableMain tbody tr td.is_subscription { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.count_interval_recurrence, #tableMain tbody tr td.count_interval_recurrence { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_unit_measurement_interval_recurrence, #tableMain tbody tr td.id_unit_measurement_interval_recurrence { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_stripe_product, #tableMain tbody tr td.id_stripe_product { + width: 10vh; + min-width: 10vh; +} +#tableMain thead tr th.does_expire_faster_once_unsealed, #tableMain tbody tr td.does_expire_faster_once_unsealed { + width: 7vh; + min-width: 7vh; +} +#tableMain thead tr th.count_interval_expiration_unsealed, #tableMain tbody tr td.count_interval_expiration_unsealed { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.id_unit_measurement_interval_expiration_unsealed, #tableMain tbody tr td.id_unit_measurement_interval_expiration_unsealed { + width: 8vh; + min-width: 8vh; +} +#tableMain thead tr th.cost_local, #tableMain tbody tr td.cost_local { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.id_currency_cost, #tableMain tbody tr td.id_currency_cost { + width: 6vh; + min-width: 6vh; +} +#tableMain thead tr th.profit_local_min, #tableMain tbody tr td.profit_local_min { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.latency_manufacture_days, #tableMain tbody tr td.latency_manufacture_days { + width: 9vh; + min-width: 9vh; +} +#tableMain thead tr th.active, #tableMain tbody tr td.active { + width: 6vh; + min-width: 6vh; } textarea { diff --git a/static/dist/css/store_stock_items.bundle.css b/static/dist/css/store_stock_items.bundle.css index d9dbd18a..99a06b67 100644 --- a/static/dist/css/store_stock_items.bundle.css +++ b/static/dist/css/store_stock_items.bundle.css @@ -1,4 +1,57 @@ +.img-product { + max-width: 20vh; + max-height: 20vh; + border-radius: 3vh; + justify-self: left; +} + +.img-thumbnail { + max-width: 10vh; + max-height: 10vh; + border-radius: 3vh; + justify-self: left; +} + +.buttonAddToBasket { + background-color: var(--c_blue_pastel); + color: var(--c_blue_dark); + border-color: var(--c_blue_dark); +} + +#buttonCheckout, .buttonBuyNow { + background-color: var(--c_purple_pastel); + color: var(--c_purple_dark); + border-color: var(--c_purple_dark); +} + +.button-increment, .button-decrement { + border: 2px solid darkgrey; + background-color: lightgray; + margin: 1vh 1vh; + width: 2.5vh; + height: 2.5vh; + border-radius: 1.25vh; + font-size: 2vh; +} + +.container-input > input { + padding: 0vh 1vh; + border-radius: 0.5vh; + max-width: 7vh; +} + +#basket { + max-width: 100%; +} + + + +/* Right column */ +.rightcolumn { + min-width: fit-content; +} + th, td { min-width: fit-content; } diff --git a/static/dist/js/legal_accessibility_statement.bundle.js b/static/dist/js/legal_accessibility_statement.bundle.js index 30747bf4..7e20a39a 100644 --- a/static/dist/js/legal_accessibility_statement.bundle.js +++ b/static/dist/js/legal_accessibility_statement.bundle.js @@ -1 +1 @@ -(()=>{"use strict";var r,e={780:()=>{},711:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={841:0,466:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(711)));var a=t.O(void 0,[466],(()=>t(780)));a=t.O(a)})(); \ No newline at end of file +(()=>{"use strict";var r,e={780:()=>{},359:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={841:0,416:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(359)));var a=t.O(void 0,[416],(()=>t(780)));a=t.O(a)})(); \ No newline at end of file diff --git a/static/dist/js/legal_license.bundle.js b/static/dist/js/legal_license.bundle.js index 69452ac8..3ace2e9c 100644 --- a/static/dist/js/legal_license.bundle.js +++ b/static/dist/js/legal_license.bundle.js @@ -1 +1 @@ -(()=>{"use strict";var r,e={623:()=>{},711:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={690:0,466:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(711)));var a=t.O(void 0,[466],(()=>t(623)));a=t.O(a)})(); \ No newline at end of file +(()=>{"use strict";var r,e={623:()=>{},359:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={690:0,416:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(359)));var a=t.O(void 0,[416],(()=>t(623)));a=t.O(a)})(); \ No newline at end of file diff --git a/static/dist/js/legal_privacy_policy.bundle.js b/static/dist/js/legal_privacy_policy.bundle.js index 092566b3..a1769ac5 100644 --- a/static/dist/js/legal_privacy_policy.bundle.js +++ b/static/dist/js/legal_privacy_policy.bundle.js @@ -1 +1 @@ -(()=>{"use strict";var r,e={713:()=>{},711:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={364:0,466:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(711)));var a=t.O(void 0,[466],(()=>t(713)));a=t.O(a)})(); \ No newline at end of file +(()=>{"use strict";var r,e={713:()=>{},359:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={364:0,416:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(359)));var a=t.O(void 0,[416],(()=>t(713)));a=t.O(a)})(); \ No newline at end of file diff --git a/static/dist/js/legal_retention_schedule.bundle.js b/static/dist/js/legal_retention_schedule.bundle.js index dd7b5194..db92da46 100644 --- a/static/dist/js/legal_retention_schedule.bundle.js +++ b/static/dist/js/legal_retention_schedule.bundle.js @@ -1 +1 @@ -(()=>{"use strict";var r,e={930:()=>{},711:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={607:0,466:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(711)));var a=t.O(void 0,[466],(()=>t(930)));a=t.O(a)})(); \ No newline at end of file +(()=>{"use strict";var r,e={930:()=>{},359:()=>{}},o={};function t(r){var a=o[r];if(void 0!==a)return a.exports;var n=o[r]={exports:{}};return e[r](n,n.exports,t),n.exports}t.m=e,r=[],t.O=(e,o,a,n)=>{if(!o){var i=1/0;for(f=0;f=n)&&Object.keys(t.O).every((r=>t.O[r](o[v])))?o.splice(v--,1):(p=!1,n0&&r[f-1][2]>n;f--)r[f]=r[f-1];r[f]=[o,a,n]},t.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),(()=>{var r={607:0,416:0};t.O.j=e=>0===r[e];var e=(e,o)=>{var a,n,[i,p,v]=o,s=0;if(i.some((e=>0!==r[e]))){for(a in p)t.o(p,a)&&(t.m[a]=p[a]);if(v)var f=v(t)}for(e&&e(o);st(359)));var a=t.O(void 0,[416],(()=>t(930)));a=t.O(a)})(); \ No newline at end of file diff --git a/static/dist/js/main.bundle.js b/static/dist/js/main.bundle.js index f99376f3..7fb44013 100644 --- a/static/dist/js/main.bundle.js +++ b/static/dist/js/main.bundle.js @@ -1,2 +1,2 @@ /*! For license information please see main.bundle.js.LICENSE.txt */ -(()=>{"use strict";(()=>{function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){for(var n=0;n0)if(r)t=!1;else if("string"!=typeof e[0])t=!1;else for(var n=0;n0)}},{key:"getDataContentType",value:function(t){var r=null,n="";return e.isEmpty(t)||("string"==typeof t?(r=t,n="application/x-www-form-urlencoded; charset=UTF-8"):(r=JSON.stringify(t),n="application/json; charset=UTF-8")),{Data:r,ContentType:n}}},{key:"arrayContainsItem",value:function(t,r){var n=!1;if(!e.isEmpty(t)&&!e.isEmpty(r))if(t[0]instanceof jQuery){for(var o=0;o=0;--i){var a=this.tryEntries[i],l=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),A(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;A(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:D(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),m}},t}function m(e,t,r,n,o,i,a){try{var l=e[i](a),u=l.value}catch(e){return void r(e)}l.done?t(u):Promise.resolve(u).then(n,o)}function b(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){m(i,n,o,a,l,"next",e)}function l(e){m(i,n,o,a,l,"throw",e)}a(void 0)}))}}function S(e,t){for(var r=0;r1&&void 0!==c[1]?c[1]:"GET",o=c.length>2&&void 0!==c[2]?c[2]:null,i=c.length>3&&void 0!==c[3]?c[3]:null,a=e.getUrlFromHash(r,i),l={method:n,headers:{"Content-Type":"application/json","X-CSRFToken":e.getCsrfToken()}},!o||"POST"!==n&&"PUT"!==n&&"PATCH"!==n||(l.body=JSON.stringify(o)),console.log("API request:",n,a,o),t.prev=7,t.next=10,fetch(a,l);case 10:if((u=t.sent).ok){t.next=13;break}throw new Error("HTTP error! status: ".concat(u.status));case 13:return t.next=15,u.json();case 15:return t.abrupt("return",t.sent);case 18:throw t.prev=18,t.t0=t.catch(7),console.error("API request failed:",t.t0),t.t0;case 22:case"end":return t.stop()}}),t,null,[[7,18]])}))),function(e){return u.apply(this,arguments)})},{key:"getUrlFromHash",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;null==t&&(t=hashPageHome),console.log("getUrlFromHash:"),console.log("base url: "+_pathHost+"\nhash: "+t+"\nparams: "+r);var n=e.parameteriseUrl(_pathHost+t,r);return console.log("url: "+n),n}},{key:"parameteriseUrl",value:function(e,t){return t&&(e+="?"+new URLSearchParams(t).toString()),e}},{key:"goToUrl",value:function(e){window.location.href=e}},{key:"goToHash",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=e.getUrlFromHash(t,r);e.goToUrl(n)}},{key:"loginUser",value:(a=b(g().mark((function t(){var r;return g().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return(r={})[keyCallback]=l.getHashPageCurrent(),t.next=4,e.request(hashPageUserLogin,"POST",r);case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)}))),function(){return a.apply(this,arguments)})},{key:"getCategories",value:(i=b(g().mark((function t(){return g().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.request(hashGetStoreProductCategory);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(){return i.apply(this,arguments)})},{key:"getCategoriesByFilters",value:(o=b(g().mark((function t(r){return g().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e.goToHash(hashPageStoreProductCategories,r);case 1:case"end":return t.stop()}}),t)}))),function(e){return o.apply(this,arguments)})},{key:"saveCategories",value:(n=b(g().mark((function t(r,n,o){var i;return g().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return(i={})[flagFormFilters]=l.convertForm2JSON(n),i[flagCategory]=r,i[flagComment]=o,t.next=6,e.request(hashSaveStoreProductCategory,"POST",i);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t)}))),function(e,t,r){return n.apply(this,arguments)})}],r&&S(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n,o,i,a,u}();function w(e){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},w(e)}function E(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null==t&&(t=document.querySelector("form."+flagFilter+" button."+flagSave)),null==r&&(r=document.querySelector("form."+flagFilter+" button."+flagCancel)),e?(r.classList.remove(flagCollapsed),t.classList.remove(flagCollapsed)):(r.classList.add(flagCollapsed),t.classList.add(flagCollapsed))}}],n=[{key:"isDirtyFilter",value:function(e){var t=l.isElementDirty(e);return t&&document.querySelectorAll(idTableMain+" tbody tr").remove(),t}}],r&&E(t.prototype,r),n&&E(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,n}();function L(e){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},L(e)}function j(e,t){for(var r=0;r at "+r[keyPostcode]+"",document.querySelectorAll(idOverlayInfoBilling).css("display","none"),document.querySelectorAll(idOverlayInfoBilling).querySelector("form").classList.add(flagSubmitted)}else document.querySelectorAll(idContainerInfoDelivery).querySelector("div").innerHTML=""+r[keyNameFull]+" at "+r[keyPostcode]+"",document.querySelectorAll(idOverlayInfoDelivery).css("display","none"),document.querySelectorAll(idOverlayInfoDelivery).querySelector("form").classList.add(flagSubmitted)}},{key:"convertFormBilling2JSON",value:function(e,t){var r;r=document.querySelectorAll(t).querySelector("form"),r=document.querySelectorAll(idOverlayInfoDelivery).querySelector("form"),console.log("converting billing form to json\nform ID: "+r.id),e[keyForm]=convertForm2JSON(r);var n=[keyNameFull,keyPhoneNumber,keyPostcode,keyAddress1,keyAddress2,keyCity,keyCounty];for(var o in console.log("ajaxData:"),console.log(e),e[keyForm][keyInfoIdentical]=getElementCurrentValue(r.querySelector("#"+keyInfoIdentical)),n)t==idOverlayInfoBilling&&e[keyForm][keyInfoIdentical]?e[keyForm][n[o]]=getElementCurrentValue((void 0).querySelector("#"+n[o])):e[keyForm][n[o]]=getElementCurrentValue(r.querySelector("#"+n[o]));return console.log("ajaxData:"),console.log(e),e}},{key:"hookupButtonCheckoutSession",value:function(){var e=document.querySelectorAll(idButtonCheckout);e.classList.remove(flagInitialised),f.initialiseEventHandler(idButtonCheckout,flagInitialised,(function(){e.removeEventListener("click"),e.addEventListener("click",(function(e){var t=v.getLocalStorage(keyBasket),r={};r[keyBasket]=t,r=convertFormBilling2JSON(r,idOverlayInfoDelivery),(r=convertFormBilling2JSON(r,idOverlayInfoBilling))[key_code_currency]=getCurrencySelected(),ajaxJSONData("checkout session",mapHashToController(hashPageStoreCheckout),r,handleResponseCheckout,!1)}))}))}},{key:"handleResponseCheckout",value:function(e){window.location.href=e.data[keyUrlCheckout]}},{key:"hookupButtonFormBillingCopy",value:function(){f.initialiseEventHandler(idButtonFormBillingCopy,flagInitialised,(function(){document.querySelectorAll(idButtonFormBillingCopy).addEventListener("click",(function(e){var t=[keyNameFull,keyPhoneNumber,keyPostcode,keyAddress1,keyAddress2,keyCity,keyCounty],r=document.querySelectorAll(idOverlayInfoBilling).querySelector("form"),n=document.querySelectorAll(idOverlayInfoDelivery).querySelector("form");for(var o in t)r.querySelector("#"+t[o]).value=getElementCurrentValue(n.querySelector("#"+t[o]))}))}))}},{key:"leave",value:function(){!function(e,t,r){var n=Qe(ze(e.prototype),"leave",r);return"function"==typeof n?function(e){return n.apply(r,e)}:n}(t,0,this)([])}}])}(C);function Ke(e){return Ke="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ke(e)}function Xe(e,t){for(var r=0;r0&&void 0!==arguments[0]&&arguments[0];if(this.constructor===t)throw new Error("Must implement initialize() method.");if(r){var o=this.getLocalStoragePage()[flagFormFilters],i=this.getFormFilters(),a=l.convertForm2JSON(i);n.areEqualDicts(o,a)}else this.sharedInitialize(),this.hookupFilters(),this.hookupButtonsAddSaveCancel(),this.hookupTableMain(),hookupOverlayConfirm((function(){e.leave(),e.saveRecordsTableDirty()}))}},{key:"hookupFilters",value:function(){if(this.constructor===t)throw new Error("Subclass of TableBasePage must implement method hookupFilters().");this.hookupButtonApplyFilters()}},{key:"hookupFilterActive",value:function(){f.initialiseEventHandler(idFormFilters+"."+flagActive,flagInitialised,(function(e){e.addEventListener("change",(function(r){t.isDirtyFilter(e)}))}))}},{key:"hookupButtonApplyFilters",value:function(){var e=this;f.initialiseEventHandler(idButtonApplyFilters,flagInitialised,(function(t){t.addEventListener("click",(function(t){t.stopPropagation(),e.getAndLoadFilteredTableContent()}))}))}},{key:"getAndLoadFilteredTableContent",value:function(){var e=this.getFormFilters(),t=l.convertForm2JSON(e);this.callFilterTableContent(t).catch((function(e){return console.error("Error:",e)}))}},{key:"getFormFilters",value:function(){return document.querySelector(idFormFilters)}},{key:"callbackLoadTableContent",value:function(e){this.getTableMain().querySelector("tbody").querySelectorAll("tr").forEach((function(e){e.remove()}));var t=e.data[flagRows];!n.isEmpty(t)&&t.every((function(e){return e.hasOwnProperty("display_order")}))&&(t=t.sort((function(e,t){return e.display_order-t.display_order}))),t.forEach(this.loadRowTable.bind(this)),this.hookupTableMain()}},{key:"getTableMain",value:function(){return document.querySelector(idTableMain)}},{key:"loadRowTable",value:function(e){throw new Error("Subclass of TableBasePage must implement method loadRowTable().")}},{key:"hookupButtonsAddSaveCancel",value:function(){this.hookupButtonSave(),this.hookupButtonCancel(),this.hookupButtonAddRowTable()}},{key:"saveRecordsTableDirty",value:function(){var e=this,t=this.getTableRecords(!0);if(0!=t.length){var r=this.getFormFilters(),n=l.getElementValueCurrent(document.querySelector(idTextareaConfirm));this.callSaveTableContent(t,r,n).then((function(t){t[flagStatus]==flagSuccess?(console.log("Data received:",t),e.callbackLoadTableContent(t),console.log("Records saved!")):showOverlayError(t[flagMessage])})).catch((function(e){return console.error("Error:",e)}))}else showOverlayError("No records to save")}},{key:"getTableRecords",value:function(){var e,t=this,r=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=this.getTableMain(),o=[];return n.querySelectorAll("tbody tr").forEach((function(n){r&&!n.classList.contains(flagDirty)||(e=t.getJsonRow(n),o.push(e))})),o}},{key:"getJsonRow",value:function(e){throw new Error("Subclass of TableBasePage must implement method getJsonRow().")}},{key:"hookupButtonCancel",value:function(){f.initialiseEventHandler(idFormFilters+" button."+flagCancel,flagInitialised,(function(e){e.addEventListener("click",(function(e){e.stopPropagation(),getAndLoadFilteredTableContent()})),e.classList.add(flagCollapsed)}))}},{key:"hookupButtonAddRowTable",value:function(){var e=this;f.initialiseEventHandler(idFormFilters+" button."+flagAdd,flagInitialised,(function(t){t.addEventListener("click",(function(t){t.stopPropagation();var r=document.querySelector(idTableMain+" tbody"),n=_rowBlank.cloneNode(!0);n.classList.remove(flagInitialised),n.querySelectorAll("."+flagInitialised).forEach((function(e){e.classList.remove(flagInitialised)}));var o=parseInt(r.querySelector("tr:last-child").querySelector("td."+flagDisplayOrder+" ."+flagSlider).getAttribute(attrValueCurrent))+1;r.appendChild(n);var i=r.querySelector("tr:last-child").querySelector("td."+flagDisplayOrder+" ."+flagSlider);i&&(i.setAttribute(attrValueCurrent,o),i.setAttribute(attrValuePrevious,o)),e.hookupTableMain()}))}))}},{key:"hookupTableMain",value:function(){if(this.constructor===t)throw new Error("Must implement hookupTableMain() method.");null==_rowBlank&&this.cacheRowBlank()}},{key:"cacheRowBlank",value:function(){var e=idTableMain+" tbody tr."+flagRowNew,t=document.querySelector(e);console.log("row blank temp: ",t),_rowBlank=t.cloneNode(!0),document.querySelectorAll(e).forEach((function(e){e.remove()}))}},{key:"hookupSlidersDisplayOrderTable",value:function(){var e=this,t=idTableMain+" tbody tr td."+flagDisplayOrder+" input."+flagSlider+"."+flagDisplayOrder;f.initialiseEventHandler(t,flagInitialised,(function(t){t.addEventListener("change",(function(r){console.log("slider change event"),e.handleChangeElementCellTable(t)}))}))}},{key:"hookupTextareasCodeTable",value:function(){var e=this,t=idTableMain+" tbody tr td."+flagCode+" textarea";f.initialiseEventHandler(t,flagInitialised,(function(t){t.addEventListener("change",(function(r){console.log("textarea change event"),e.handleChangeElementCellTable(t)}))}))}},{key:"handleChangeElementCellTable",value:function(e){var t=l.getRowFromElement(e),r=l.getCellFromElement(e);console.log("td: ",r);var n=this.isDirtyRow(t),o=e.classList.contains(flagDirty),i=l.isElementDirty(e);if(console.log("isDirtyElement: ",i),console.log("wasDirtyElement: ",o),i!=o){l.handleDirtyElement(r,i);var a=this.isDirtyRow(t);if(console.log("isNowDirtyRow: ",a),console.log("wasDirtyRow: ",n),a!=n){l.handleDirtyElement(t,a);var u=this.getTableRecords(!0),c=u.length>0;console.log("dirty records:",u),console.log("existsDirtyRecord:",c),this.toggleShowButtonsSaveCancel(c)}}}},{key:"isDirtyRow",value:function(e){throw new Error("Subclass of TableBasePage must implement method isDirtyRow().")}},{key:"toggleShowButtonsSaveCancel",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;null==t&&(t=document.querySelector(idFormFilters+" button."+flagSave)),null==r&&(r=document.querySelector(idFormFilters+" button."+flagCancel)),e?(r.classList.remove(flagCollapsed),t.classList.remove(flagCollapsed)):(r.classList.add(flagCollapsed),t.classList.add(flagCollapsed))}},{key:"handleChangeSelectCellTable",value:function(e){var t=l.getRowFromElement(e),r=l.getCellFromElement(e);console.log("td: ",r);var n=this.isDirtyRow(t),o=e.classList.contains(flagDirty),i=l.isElementDirty(e);if(console.log("isDirtyElement: ",i),console.log("wasDirtyElement: ",o),i!=o){l.handleDirtyElement(r,i);var a=e.options[e.selectedIndex];r.setAttribute(attrIdAccessLevel,a.value),r.setAttribute(flagAccessLevelRequired,a.textcontent);var u=this.isDirtyRow(t);if(console.log("isNowDirtyRow: ",u),console.log("wasDirtyRow: ",n),u!=n){l.handleDirtyElement(t,u);var c=this.getTableRecords(!0),s=c.length>0;console.log("dirty records:",c),console.log("existsDirtyRecord:",s),this.toggleShowButtonsSaveCancel(s)}}}},{key:"hookupTextareasNameTable",value:function(){var e=this,t=idTableMain+" tbody tr td."+flagName+" textarea";f.initialiseEventHandler(t,flagInitialised,(function(t){t.addEventListener("change",(function(r){console.log("textarea change event"),e.handleChangeElementCellTable(t)}))}))}},{key:"hookupTextareasDescriptionTable",value:function(){var e=this,t=idTableMain+" tbody tr td."+flagDescription+" textarea";f.initialiseEventHandler(t,flagInitialised,(function(t){t.addEventListener("change",(function(r){console.log("textarea change event"),e.handleChangeElementCellTable(t)}))}))}},{key:"hookupInputsActiveTable",value:function(){var e=this,t=idTableMain+" tbody tr td."+flagActive+' input[type="checkbox"]';f.initialiseEventHandler(t,flagInitialised,(function(t){t.addEventListener("change",(function(r){console.log("input change event"),e.handleChangeElementCellTable(t)}))}))}},{key:"hookupTdsAccessLevel",value:function(){var e=this;f.initialiseEventHandler(idTableMain+" tbody td."+flagAccessLevel,flagInitialised,(function(t){t.addEventListener("click",(function(t){e.handleClickTdAccessLevel(t)}))}))}},{key:"handleClickTdAccessLevel",value:function(e){console.log("tdAccessLevel clicked"),e.stopPropagation();var t=l.getCellFromElement(e.target);console.log("tdAccessLevel: ",t);var r=l.getRowFromElement(t),n=t.querySelector("div."+flagAccessLevel).getAttribute(attrIdAccessLevel),o=document.createElement("select");o.classList.add(flagAccessLevel),o.setAttribute(attrValueCurrent,n),o.setAttribute(attrValuePrevious,n),optionsAccessLevel.forEach((function(e){var t=document.createElement("option");t.value=e.value,t.textContent=e.text,e.value==n&&(t.selected=!0),o.appendChild(t)}));var i=t.cloneNode(!0);i.innerHTML="",i.appendChild(o),r.replaceChild(i,t),this.hookupDdlsAccessLevelTable()}},{key:"hookupDdlsAccessLevelTable",value:function(){var e=this;f.initialiseEventHandler(idTableMain+" tbody select."+flagAccessLevel,flagInitialised,(function(t){t.addEventListener("change",(function(r){r.stopPropagation(),e.handleChangeDdlAccessLevelTable(t)}))}))}},{key:"handleChangeDdlAccessLevelTable",value:function(e){var t=l.getRowFromElement(e),r=l.getCellFromElement(e);console.log("td: ",r);var n=this.isDirtyRow(t),o=e.classList.contains(flagDirty),i=l.isElementDirty(e);if(console.log("isDirtyElement: ",i),console.log("wasDirtyElement: ",o),i!=o){l.handleDirtyElement(r,i);var a=e.options[e.selectedIndex];r.setAttribute(attrIdAccessLevel,a.value),r.setAttribute(flagAccessLevelRequired,a.textcontent);var u=this.isDirtyRow(t);if(console.log("isNowDirtyRow: ",u),console.log("wasDirtyRow: ",n),u!=n){l.handleDirtyElement(t,u);var c=this.getTableRecords(!0),s=c.length>0;console.log("dirty records:",c),console.log("existsDirtyRecord:",s),this.toggleShowButtonsSaveCancel(s)}}}},{key:"leave",value:function(){if(this.constructor===t)throw new Error("Must implement leave() method.");!function(e,t,r){var n=ut(ct(e.prototype),"leave",r);return"function"==typeof n?function(e){return n.apply(r,e)}:n}(t,0,this)([]);var e=this.getFormFilters(),r={};r[flagFormFilters]=l.convertForm2JSON(e),this.setLocalStoragePage(r),_rowBlank=null}}],[{key:"isDirtyFilter",value:function(e){var t=l.isElementDirty(e);if(t){var r=document.querySelector(idTableMain+" tbody");r.querySelectorAll("tr").remove(),r.appendChild(document.createElement('
Press "Apply Filters" to refresh the table.
'))}return t}}])}(C);function yt(e){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},yt(e)}function dt(e,t){for(var r=0;r",t))})),e.addEventListener("change",(function(e){loadPermutations()}))})),f.initialiseEventHandler(idFilterIsOutOfStock,flagInitialised,(function(e){e.addEventListener("change",(function(e){loadPermutations()}))})),f.initialiseEventHandler(idFilterQuantityMin,flagInitialised,(function(e){e.addEventListener("change",(function(e){loadPermutations()}))})),f.initialiseEventHandler(idFilterQuantityMax,flagInitialised,(function(e){e.addEventListener("change",(function(e){loadPermutations()}))}))}},{key:"loadPermutations",value:function(){var e=document.querySelectorAll(idFormFiltersPermutations),t={};t[keyForm]=convertForm2JSON(e),t.csrf_token=t[keyForm].csrf_token,console.log("ajaxData:"),console.log(t),ajaxJSONData("permutations",mapHashToController(hashPageStorePermutationsPost),t,callbackLoadPermutations,!1,{"X-CSRFToken":t.csrf_token})}},{key:"callbackLoadPermutations",value:function(e){console.log("ajax:"),console.log(e.data);var t,r,n,o=document.querySelectorAll(idTableMain);(t=o.querySelector("tbody")).querySelector("tr").remove(),e.data.forEach((function(e){r=_rowBlank.cloneNode(!0),(r=document.querySelectorAll(r)).classList.remove(flagRowNew),console.log("applying data row: ",e),r.querySelector("td."+flagCategory+" select").value=e[attrIdCategory],n=r.querySelector("td."+flagProduct+" select"),listProducts.forEach((function(t){t[attrIdCategory]==e[attrIdCategory]&&n.appendChild(document.createElement("