summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/banner.py33
-rw-r--r--indoteknik_api/controllers/api_v1/category.py16
-rw-r--r--indoteknik_api/controllers/api_v1/flash_sale.py5
-rw-r--r--indoteknik_api/controllers/api_v1/lead.py4
-rw-r--r--indoteknik_api/controllers/api_v1/manufacture.py3
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py49
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py33
7 files changed, 104 insertions, 39 deletions
diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py
index 1bd0fea6..d1ebf573 100644
--- a/indoteknik_api/controllers/api_v1/banner.py
+++ b/indoteknik_api/controllers/api_v1/banner.py
@@ -1,6 +1,7 @@
from .. import controller
from odoo import http
from odoo.http import request
+from datetime import datetime
class Banner(controller.Controller):
@@ -13,26 +14,44 @@ class Banner(controller.Controller):
type = kw.get('type')
limit = int(kw.get('limit', 0))
offset = int(kw.get('offset', 0))
- order = kw.get('order')
- if not order:
- order = 'write_date DESC'
+ order = kw.get('order', 'write_date DESC')
query = [('x_status_banner', '=', 'tayang')]
if type:
query += [('x_banner_category.x_studio_field_KKVl4', '=', type)]
+ if type == 'index-a-1':
+ order = 'group_by_week ASC, sequence ASC'
+
if manufacture_id:
query += [('x_relasi_manufacture', '=', int(manufacture_id))]
banners = request.env['x_banner.banner'].search(query, limit=limit, offset=offset, order=order)
- data = []
+ week_number = self.get_week_number_of_current_month()
+
+ end_datas = []
+ datas = []
for banner in banners:
- data.append({
+ data = {
'name': banner.x_name,
'url': banner.x_url_banner,
'background_color': banner.background_color,
+ 'sequence': banner.sequence,
+ 'group_by_week': banner.group_by_week,
'image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
- })
+ }
+
+ if banner.group_by_week and int(banner.group_by_week) < week_number and type == 'index-a-1':
+ end_datas.append(data)
+ continue
+
+ datas.append(data)
- return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) \ No newline at end of file
+ datas += end_datas
+ return self.response(datas, headers=[('Cache-Control', 'max-age=3600, public')])
+
+ def get_week_number_of_current_month(self):
+ today = datetime.now().day
+ week_number = (today - 1) // 7 + 1
+ return min(week_number, 4) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py
index b5e01d4e..efbf52f2 100644
--- a/indoteknik_api/controllers/api_v1/category.py
+++ b/indoteknik_api/controllers/api_v1/category.py
@@ -54,7 +54,7 @@ class Category(controller.Controller):
@controller.Controller.must_authorized()
def get_categories_homepage_count(self):
query = [('status', '=', 'tayang')]
- categories = request.env['website.categories.homepage'].search_read(query, ['id'])
+ categories = request.env['website.categories.homepage'].search_read(query, ['id'], order="sequence")
return self.response([x['id'] for x in categories])
@@ -69,17 +69,7 @@ class Category(controller.Controller):
categories = request.env['website.categories.homepage'].search(query, order='sequence')
data = []
for category in categories:
- query_product = [
- ('active', '=', True),
- ('type', '=', 'product'),
- ('product_rating', '>', 0),
- ('public_categ_ids', 'child_of', [category.category_id.id])
- ]
- products = request.env['product.template'].search(query_product, order='product_rating desc', limit=12)
- # product_brands = []
- brands = request.env['x_manufactures'].search([
- ('product_tmpl_ids.public_categ_ids', 'child_of', [category.category_id.id])
- ], limit=8)
+ products = category.product_ids
data.append({
'id': category.id,
@@ -88,8 +78,6 @@ class Category(controller.Controller):
'name': category.category_id.name,
'image': request.env['ir.attachment'].api_image('website.categories.homepage', 'image', category.id),
'url': category.url,
- # 'brands': [y.x_name for y in brands],
- 'brands': [request.env['x_manufactures'].api_single_response(y) for y in brands],
'products': [request.env['product.template'].api_single_response(x) for x in products]
})
return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])
diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py
index dc7c3928..dff8bec3 100644
--- a/indoteknik_api/controllers/api_v1/flash_sale.py
+++ b/indoteknik_api/controllers/api_v1/flash_sale.py
@@ -1,4 +1,3 @@
-from datetime import datetime
import logging
from .. import controller
from odoo import http
@@ -28,7 +27,7 @@ class FlashSale(controller.Controller):
'banner': request.env['ir.attachment'].api_image('product.pricelist', 'banner', pricelist.id),
'banner_mobile': request.env['ir.attachment'].api_image('product.pricelist', 'banner_mobile', pricelist.id),
'banner_top': request.env['ir.attachment'].api_image('product.pricelist', 'banner_top', pricelist.id),
- 'duration': round((pricelist.end_date - datetime.now()).total_seconds()),
+ 'duration': pricelist._remaining_time_in_second(),
'product_total': request.env['product.pricelist.item'].search_count(query),
})
return self.response(data)
@@ -94,7 +93,7 @@ class FlashSale(controller.Controller):
'name': active_flash_sale.name,
'banner': base_url + 'api/image/product.pricelist/banner/' + str(active_flash_sale.id) if active_flash_sale.banner else '',
'banner_mobile': base_url + 'api/image/product.pricelist/banner_mobile/' + str(active_flash_sale.id) if active_flash_sale.banner_mobile else '',
- 'duration': round((active_flash_sale.end_date - datetime.now()).total_seconds()),
+ 'duration': active_flash_sale._remaining_time_in_second(),
'flashsale_option': active_flash_sale.flashsale_option,
'product_total': request.env['product.template'].search_count(query),
'products': [request.env['product.template'].api_single_response(x) for x in product_templates]
diff --git a/indoteknik_api/controllers/api_v1/lead.py b/indoteknik_api/controllers/api_v1/lead.py
index df4f46bd..23c3bf99 100644
--- a/indoteknik_api/controllers/api_v1/lead.py
+++ b/indoteknik_api/controllers/api_v1/lead.py
@@ -20,7 +20,9 @@ class Lead(controller.Controller):
if not params['valid']:
return self.response(code=400, description=params)
-
+
+ params['value']['user_id'] = 20
+
lead = request.env['crm.lead'].create(params['value'])
return self.response(True) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/manufacture.py b/indoteknik_api/controllers/api_v1/manufacture.py
index 345fd660..cbee253d 100644
--- a/indoteknik_api/controllers/api_v1/manufacture.py
+++ b/indoteknik_api/controllers/api_v1/manufacture.py
@@ -16,6 +16,7 @@ class Manufacture(controller.Controller):
level = kw.get('level')
limit = int(kw.get('limit', 0))
offset = int(kw.get('offset', 0))
+ order = 'sequence ASC'
if name:
name = '%' + name.replace(' ', '%') + '%' if '%' not in name else name
@@ -26,7 +27,7 @@ class Manufacture(controller.Controller):
return self.response(code=400, description='level possible value is prioritas, gold, silver')
query.append(('x_manufacture_level', '=', level))
- manufactures = request.env['x_manufactures'].search(query, limit=limit, offset=offset)
+ manufactures = request.env['x_manufactures'].search(query, order=order, limit=limit, offset=offset)
data = {
'manufacture_total': request.env['x_manufactures'].search_count(query),
'manufactures': [request.env['x_manufactures'].api_single_response(x) for x in manufactures]
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index a8b2fd11..ecc6c771 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -1,5 +1,6 @@
from .. import controller
from odoo import http
+from datetime import datetime, timedelta
from odoo.http import request
import json
@@ -276,6 +277,7 @@ class SaleOrder(controller.Controller):
'team_id': 2,
'company_id': 1,
'currency_id': 12,
+ 'source_id': 59,
'state': 'draft',
'picking_policy': 'direct',
'partner_id': params['value']['partner_id'],
@@ -362,9 +364,9 @@ class SaleOrder(controller.Controller):
line.amount_voucher_disc = voucher_disc_line
voucher_disc_item = voucher_disc_line / line.product_uom_qty
- voucher_disc_subtotal = line.price_subtotal - voucher_disc_item
+ voucher_disc_unit = line.price_unit - voucher_disc_item
- line.discount = (line.price_unit - voucher_disc_subtotal) / line.price_unit * 100
+ line.discount += (line.price_unit - voucher_disc_unit) / line.price_unit * 100
cart_ids = [x['cart_id'] for x in products]
user_cart.browse(cart_ids).unlink()
@@ -372,7 +374,49 @@ class SaleOrder(controller.Controller):
'id': sale_order.id,
'name': sale_order.name
})
+
+ @http.route(PREFIX_PARTNER + 'sale-order/<id>/awb', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized(private=True, private_key='partner_id')
+ def get_airway_bill_by_sale_order_id(self, **kw):
+ id = int(kw.get('id', 0))
+ response = {'airways': None}
+ airway_bills = request.env['airway.bill'].search([('so_id', '=', id)])
+
+ if not airway_bills:
+ return self.response(response)
+
+ airways = []
+ for airway_bill in airway_bills:
+ data = airway_bill.decode_response()
+ delivery_order = airway_bill.do_id
+ result = data['rajaongkir']['result']
+
+ manifests_data = []
+ for manifest in airway_bill.manifest_ids:
+ manifest_data = {
+ 'code': manifest.code,
+ 'description': manifest.description,
+ 'datetime': datetime.strftime(manifest.datetime, '%Y-%m-%d %H:%M:%S'),
+ 'city': manifest.city,
+ }
+ manifests_data.append(manifest_data)
+
+ airways.append({
+ 'delivery_order': {
+ 'name': delivery_order.name,
+ 'carrier': delivery_order.carrier_id.name,
+ 'receiver_name': airway_bill.receiver_name,
+ 'receiver_city': airway_bill.receiver_city,
+ },
+ 'delivered': result['delivered'],
+ 'waybill_number': result['summary']['waybill_number'],
+ 'delivery_status': result['delivery_status'],
+ 'manifests': manifests_data
+ })
+ response = {'airways': airways}
+ return self.response(response)
+
@http.route('/api/sale_order/invoiced', auth='public', methods=['GET'])
def get_sale_order_invoiced_by_partner_id(self, **kw):
if not self.authenticate():
@@ -481,3 +525,4 @@ class SaleOrder(controller.Controller):
}
return self.response(data)
+ \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py
index 4baa93b7..3a2c798e 100644
--- a/indoteknik_api/controllers/api_v1/voucher.py
+++ b/indoteknik_api/controllers/api_v1/voucher.py
@@ -12,6 +12,7 @@ class Voucher(controller.Controller):
cart = request.env['website.user.cart']
code = kw.get('code')
user_id = kw.get('user_id')
+ source = kw.get('source')
visibility = ['public']
parameter = []
@@ -25,15 +26,15 @@ class Voucher(controller.Controller):
parameter += [('visibility', 'in', visibility)]
vouchers = request.env['voucher'].get_active_voucher(parameter)
vouchers = vouchers.res_format()
- checkout = cart.get_user_checkout(user_id)
+ checkout = cart.get_user_checkout(user_id, source=source)
for voucher in vouchers:
apply_status = ''
products = checkout['products']
min_purchase_amount = voucher['min_purchase_amount']
- can_apply = True
+ can_apply = False
difference_to_apply = 0
-
+
manufacture_ids = voucher['manufacture_ids']
subtotal = 0
has_match_manufacture = False
@@ -44,17 +45,26 @@ class Voucher(controller.Controller):
manufacture_id = product['manufacture']['id'] or False
if len(manufacture_ids) == 0 or manufacture_id in manufacture_ids:
- purchase_amt = price * quantity
- discount_amt = (price - price_discount) * quantity
- subtotal += purchase_amt - discount_amt
has_match_manufacture = True
-
+
+ if product['has_flashsale']:
+ continue
+
+ purchase_amt = price * quantity
+ discount_amt = (price - price_discount) * quantity
+ subtotal += purchase_amt - discount_amt
+
+ has_flashsale_products = any(product['has_flashsale'] for product in products)
if not has_match_manufacture:
- can_apply = False
- apply_status = 'UM'
+ apply_status = 'UM' # Unqualified Manufacture
elif subtotal < min_purchase_amount:
- can_apply = False
- apply_status = 'MPA'
+ apply_status = 'MPA' # Minimum Purchase Amount
+ if has_flashsale_products:
+ apply_status += '-HF' # Has Flashsale
+ else:
+ can_apply = True
+
+ if subtotal < min_purchase_amount:
difference_to_apply = min_purchase_amount - subtotal
obj_voucher = request.env['voucher'].browse(voucher['id'])
@@ -62,6 +72,7 @@ class Voucher(controller.Controller):
voucher['can_apply'] = can_apply
voucher['apply_status'] = apply_status
+ voucher['has_flashsale_products'] = has_flashsale_products
voucher['discount_voucher'] = discount_voucher
voucher['difference_to_apply'] = difference_to_apply