diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-27 16:49:05 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-27 16:49:05 +0700 |
| commit | 6fa5de951abc02884eb37cdc6786c0f3d141ccc5 (patch) | |
| tree | e76536fa660a0af978153b7e4c9bf678b902e318 | |
| parent | ebbf7e832b570f1d2ecec838983b7582ade78af4 (diff) | |
fix validation request, add context in sale order, add benchmark apache_solr
| -rw-r--r-- | indoteknik_api/controllers/api_v1/flash_sale.py | 2 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 8 | ||||
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 40 | ||||
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 5 |
4 files changed, 27 insertions, 28 deletions
diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py index cad2cb61..a0aaa44e 100644 --- a/indoteknik_api/controllers/api_v1/flash_sale.py +++ b/indoteknik_api/controllers/api_v1/flash_sale.py @@ -10,7 +10,7 @@ _logger = logging.getLogger(__name__) class FlashSale(controller.Controller): prefix = '/api/v1/' - @http.route(prefix + 'flashsale/header', auth='public', methods=['GET']) + @http.route(prefix + 'flashsale/header', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized() def _get_flash_sale_header(self, **kw): try: diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 950d98db..425dd296 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -53,6 +53,7 @@ class SaleOrder(controller.Controller): 'name': [], 'limit': ['default:0', 'number'], 'offset': ['default:0', 'number'], + 'context': [] }) limit = params['value']['limit'] offset = params['value']['offset'] @@ -61,6 +62,13 @@ class SaleOrder(controller.Controller): partner_child_ids = self.get_partner_child_ids(params['value']['partner_id']) domain = [('partner_id', 'in', partner_child_ids)] + + context = params['value']['context'] + if context == 'quotation': + domain += [('approval_status', '=', False)] + if not context: + domain += [('approval_status', '!=', False)] + if params['value']['name']: name = params['value']['name'].replace(' ', '%') domain += [ diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 86628400..5b20f7d4 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -70,40 +70,30 @@ class Controller(http.Controller): 'value': {}, 'query': {} } - for key in queries: - rules = queries[key] - is_number = len([r for r in rules if r == 'number']) > 0 - - has_alias = [r for r in rules if r.startswith('alias:')] - alias = key - if len(has_alias) > 0: - alias = has_alias[0].replace('alias:', '') - - has_default = [r for r in rules if r.startswith('default:')] - default = None - if len(has_default) > 0: - default = has_default[0].replace('default:', '') - - value = kw.get(key, '') - if value in ['null', 'undefined']: + + for key, rules in queries.items(): + is_number = 'number' in rules + alias = next((r.replace('alias:', '') for r in rules if r.startswith('alias:')), key) + default = next((r.replace('default:', '') for r in rules if r.startswith('default:')), None) + + if (value := kw.get(key, '')) in ['null', 'undefined']: value = '' - for rule in rules: - if rule == 'required' and not value: - result['reason'].append(key + ' is ' + rule) - elif rule == 'number' and value and not value.isdigit(): - result['reason'].append(key + ' must be ' + rule) + if 'required' in rules and not value: + result['reason'].append(f"{key} is required") + if 'number' in rules and value and not value.isdigit(): + result['reason'].append(f"{key} must be a number") result['query'][key] = value + if not value and default: value = default if is_number and value.isdigit(): value = int(value) - if not value and not default: - value = None + result['value'][alias] = value - if len(result['reason']) > 0: - result['valid'] = False + result['valid'] = not result['reason'] + return result def time_to_str(self, object, format): diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ee166002..3709e88a 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -12,7 +12,7 @@ class ApacheSolr(models.Model): _name = 'apache.solr' _order = 'id desc' - def _sync_product_to_solr(self, limit = 500): + def _sync_product_to_solr(self, limit=500): # _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() @@ -23,6 +23,7 @@ class ApacheSolr(models.Model): documents = [] counter = 0 for template in templates: + template_time = time.time() counter += 1 price_excl_after_disc = price_excl = discount = tax = 0 variants_name = variants_code = '' @@ -108,7 +109,7 @@ class ApacheSolr(models.Model): documents.append(document) template.solr_flag = 1 # add counter for monitoring - _logger.info('[SYNC_PRODUCT_TO_SOLR] %s/%i' % (counter, limit)) + _logger.info('[SYNC_PRODUCT_TO_SOLR] {}/{} {:.6f}'.format(counter, limit, time.time() - template_time)) _logger.info('[SYNC_PRODUCT_TO_SOLR] Success add to solr product %s' % template.id) _solr.add(documents) end_time = time.time() |
