summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-01-24 13:58:03 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-01-24 13:58:03 +0700
commit93d049139c2be8a70d32145a89e8b6e34732d56d (patch)
tree86357713102fbfba446e6015b225ec3d2a46b4c0
parentda5f5134f56b2ccf1c1de16c3f7616ab3719f3ea (diff)
parent3f311b95265adf1902e650b12fba93cf81a7f72d (diff)
Merge branch 'release' into feature/rest-api
-rw-r--r--indoteknik_api/controllers/api_v1/content.py31
-rw-r--r--indoteknik_api/controllers/api_v1/product.py10
-rw-r--r--indoteknik_api/models/x_manufactures.py1
-rwxr-xr-xindoteknik_custom/models/sale_monitoring.py58
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py98
-rwxr-xr-xindoteknik_custom/views/sale_monitoring.xml5
-rwxr-xr-xindoteknik_custom/views/sale_monitoring_detail.xml5
7 files changed, 137 insertions, 71 deletions
diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py
index 3d4e443a..32828244 100644
--- a/indoteknik_api/controllers/api_v1/content.py
+++ b/indoteknik_api/controllers/api_v1/content.py
@@ -6,6 +6,37 @@ from odoo.http import request
class WebsiteContent(controller.Controller):
prefix = '/api/v1/'
+ @http.route(prefix + 'banner', auth='public', methods=['GET', 'OPTIONS'])
+ def get_banner(self, **kw):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+
+ category_id = int(kw.get('category_id'), 0)
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ]
+
+ if category_id > 0:
+ query = [
+ ('x_status_banner', '=', 'tayang'),
+ ('x_banner_category', '=', category_id),
+ ]
+
+ data = []
+ banners = request.env['x_banner.banner'].search(query)
+ for banner in banners:
+ data.append({
+ # 'image': base_url + 'api/image/x_banner.banner/image' + str(banner.id) if banner.x_banner_image else '',
+ 'banner_image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id),
+ 'category_id': banner.x_banner_category.id,
+ 'category_image': banner.x_banner_category.x_name,
+ 'name': banner.x_name,
+ 'url': banner.x_url_banner,
+ 'status': banner.x_status_banner,
+ })
+ return self.response(data)
+
@http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS'])
def get_product_ads(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 23dcf48e..dc941f13 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -48,8 +48,9 @@ class Product(controller.Controller):
'manufacture_id': brand.id,
'sequence': brand.sequence if brand.sequence else count,
'name': brand.x_name,
- 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
- brand.id) if brand.x_logo_manufacture else '',
+ # 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ # brand.id) if brand.x_logo_manufacture else '',
+ 'image': request.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', brand.id),
})
continue
@@ -74,8 +75,9 @@ class Product(controller.Controller):
'manufacture_id': brand.id,
'sequence': brand.sequence if brand.sequence else count,
'name': brand.x_name,
- 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
- brand.id) if brand.x_logo_manufacture else '',
+ # 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(
+ # brand.id) if brand.x_logo_manufacture else '',
+ 'image': request.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', brand.id),
'products_total': count_products,
'products': [request.env['product.template'].api_single_response(x) for x in products]
})
diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py
index 988d7a45..b85f6d27 100644
--- a/indoteknik_api/models/x_manufactures.py
+++ b/indoteknik_api/models/x_manufactures.py
@@ -5,7 +5,6 @@ class Manufactures(models.Model):
_inherit = 'x_manufactures'
def api_single_response(self, manufacture, with_detail=False):
- base_url = self.env['ir.config_parameter'].get_param('web.base.url')
data = {
'id': manufacture.id,
'logo': self.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', manufacture.id),
diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py
index a837a6bc..a3265a8b 100755
--- a/indoteknik_custom/models/sale_monitoring.py
+++ b/indoteknik_custom/models/sale_monitoring.py
@@ -1,5 +1,7 @@
from odoo import fields, models, api, tools
+import logging
+_logger = logging.getLogger(__name__)
class SaleMonitoring(models.Model):
_name = 'sale.monitoring'
@@ -22,29 +24,35 @@ class SaleMonitoring(models.Model):
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""
- CREATE OR REPLACE VIEW %s AS (
- SELECT
- smd.sale_order_id AS id,
- smd.date_order,
- smd.sale_order_id,
- smd.partner_id,
- smd.user_id,
- SUM(smd.qty_so) AS qty_so,
- SUM(smd.qty_po) AS qty_po,
- SUM(smd.qty_po_received) AS qty_po_received,
- SUM(smd.qty_so_delivered) AS qty_so_delivered,
- SUM(smd.qty_so_invoiced) AS qty_so_invoiced,
- CASE
- WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali'
- WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full'
- WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali'
- WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full'
- WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM'
- WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA'
- ELSE 'Belum Invoiced'
- END AS status,
- get_po_number(smd.sale_order_id) as po_number
- FROM sale_monitoring_detail smd
- GROUP BY smd.date_order, smd.sale_order_id, smd.partner_id, smd.user_id
- )
+ CREATE OR REPLACE VIEW %s AS (
+ SELECT
+ smd.sale_order_id AS id,
+ smd.date_order,
+ smd.sale_order_id,
+ smd.partner_id,
+ smd.user_id,
+ SUM(smd.qty_so) AS qty_so,
+ SUM(smd.qty_po) AS qty_po,
+ SUM(smd.qty_po_received) AS qty_po_received,
+ SUM(smd.qty_so_delivered) AS qty_so_delivered,
+ SUM(smd.qty_so_invoiced) AS qty_so_invoiced,
+ CASE
+ WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali'
+ WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full'
+ WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali'
+ WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full'
+ WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM'
+ WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA'
+ ELSE 'Belum Invoiced'
+ END AS status,
+ get_po_number(smd.sale_order_id) as po_number
+ FROM sale_monitoring_detail smd
+ GROUP BY smd.date_order, smd.sale_order_id, smd.partner_id, smd.user_id
+ )
""" % self._table)
+
+ def action_refresh(self):
+ _logger.info("Refresh %s View Starting..." % self._table)
+ self.env.cr.execute("REFRESH MATERIALIZED VIEW sale_monitoring_detail")
+ _logger.info("Refresh %s View Success" % self._table)
+ \ No newline at end of file
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py
index d766cecd..553ec21f 100755
--- a/indoteknik_custom/models/sale_monitoring_detail.py
+++ b/indoteknik_custom/models/sale_monitoring_detail.py
@@ -1,4 +1,7 @@
from odoo import fields, models, api, tools
+import logging
+
+_logger = logging.getLogger(__name__)
class SaleMonitoringDetail(models.Model):
@@ -20,45 +23,62 @@ class SaleMonitoringDetail(models.Model):
status = fields.Char(string="Status")
def init(self):
- tools.drop_view_if_exists(self.env.cr, self._table)
+ self._drop_view()
+ self.env.cr.execute("SELECT matviewname from pg_matviews where schemaname = 'public' and matviewname = '%s'" % self._table)
+ materialized_view = self.env.cr.fetchone()
+ if materialized_view is None:
+ self._init_materialized_view()
+
+ def action_refresh(self):
+ _logger.info("Refresh %s View Starting..." % self._table)
+ self.env.cr.execute("REFRESH MATERIALIZED VIEW %s" % self._table)
+ _logger.info("Refresh %s View Success" % self._table)
+
+ def _drop_view(self):
+ self.env.cr.execute("SELECT viewname from pg_views where schemaname = 'public' and viewname = '%s'" % self._table)
+ standard_view = self.env.cr.fetchone()
+ if standard_view is not None:
+ self.env.cr.execute("DROP VIEW %s CASCADE" % self._table)
+
+ def _init_materialized_view(self):
self.env.cr.execute("""
- CREATE OR REPLACE VIEW %s AS (
- SELECT
- *,
- CASE
- WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali'
- WHEN qty_po < qty_so THEN 'Belum PO full'
- WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali'
- WHEN qty_po_received < qty_so THEN 'Belum Received full'
- WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM'
- WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA'
- ELSE 'Belum Invoiced'
- END AS status
- FROM
- (
+ CREATE MATERIALIZED VIEW %s AS (
SELECT
- sol.id AS id,
- so.id AS sale_order_id,
- so.partner_id as partner_id,
- so.user_id,
- p.id AS product_id,
- sol.product_uom_qty AS qty_so,
- sol.qty_delivered AS qty_so_delivered,
- get_qty_to_delivered(sol.id) as qty_to_delivered,
- sol.qty_invoiced AS qty_so_invoiced,
- so.date_order AS date_order,
- get_qty_po(so.id, sol.product_id) AS qty_po,
- get_qty_received(so.id, sol.product_id) AS qty_po_received
- FROM sale_order so
- JOIN sale_order_line sol ON sol.order_id = so.id
- JOIN product_product p ON p.id = sol.product_id
- JOIN product_template pt ON pt.id = p.product_tmpl_id
- WHERE pt.type IN ('consu','product')
- AND so.state IN ('sale','done')
- AND so.create_date >= '2022-08-10'
- ) a
- WHERE
- a.qty_so_delivered > a.qty_so_invoiced
- or a.qty_to_delivered > 0
- )
+ *,
+ CASE
+ WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali'
+ WHEN qty_po < qty_so THEN 'Belum PO full'
+ WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali'
+ WHEN qty_po_received < qty_so THEN 'Belum Received full'
+ WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM'
+ WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA'
+ ELSE 'Belum Invoiced'
+ END AS status
+ FROM
+ (
+ SELECT
+ sol.id AS id,
+ so.id AS sale_order_id,
+ so.partner_id as partner_id,
+ so.user_id,
+ p.id AS product_id,
+ sol.product_uom_qty AS qty_so,
+ sol.qty_delivered AS qty_so_delivered,
+ get_qty_to_delivered(sol.id) as qty_to_delivered,
+ sol.qty_invoiced AS qty_so_invoiced,
+ so.date_order AS date_order,
+ get_qty_po(so.id, sol.product_id) AS qty_po,
+ get_qty_received(so.id, sol.product_id) AS qty_po_received
+ FROM sale_order so
+ JOIN sale_order_line sol ON sol.order_id = so.id
+ JOIN product_product p ON p.id = sol.product_id
+ JOIN product_template pt ON pt.id = p.product_tmpl_id
+ WHERE pt.type IN ('consu','product')
+ AND so.state IN ('sale','done')
+ AND so.create_date >= '2022-08-10'
+ ) a
+ WHERE
+ a.qty_so_delivered > a.qty_so_invoiced
+ or a.qty_to_delivered > 0
+ )
""" % self._table)
diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml
index 025e5d26..b3b186e9 100755
--- a/indoteknik_custom/views/sale_monitoring.xml
+++ b/indoteknik_custom/views/sale_monitoring.xml
@@ -4,7 +4,10 @@
<field name="name">sale.monitoring.tree</field>
<field name="model">sale.monitoring</field>
<field name="arch" type="xml">
- <tree create="false">
+ <tree create="false" multi_edit="1">
+ <header>
+ <button name="action_refresh" string="Refresh" class="oe_highlight" type="object" />
+ </header>
<field name="date_order"/>
<field name="sale_order_id"/>
<field name="partner_id"/>
diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml
index 9e4734d3..d22f0a13 100755
--- a/indoteknik_custom/views/sale_monitoring_detail.xml
+++ b/indoteknik_custom/views/sale_monitoring_detail.xml
@@ -4,7 +4,10 @@
<field name="name">sale.monitoring.detail.tree</field>
<field name="model">sale.monitoring.detail</field>
<field name="arch" type="xml">
- <tree create="false">
+ <tree create="false" multi_edit="1">
+ <header>
+ <button name="action_refresh" string="Refresh" class="oe_highlight" type="object" />
+ </header>
<field name="date_order"/>
<field name="sale_order_id"/>
<field name="partner_id"/>