summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-04-10 09:57:49 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-04-10 09:57:49 +0700
commit9768f8733053df18d9510fcab1cbeea66fa62e6e (patch)
treea4763e268cfd99b3874d571fe78cdf9ebfb44c2e
parent404db39b3f80c538e202e1fe728fd043cecaf7c8 (diff)
parent0dce304f59a437b369ff94a2ce31fbfe2f1e0258 (diff)
Merge branch 'release' into staging
-rw-r--r--indoteknik_api/controllers/__init__.py3
-rw-r--r--indoteknik_api/controllers/api_v1/product.py1
-rw-r--r--indoteknik_api/controllers/api_v2/__init__.py2
-rw-r--r--indoteknik_api/controllers/api_v2/product.py21
-rw-r--r--indoteknik_api/controllers/api_v2/product_variant.py22
-rw-r--r--indoteknik_api/models/product_product.py20
-rw-r--r--indoteknik_api/models/product_template.py47
-rwxr-xr-xindoteknik_custom/models/crm_lead.py12
-rwxr-xr-xindoteknik_custom/models/sale_order.py34
-rwxr-xr-xindoteknik_custom/views/sale_order.xml1
10 files changed, 151 insertions, 12 deletions
diff --git a/indoteknik_api/controllers/__init__.py b/indoteknik_api/controllers/__init__.py
index 30664b92..01dde20f 100644
--- a/indoteknik_api/controllers/__init__.py
+++ b/indoteknik_api/controllers/__init__.py
@@ -1,2 +1,3 @@
from . import controller
-from . import api_v1 \ No newline at end of file
+from . import api_v1
+from . import api_v2 \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 736fd68e..54b039c7 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -4,7 +4,6 @@ from odoo.http import request
from datetime import datetime, timedelta
import ast
import logging
-import math
_logger = logging.getLogger(__name__)
diff --git a/indoteknik_api/controllers/api_v2/__init__.py b/indoteknik_api/controllers/api_v2/__init__.py
new file mode 100644
index 00000000..24f11c3d
--- /dev/null
+++ b/indoteknik_api/controllers/api_v2/__init__.py
@@ -0,0 +1,2 @@
+from . import product
+from . import product_variant \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v2/product.py b/indoteknik_api/controllers/api_v2/product.py
new file mode 100644
index 00000000..772906f6
--- /dev/null
+++ b/indoteknik_api/controllers/api_v2/product.py
@@ -0,0 +1,21 @@
+from .. import controller
+from odoo import http
+from odoo.http import request
+
+class V2Product(controller.Controller):
+ prefix = '/api/v2/'
+
+ @http.route(prefix + 'product/<id>', auth='public', methods=['GET'])
+ @controller.Controller.must_authorized()
+ def v2_get_product_by_id(self, **kw):
+ id = kw.get('id')
+ if not id:
+ return self.response(code=400, description='id is required')
+
+ data = []
+ id = [int(x) for x in id.split(',')]
+ product_templates = request.env['product.template'].search([('id', 'in', id)])
+ if product_templates:
+ data = [request.env['product.template'].v2_api_single_response(x, with_detail='DEFAULT') for x in product_templates]
+
+ return self.response(data) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v2/product_variant.py b/indoteknik_api/controllers/api_v2/product_variant.py
new file mode 100644
index 00000000..b74e4936
--- /dev/null
+++ b/indoteknik_api/controllers/api_v2/product_variant.py
@@ -0,0 +1,22 @@
+from .. import controller
+from odoo import http
+from odoo.http import request
+
+class V2ProductVariant(controller.Controller):
+ prefix = '/api/v2/'
+
+ @http.route(prefix + 'product_variant/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def v2_get_product_variant_by_id(self, **kw):
+ id = kw.get('id')
+ if not id:
+ return self.response(code=400, description='id is required')
+
+ data = []
+ id = [int(x) for x in id.split(',')]
+ product_products = request.env['product.product'].search([('id', 'in', id)])
+ if product_products:
+ data = [request.env['product.product'].v2_api_single_response(x) for x in product_products]
+
+ return self.response(data)
+
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 284900de..c867eaa0 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -19,6 +19,26 @@ class ProductProduct(models.Model):
'code': product_product.default_code or '',
'name': product_product.display_name,
'price': self.env['product.pricelist'].compute_price(product_pricelist_default_discount_id, product_product.id),
+ 'stock': product_product.qty_stock_vendor,
+ 'weight': product_product.weight,
+ 'attributes': [x.name for x in product_product.product_template_attribute_value_ids],
+ 'manufacture' : self.api_manufacture(product_product)
+ }
+ return data
+
+ def v2_api_single_response(self, product_product):
+ product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
+ product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
+ product_template = product_product.product_tmpl_id
+ data = {
+ 'id': product_product.id,
+ 'parent': {
+ 'id': product_template.id,
+ 'name': product_template.name,
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id),
+ },
+ 'code': product_product.default_code or '',
+ 'name': product_product.display_name,
'price': {
'price': product_product._get_website_price_exclude_tax(),
'discount_percentage': product_product._get_website_disc(0),
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 72dda17f..4d16727f 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -51,6 +51,53 @@ class ProductTemplate(models.Model):
data.update(data_with_detail)
return data
+ def v2_api_single_response(self, product_template, with_detail=''):
+ product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id')
+ product_pricelist_default_discount_id = int(product_pricelist_default_discount_id)
+ data = {
+ 'id': product_template.id,
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id),
+ 'code': product_template.default_code or '',
+ 'name': product_template.name,
+ 'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default_discount_id),
+ 'variant_total': len(product_template.product_variant_ids),
+ 'stock_total': product_template.qty_stock_vendor,
+ 'weight': product_template.weight,
+ 'manufacture': self.api_manufacture(product_template),
+ 'categories': self.api_categories(product_template),
+ }
+
+ if with_detail != '':
+ data_with_detail = {
+ 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id),
+ 'display_name': product_template.display_name,
+ 'variants': [self.env['product.product'].v2_api_single_response(variant) for variant in product_template.product_variant_ids],
+ 'description': product_template.website_description or '',
+ }
+ data.update(data_with_detail)
+
+ if with_detail == 'SOLR':
+ is_image_found = self.env['ir.attachment'].is_found('product.template', 'image_128', product_template.id)
+ rate = 0
+ if data['lowest_price']['price'] > 0:
+ rate += 1
+ if product_template.have_promotion_program:
+ rate += 1
+ if is_image_found:
+ rate += 1
+ if product_template.website_description:
+ rate += 1
+ if product_template.qty_stock_vendor > 0:
+ rate += 1
+ data_with_detail = {
+ 'solr_flag': product_template.solr_flag,
+ 'product_rating': rate,
+ 'search_rank': product_template.search_rank,
+ 'search_rank_weekly': product_template.search_rank_weekly
+ }
+ data.update(data_with_detail)
+ return data
+
def api_manufacture(self, product_template):
if product_template.x_manufacture:
manufacture = product_template.x_manufacture
diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py
index 74b4796a..b34183d8 100755
--- a/indoteknik_custom/models/crm_lead.py
+++ b/indoteknik_custom/models/crm_lead.py
@@ -57,9 +57,9 @@ class CrmLead(models.Model):
if not lead.partner_id:
continue
-
- if lead.partner_id.parent_id:
- salesperson_id = lead.partner_id.parent_id.user_id
- else:
- salesperson_id = lead.partner_id.user_id
- lead.user_id = salesperson_id
+ if not lead.user_id or lead.user_id == 2:
+ if lead.partner_id.parent_id:
+ salesperson_id = lead.partner_id.parent_id.user_id
+ else:
+ salesperson_id = lead.partner_id.user_id
+ lead.user_id = salesperson_id
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index fa5f3b6a..4768f31c 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -71,6 +71,7 @@ class SaleOrder(models.Model):
date_doc_kirim = fields.Datetime(string='Tanggal Kirim di SJ', help="Tanggal Kirim di cetakan SJ yang terakhir, tidak berpengaruh ke Accounting")
payment_type = fields.Char(string='Payment Type', help='Jenis pembayaran dengan Midtrans')
gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans')
+ notification = fields.Char(string='Notification', help='Dapat membantu error dari approval')
@api.model
def _generate_so_access_token(self, limit=50):
@@ -195,7 +196,6 @@ class SaleOrder(models.Model):
def check_due(self):
"""To show the due amount and warning stage"""
for order in self:
- # partner_id = 0aku
if order.partner_id.parent_id:
partner_id = order.partner_id.parent_id
else:
@@ -255,7 +255,9 @@ class SaleOrder(models.Model):
raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval'))
if order.total_percent_margin <= 15 and not self.env.user.is_leader:
order.approval_status = 'pengajuan2'
- elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager:
+ elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager:
+ order.approval_status = 'pengajuan1'
+ elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager:
order.approval_status = 'pengajuan1'
else:
raise UserError("Bisa langsung Confirm")
@@ -291,17 +293,41 @@ class SaleOrder(models.Model):
raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval'))
if order.total_percent_margin <= 15 and not self.env.user.is_leader:
raise UserError("Harus diapprove oleh Pimpinan")
- elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager:
+ elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager:
raise UserError("Harus diapprove oleh Manager")
+ elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager:
+ raise UserError("Ada invoice due date, harus diapprove oleh Manager")
else:
order.approval_status = 'approved'
order.calculate_line_no()
return res
+ def _have_outstanding_invoices(self):
+ partner_id = self.partner_id
+ if self.partner_id.parent_id:
+ partner_id = self.partner_id
+ partners = []
+ partners += partner_id.child_ids
+ partners.append(partner_id)
+ for partner in partners:
+ query = [
+ ('partner_id', '=', partner.id),
+ ('state', '=', 'posted'),
+ ('move_type', '=', 'out_invoice'),
+ ('amount_residual_signed', '>', 0)
+ ]
+ invoices = self.env['account.move'].search(query)
+ for invoice in invoices:
+ if invoice.invoice_day_to_due < 0:
+ self.notification = 'Ada %s yang sudah jatuh tempo dan belum lunas' % invoice.name
+ # self.env.cr.commit()
+ return True
+
+
def compute_total_margin(self):
for order in self:
- total_margin = total_percent_margin = sum_sales_price = 0
+ total_margin = total_percent_margin = 0
for line in order.order_line:
if not line.product_id:
order.total_margin = 0
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 203b2d13..a1120137 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -33,6 +33,7 @@
</field>
<field name="source_id" position="after">
<field name="date_doc_kirim" readonly="1"/>
+ <field name="notification" readonly="1"/>
</field>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="attributes">
<attribute name="attrs">