summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-10-06 08:59:52 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-10-06 08:59:52 +0700
commitd3a28f88b3b94123a3db4ae0873c7e157bbb13f8 (patch)
treec2a383be583f41d80f98ee78fddf0641f1ebefbe /indoteknik_custom
parent3d20a65942b64f252a10bada016042a3e1fc498a (diff)
parent1c18f6c7438537a60f181d089df06a0b4ba915f9 (diff)
Merge commit '1c18f6c7438537a60f181d089df06a0b4ba915f9'
Diffstat (limited to 'indoteknik_custom')
-rwxr-xr-xindoteknik_custom/__init__.py1
-rwxr-xr-xindoteknik_custom/__manifest__.py2
-rw-r--r--indoteknik_custom/controllers/__init__.py2
-rw-r--r--indoteknik_custom/controllers/api/__init__.py2
-rw-r--r--indoteknik_custom/controllers/api/product.py95
-rw-r--r--indoteknik_custom/controllers/api/sale_order.py110
-rw-r--r--indoteknik_custom/controllers/api_controller.py51
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/product_pricelist.py12
-rwxr-xr-xindoteknik_custom/models/sale_monitoring.py12
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py73
-rw-r--r--indoteknik_custom/views/product_pricelist.xml28
-rwxr-xr-xindoteknik_custom/views/product_pricelist_item.xml37
-rwxr-xr-xindoteknik_custom/views/sale_order.xml6
14 files changed, 126 insertions, 306 deletions
diff --git a/indoteknik_custom/__init__.py b/indoteknik_custom/__init__.py
index 38718f08..0650744f 100755
--- a/indoteknik_custom/__init__.py
+++ b/indoteknik_custom/__init__.py
@@ -1,2 +1 @@
from . import models
-from . import controllers \ No newline at end of file
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 0d6da7f1..a00f4ccd 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -14,6 +14,8 @@
'views/blog_post.xml',
'views/coupon_program.xml',
'views/delivery_order.xml',
+ 'views/product_pricelist.xml',
+ 'views/product_pricelist_item.xml',
'views/product_public_category.xml',
'views/product_template.xml',
'views/purchase_order.xml',
diff --git a/indoteknik_custom/controllers/__init__.py b/indoteknik_custom/controllers/__init__.py
deleted file mode 100644
index 2fd318df..00000000
--- a/indoteknik_custom/controllers/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-from . import api_controller
-from . import api
diff --git a/indoteknik_custom/controllers/api/__init__.py b/indoteknik_custom/controllers/api/__init__.py
deleted file mode 100644
index bd901bd4..00000000
--- a/indoteknik_custom/controllers/api/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-from . import sale_order
-from . import product
diff --git a/indoteknik_custom/controllers/api/product.py b/indoteknik_custom/controllers/api/product.py
deleted file mode 100644
index 3b1c4ce8..00000000
--- a/indoteknik_custom/controllers/api/product.py
+++ /dev/null
@@ -1,95 +0,0 @@
-import base64
-
-from .. import api_controller
-from odoo import http
-from odoo.http import request
-
-
-class ProductApi(api_controller.ApiController):
- @http.route('/api/product/search', auth='public', methods=['GET'])
- def search_product(self, **kw):
- self.authenticate(kw)
- query = kw.get('query')
- if not query:
- return self.response(code=400, description='Field query is required')
-
- query = '%' + query.replace(' ', '%') + '%'
- domain = [
- ('sale_ok', '=', True),
- '|',
- ('default_code', 'ilike', query),
- ('name', 'ilike', query)
- ]
-
- manufactures = kw.get('manufactures')
- if manufactures:
- manufactures = [int(x) for x in manufactures.split(',')]
- domain.append(('x_manufacture', 'in', manufactures))
-
- categories = kw.get('categories')
- if categories:
- categories = [int(x) for x in categories.split(',')]
- domain.append(('public_categ_ids', 'child_of', categories))
-
- product_variants = request.env['product.product'].search(domain)
- product_variant_ids = [v['id'] for v in product_variants]
-
- base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
- domain = [
- ('product_variant_ids', 'in', product_variant_ids)
- ]
- product_templates = self.search_with_api_params('product.template', kw, domain)
- data = {
- 'total_records': len(request.env['product.template'].search(domain)),
- 'products': []
- }
- for product_template in product_templates:
- stock = 0
- for product_variant in product_template.product_variant_ids:
- stock += product_variant.qty_stock_vendor
-
- discount_price = 0
- price = product_template.web_price
- if price > 0:
- if product_template.taxes_id:
- if not product_template.taxes_id.price_include:
- price += (price * product_template.taxes_id.amount / 100)
- else:
- price += (price * 11 / 100)
-
- promotion = {}
- manufacture = {}
- if product_template.x_manufacture:
- manufacture.update({
- 'id': product_template.x_manufacture.id,
- 'name': product_template.x_manufacture.x_name,
- })
- domain = [
- ('rule_products_domain', 'ilike', product_template.x_manufacture.x_name),
- ('active', '=', True)
- ]
- coupon_program = request.env['coupon.program'].search(domain, limit=1)
- if coupon_program:
- discount_price = price - (price * coupon_program.discount_percentage / 100)
- icon_1 = (base_url + 'api/image/coupon.program/x_studio_field_Ifopn/' + str(coupon_program.id)) if coupon_program.x_studio_field_Ifopn else ''
- icon_2 = (base_url + 'api/image/coupon.program/x_studio_field_2Ul77/' + str(coupon_program.id)) if coupon_program.x_studio_field_2Ul77 else ''
- promotion.update({
- 'name': coupon_program.name,
- 'discount_percentage': coupon_program.discount_percentage,
- 'icon_1': icon_1,
- 'icon_2': icon_2
- })
-
- data['products'].append({
- 'id': product_template.id,
- 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '',
- 'name': product_template.name,
- 'price': price,
- 'discount_price': discount_price,
- 'total_variant': len(product_template.product_variant_ids),
- 'stock': stock,
- 'manufacture': manufacture,
- 'promotion': promotion,
- })
-
- return self.response(data)
diff --git a/indoteknik_custom/controllers/api/sale_order.py b/indoteknik_custom/controllers/api/sale_order.py
deleted file mode 100644
index c00a94d3..00000000
--- a/indoteknik_custom/controllers/api/sale_order.py
+++ /dev/null
@@ -1,110 +0,0 @@
-from .. import api_controller
-from odoo import http
-from odoo.http import request
-
-
-class SaleOrderApi(api_controller.ApiController):
- @http.route('/api/sale_order/invoiced', auth='public', methods=['GET'])
- def get_sale_order_invoiced_by_partner_id(self, **kw):
- self.authenticate(kw)
- partner_id = kw.get('partner_id')
- if not partner_id:
- return self.response(code=400, description='Field partner_id is required')
-
- partner_id = int(partner_id)
- # Get company member by partner_id
- parent_partner_id = request.env['res.partner'].search([('id', '=', partner_id)], limit=1).parent_id.id
- partner_childs = request.env['res.partner'].search([('parent_id', '=', int(parent_partner_id))])
- partner_child_ids = [v['id'] for v in partner_childs] + [partner_id]
-
- # Get sale order by company member and invoiced
- data = []
- default_domain = [
- ('partner_id', 'in', partner_child_ids),
- '|',
- ('invoice_status', '=', 'invoiced'),
- ('invoice_status', '=', 'to_invoice')
- ]
- sale_orders = self.search_with_api_params('sale.order', kw, default_domain)
- for sale_order in sale_orders:
- pickings = []
- for picking in sale_order.picking_ids:
- if picking.state in ['confirmed', 'assigned', 'done']:
- pickings.append({
- 'id': picking.id,
- 'name': picking.name,
- 'delivery_address': picking.partner_id.street,
- 'delivery_tracking_no': picking.delivery_tracking_no,
- 'delivery_status': picking.delivery_status
- })
-
- data.append({
- 'id': sale_order.id,
- 'name': sale_order.name,
- 'amount_total': sale_order.amount_total,
- 'salesperson': sale_order.user_id.name,
- 'date_order': self.time_to_str(sale_order.date_order, '%d/%m/%Y'),
- 'pickings': pickings,
- 'access_token': sale_order.access_token
- })
- return self.response(data)
-
- @http.route('/api/sale_order/invoiced/detail', auth='public', methods=['GET'])
- def get_sale_order_invoiced_detail_by_partner(self, **kw):
- self.authenticate(kw)
-
- id = kw.get('id')
- partner_id = kw.get('partner_id')
- if not id:
- return self.response(code=400, description='Field id is required')
- if not partner_id:
- return self.response(code=400, description='Field partner_id is required')
-
- default_domain = [
- ('id', '=', id),
- '|',
- ('invoice_status', '=', 'invoiced'),
- ('invoice_status', '=', 'to_invoice')
- ]
- parent_partner_id = request.env['res.partner'].search([('id', '=', int(partner_id))], limit=1).parent_id.id
- partner_childs = request.env['res.partner'].search([('parent_id', '=', int(parent_partner_id))])
- partner_child_ids = [v['id'] for v in partner_childs] + [int(partner_id)]
- default_domain.append(('partner_id', 'in', partner_child_ids))
-
- sale_order = self.search_with_api_params('sale.order', kw, default_domain)
- orders = []
- for order in sale_order.order_line:
- orders.append({
- 'name': order.name,
- 'product_qty': order.product_qty,
- 'price_unit': order.price_unit,
- 'price_tax': order.price_tax,
- 'price_total': order.price_total,
- 'price_subtotal': order.price_subtotal,
- 'tax': order.tax_id.name,
- 'discount': order.discount,
- })
-
- data = {
- 'id': sale_order.id,
- 'name': sale_order.name,
- 'carrier': sale_order.carrier_id.name,
- 'partner': {
- 'id': sale_order.partner_id.id,
- 'name': sale_order.partner_id.name,
- 'mobile': sale_order.partner_id.mobile,
- 'email': sale_order.partner_id.email
- },
- 'delivery_address': sale_order.partner_shipping_id.street,
- 'delivery_method': sale_order.carrier_id.name,
- 'payment_term': sale_order.payment_term_id.name,
- 'salesperson': sale_order.user_id.name,
- 'date_order': self.time_to_str(sale_order.date_order, '%d/%m/%Y %H:%M:%S'),
- 'note': sale_order.note,
- 'amount_untaxed': sale_order.amount_untaxed,
- 'amount_tax': sale_order.amount_tax,
- 'amount_total': sale_order.amount_total,
- 'orders': orders
- }
-
- return self.response(data)
diff --git a/indoteknik_custom/controllers/api_controller.py b/indoteknik_custom/controllers/api_controller.py
deleted file mode 100644
index faf8b640..00000000
--- a/indoteknik_custom/controllers/api_controller.py
+++ /dev/null
@@ -1,51 +0,0 @@
-import datetime
-import base64
-
-from odoo import http
-from odoo.http import request
-import json
-from pytz import timezone
-
-
-class ApiController(http.Controller):
- def authenticate(self, kw):
- db = kw.get('db')
- username = kw.get('username')
- password = kw.get('password')
- request.session.authenticate(db, username, password)
-
- def time_to_str(self, object, format):
- time = ''
- if isinstance(object, datetime.datetime):
- time = object.astimezone(timezone('Asia/Jakarta')).strftime(format)
- return time
-
- def response(self, data=[], code=200, description='OK'):
- response = {
- 'status': {
- 'code': code,
- 'description': description
- }
- }
- if code == 200:
- response.update({'result': data})
-
- response = json.dumps(response)
- return request.make_response(response, [('Content-Type', 'application/json')])
-
- def search_with_api_params(self, model: str, kw, domain=[]):
- limit = kw.get('limit', 0)
- offset = kw.get('offset', 0)
- order = kw.get('order', '')
- # domain = kw.get('domain', [])
- # if domain:
- # domain = json.loads(domain)
- # domain += default_domain
-
- return request.env[model].search(domain, limit=int(limit), offset=int(offset), order=order)
-
- @http.route('/api/image/<model>/<field>/<id>', auth='public', methods=['GET'])
- def get_image(self, model, field, id):
- model = request.env[model].sudo().search([('id', '=', id)], limit=1)
- image = model[field] if model[field] else ''
- return request.make_response(base64.b64decode(image), [('Content-Type', 'image/jpg')])
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 19916fd4..415cd380 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -24,4 +24,5 @@ from . import stock_move
from . import stock_picking
from . import stock_picking_type
from . import delivery_order
+from . import product_pricelist
from . import users
diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py
new file mode 100644
index 00000000..b70eb6e6
--- /dev/null
+++ b/indoteknik_custom/models/product_pricelist.py
@@ -0,0 +1,12 @@
+from odoo import models, fields, api
+from odoo.exceptions import UserError
+
+
+class ProductPricelist(models.Model):
+ _inherit = 'product.pricelist'
+
+ is_flash_sale = fields.Boolean(string='Flash Sale', default=False)
+ banner = fields.Binary(string='Banner')
+ start_date = fields.Datetime(string='Start Date')
+ end_date = fields.Datetime(string='End Date')
+
diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py
index 2ef23f39..a837a6bc 100755
--- a/indoteknik_custom/models/sale_monitoring.py
+++ b/indoteknik_custom/models/sale_monitoring.py
@@ -35,12 +35,12 @@ class SaleMonitoring(models.Model):
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_po) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali'
- WHEN SUM(qty_po_received) <> SUM(qty_po) THEN 'Belum Received full'
- WHEN SUM(qty_so_delivered) <> SUM(qty_so) AND SUM(qty_so_delivered) <= 0 THEN 'SIAP KIRIM'
- WHEN SUM(qty_so_delivered) <> SUM(qty_so) THEN 'KIRIM SISANYA'
+ 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
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py
index d80ec99b..843c7348 100755
--- a/indoteknik_custom/models/sale_monitoring_detail.py
+++ b/indoteknik_custom/models/sale_monitoring_detail.py
@@ -23,41 +23,42 @@ class SaleMonitoringDetail(models.Model):
tools.drop_view_if_exists(self.env.cr, self._table)
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
+ (
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_po and qty_po_received <= 0 THEN 'Belum Received sama sekali'
- WHEN qty_po_received <> qty_po THEN 'Belum Received full'
- WHEN qty_so_delivered <> qty_so AND qty_so_delivered <= 0 THEN 'SIAP KIRIM'
- WHEN qty_so_delivered <> qty_so THEN 'KIRIM SISANYA'
- ELSE 'Belum Invoiced'
- END AS status
- FROM
- (
- SELECT
- p.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,
- 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 <> a.qty_so_delivered
- OR a.qty_so <> a.qty_so_invoiced
- )
+ p.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/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml
new file mode 100644
index 00000000..18e9835a
--- /dev/null
+++ b/indoteknik_custom/views/product_pricelist.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="product_pricelist_view_inherit" model="ir.ui.view">
+ <field name="name">product.pricelist.view.inherit</field>
+ <field name="model">product.pricelist</field>
+ <field name="inherit_id" ref="product.product_pricelist_view"/>
+ <field name="arch" type="xml">
+ <field name="company_id" position="after">
+ <field name="is_flash_sale"/>
+ </field>
+ <group name="pricelist_settings" position="after">
+ <group name="flash_sale_setting">
+ <field name="banner" widget="image" attrs="{
+ 'invisible': [('is_flash_sale', '=', False)]
+ }" />
+ <field name="start_date" attrs="{
+ 'invisible': [('is_flash_sale', '=', False)],
+ 'required': [('is_flash_sale', '=', True)]
+ }" />
+ <field name="end_date" attrs="{
+ 'invisible': [('is_flash_sale', '=', False)],
+ 'required': [('is_flash_sale', '=', True)]
+ }" />
+ </group>
+ </group>
+ </field>
+ </record>
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/product_pricelist_item.xml b/indoteknik_custom/views/product_pricelist_item.xml
new file mode 100755
index 00000000..94ba9e4f
--- /dev/null
+++ b/indoteknik_custom/views/product_pricelist_item.xml
@@ -0,0 +1,37 @@
+<odoo>
+ <data>
+ <record id="product_pricelist_item_action" model="ir.actions.act_window">
+ <field name="name">Product Pricelist Item</field>
+ <field name="res_model">product.pricelist.item</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <record id="product_pricelist_item_form_view_inherit" model="ir.ui.view">
+ <field name="name">product.pricelist.item.form.view.inherit</field>
+ <field name="model">product.pricelist.item</field>
+ <field name="inherit_id" ref="product.product_pricelist_item_form_view" />
+ <field name="arch" type="xml">
+ <field name="applied_on" position="before">
+ <field name="pricelist_id" />
+ </field>
+ </field>
+ </record>
+
+ <record id="product_pricelist_item_view_search_inherit" model="ir.ui.view">
+ <field name="name">product.pricelist.item.search.inherit</field>
+ <field name="model">product.pricelist.item</field>
+ <field name="inherit_id" ref="product.product_pricelist_item_view_search"/>
+ <field name="arch" type="xml">
+ <field name="pricelist_id" position="before">
+ <field name="product_id" string="Products"/>
+ </field>
+ </field>
+ </record>
+
+ <menuitem id="product_pricelist_item"
+ name="Pricelist Items"
+ parent="sale.product_menu_catalog"
+ sequence="2"
+ action="product_pricelist_item_action"/>
+ </data>
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 0abbae94..f83b2a6b 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -26,11 +26,11 @@
<field name="vendor_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
<field name="purchase_price" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
<field name="purchase_tax_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
- <field name="item_percent_margin" groups="sales_team.group_sale_manager"/>
+ <field name="item_percent_margin"/>
</xpath>
<field name="amount_total" position="after">
- <field name="total_margin" groups="sales_team.group_sale_manager"/>
- <field name="total_percent_margin" groups="sales_team.group_sale_manager"/>
+ <field name="total_margin"/>
+ <field name="total_percent_margin"/>
</field>
<field name="effective_date" position="after">
<field name="carrier_id"/>