summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-04-11 13:57:01 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-04-11 13:57:01 +0700
commit000a7fa68a738843c443145c1a8d102783e04fac (patch)
tree04b7c6bf423ce0cf93ea4a526408d71426caaf9e
parentd1b86303b0934c9f6348e7016822d449349540d3 (diff)
parent3b5871b8c364e819a2fbaf268e4693e848e6af0a (diff)
Merge branch 'release' into flashsale-solr
-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/__manifest__.py1
-rw-r--r--indoteknik_custom/models/automatic_purchase.py6
-rw-r--r--indoteknik_custom/models/ip_lookup.py37
-rw-r--r--indoteknik_custom/models/res_partner.py6
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py1
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv3
-rw-r--r--indoteknik_custom/views/group_partner.xml55
-rw-r--r--indoteknik_custom/views/res_partner.xml1
15 files changed, 215 insertions, 11 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 8c60ce43..409b69c2 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/__manifest__.py b/indoteknik_custom/__manifest__.py
index 5873d73a..6e67afe1 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -11,6 +11,7 @@
'depends': ['base', 'coupon', 'delivery', 'sale', 'sale_management', 'vit_kelurahan'],
'data': [
'security/ir.model.access.csv',
+ 'views/group_partner.xml',
'views/blog_post.xml',
'views/coupon_program.xml',
'views/delivery_order.xml',
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 60444b6a..eea66b99 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -45,7 +45,7 @@ class AutomaticPurchase(models.Model):
], order='brand_id')
count = brand_id = 0
for product in products_vendors:
- if vendor.id == 5571 and (count == 200 or brand_id != product.brand_id.id):
+ if count == 200 or brand_id != product.brand_id.id:
count = 0
counter_po_number += 1
new_po = self.env['purchase.order'].create([param_header])
@@ -55,8 +55,8 @@ class AutomaticPurchase(models.Model):
'order_id': new_po.id
}])
self.env.cr.commit()
- else:
- new_po = self.env['purchase.order'].create([param_header])
+ # else:
+ # new_po = self.env['purchase.order'].create([param_header])
brand_id = product.brand_id.id
count += 10
param_line = {
diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py
index 0fbb03ea..244982c0 100644
--- a/indoteknik_custom/models/ip_lookup.py
+++ b/indoteknik_custom/models/ip_lookup.py
@@ -41,12 +41,38 @@ class IpLookup(models.Model):
logs = self.env['ip.lookup.line'].search(domain, limit=45, order='create_date asc')
for log in logs:
try:
- ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json()
- del ipinfo['status']
- log.lookup = json.dumps(ipinfo, indent=4, sort_keys=True)
+ query = [
+ ('ip_address', '=', log.ip_address),
+ ('lookup', '!=', False)
+ ]
+ last_data = self.env['ip.lookup.line'].search(query, limit=1)
+ if last_data:
+ log.lookup = last_data.lookup
+ country = json.loads(last_data.lookup)['country']
+ timezone = json.loads(last_data)['timezone']
+ else:
+ ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json()
+ del ipinfo['status']
+ lookup_json = json.dumps(ipinfo, indent=4, sort_keys=True)
+ log.lookup = lookup_json
+ country = json.loads(lookup_json)['country']
+ timezone = json.loads(lookup_json)['timezone']
+ log.country = country
+ log.timezone = timezone
+ log.continent = timezone.split('/')[0]
except:
- log.lookup = ''
+ # log.lookup = ''
+ _logger.info('Failed parsing IP Lookup Line %s' % log.id)
+ def _load_info_address_lookup(self):
+ lines = self.env['ip.lookup.line'].search([('country', '=', False), ('lookup', '!=', False)], limit=500)
+ for line in lines:
+ line.country = json.loads(line.lookup)['country']
+ timezone = json.loads(line.lookup)['timezone']
+ continent = timezone.split('/')[0]
+ line.timezone = timezone
+ line.continent = continent
+ _logger.info('Success parsing ip lookup line id %s' % line.id)
class IpLookupLine(models.Model):
_name = 'ip.lookup.line'
@@ -56,4 +82,5 @@ class IpLookupLine(models.Model):
ip_address = fields.Char(string='IP Address')
lookup = fields.Char(string='Lookup')
country = fields.Char(string='Country')
-
+ timezone = fields.Char(string='Timezone')
+ continent = fields.Char(string='Continent', help='diparsing dari field timezone')
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index ad88957f..eaf93717 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -1,5 +1,9 @@
from odoo import models, fields
+class GroupPartner(models.Model):
+ _name = 'group.partner'
+
+ name = fields.Char(string='Name')
class ResPartner(models.Model):
_inherit = 'res.partner'
@@ -7,3 +11,5 @@ class ResPartner(models.Model):
reference_number = fields.Char(string="Reference Number")
company_type_id = fields.Many2one('res.partner.company_type', string='Company Type')
custom_pricelist_id = fields.Many2one('product.pricelist', string='Price Matrix')
+ group_partner_id = fields.Many2one('group.partner', string='Group Partner')
+
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py
index 553ec21f..82bd5c48 100755
--- a/indoteknik_custom/models/sale_monitoring_detail.py
+++ b/indoteknik_custom/models/sale_monitoring_detail.py
@@ -76,6 +76,7 @@ class SaleMonitoringDetail(models.Model):
WHERE pt.type IN ('consu','product')
AND so.state IN ('sale','done')
AND so.create_date >= '2022-08-10'
+ and sol.product_uom_qty > get_qty_available(sol.product_id)
) a
WHERE
a.qty_so_delivered > a.qty_so_invoiced
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 1788c77f..f7de6d3f 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -44,4 +44,5 @@ access_uangmuka_pembelian,access.uangmuka.pembelian,model_uangmuka_pembelian,,1,
access_automatic_purchase,access.automatic.purchase,model_automatic_purchase,,1,1,1,1
access_automatic_purchase_line,access.automatic.purchase.line,model_automatic_purchase_line,,1,1,1,1
access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_purchase_match,,1,1,1,1
-access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1 \ No newline at end of file
+access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1
+access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/group_partner.xml b/indoteknik_custom/views/group_partner.xml
new file mode 100644
index 00000000..4d5fd923
--- /dev/null
+++ b/indoteknik_custom/views/group_partner.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<odoo>
+ <record id="group_partner_tree" model="ir.ui.view">
+ <field name="name">group.partner.tree</field>
+ <field name="model">group.partner</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="name"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="group_partner_form" model="ir.ui.view">
+ <field name="name">group.partner.form</field>
+ <field name="model">group.partner</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="name"/>
+ </group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="view_group_partner_filter" model="ir.ui.view">
+ <field name="name">group.partner.list.select</field>
+ <field name="model">group.partner</field>
+ <field name="priority" eval="15"/>
+ <field name="arch" type="xml">
+ <search string="Search Name">
+ <field name="name"/>
+ </search>
+ </field>
+ </record>
+
+ <record id="group_partner_action" model="ir.actions.act_window">
+ <field name="name">Group Partner</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">group.partner</field>
+ <field name="search_view_id" ref="view_group_partner_filter"/>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_group_partner"
+ name="Group Partner"
+ parent="contacts.res_partner_menu_config"
+ sequence="5"
+ action="group_partner_action"
+ />
+</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml
index 47f41ab2..a9372da0 100644
--- a/indoteknik_custom/views/res_partner.xml
+++ b/indoteknik_custom/views/res_partner.xml
@@ -11,6 +11,7 @@
</field>
<field name="industry_id" position="after">
<field name="company_type_id"/>
+ <field name="group_partner_id"/>
</field>
</field>
</record>