From 3285da702db176851e78db9d8afe7af866c31b94 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 29 Apr 2023 10:37:22 +0700 Subject: add po id in procurement monitoring --- .../models/procurement_monitoring_detail.py | 16 +++++++++++++++- .../views/procurement_monitoring_detail.xml | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index 97d35faf..e9da8147 100644 --- a/indoteknik_custom/models/procurement_monitoring_detail.py +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -21,6 +21,20 @@ class SaleMonitoringDetail(models.Model): qty_po = fields.Integer(string='Qty PO') date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") + po_ids = fields.Many2many('purchase.order', string='PO', compute='_compute_po') + + def _compute_po(self): + for line in self: + query = [ + ('order_id.sale_order_id', '=', line.sale_order_id.id), + ('order_id.approval_status', '=', 'approved'), + ('product_id', '=', line.product_id.id), + ] + pos = self.env['purchase.order.line'].search(query) + po_ids = [] + for po in pos: + po_ids.append(po.order_id.id) + line.po_ids = po_ids def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -53,6 +67,6 @@ class SaleMonitoringDetail(models.Model): AND so.create_date >= '2022-08-10' and so.so_status not in ('terproses') ) a - where a.qty_po < a.qty_so + --where a.qty_po < a.qty_so ) """ % self._table) diff --git a/indoteknik_custom/views/procurement_monitoring_detail.xml b/indoteknik_custom/views/procurement_monitoring_detail.xml index b3785d14..8f3827c1 100644 --- a/indoteknik_custom/views/procurement_monitoring_detail.xml +++ b/indoteknik_custom/views/procurement_monitoring_detail.xml @@ -14,6 +14,7 @@ + Date: Tue, 2 May 2023 09:45:45 +0700 Subject: add status validation in procurement monitoring detail --- indoteknik_custom/models/procurement_monitoring_detail.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index e9da8147..6031e04a 100644 --- a/indoteknik_custom/models/procurement_monitoring_detail.py +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -43,7 +43,8 @@ class SaleMonitoringDetail(models.Model): SELECT *, a.qty_so-a.qty_reserved as qty_suggest, - case when a.qty_so-a.qty_reserved > 0 then 'harus beli' + case when a.qty_po >= a.qty_so then 'cukup' + when a.qty_so-a.qty_reserved > 0 then 'harus beli' else 'cukup' end as status FROM ( -- cgit v1.2.3 From 02d95b8fbc4faf0045d293514ce63de358fa7645 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 2 May 2023 15:16:54 +0700 Subject: add kurir rajaongkir --- indoteknik_api/controllers/api_v1/__init__.py | 1 + indoteknik_api/controllers/api_v1/courier.py | 26 +++++ indoteknik_custom/models/raja_ongkir.py | 8 ++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/raja_ongkir.xml | 152 +++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 indoteknik_api/controllers/api_v1/courier.py diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index 5d5f723b..d05cdf3a 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -23,3 +23,4 @@ from . import customer from . import content from . import midtrans from . import wati +from . import courier diff --git a/indoteknik_api/controllers/api_v1/courier.py b/indoteknik_api/controllers/api_v1/courier.py new file mode 100644 index 00000000..cd3e35c0 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/courier.py @@ -0,0 +1,26 @@ +from .. import controller +from odoo import http +from odoo.http import request + + +class Courier(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'courier', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_courier(self): + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + query = [ + ('publish', '=', True), + ] + + couriers = request.env['rajaongkir.kurir'].search(query) + data = [] + for courier in couriers: + data.append({ + 'id': courier.delivery_carrier_id.id, + 'name': courier.name, + 'image': base_url + 'api/image/rajaongkir.kurir/image/'+str(courier.id) + }) + return self.response(data) + \ No newline at end of file diff --git a/indoteknik_custom/models/raja_ongkir.py b/indoteknik_custom/models/raja_ongkir.py index a9ef2e83..fa02a6bf 100644 --- a/indoteknik_custom/models/raja_ongkir.py +++ b/indoteknik_custom/models/raja_ongkir.py @@ -4,6 +4,14 @@ import json _logger = logging.getLogger(__name__) +class Kurir(models.Model): + _name = 'rajaongkir.kurir' + + delivery_carrier_id = fields.Many2one('delivery.carrier', String='Odoo Carrier', help='dimapping dengan bawaan delivery carrier di odoo') + name = fields.Char(string='Name', help='nama kurir sesuai dengan data yang ada di API RajaOngkir') + publish = fields.Boolean(string='Publish') + image = fields.Binary(string='Image') + class State(models.Model): _inherit = 'res.country.state' diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 4abfa123..2a5d9879 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -46,4 +46,5 @@ access_automatic_purchase_line,access.automatic.purchase.line,model_automatic_pu 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 access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 -access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 \ No newline at end of file +access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 +access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/raja_ongkir.xml b/indoteknik_custom/views/raja_ongkir.xml index 4eb19b02..124a91ae 100644 --- a/indoteknik_custom/views/raja_ongkir.xml +++ b/indoteknik_custom/views/raja_ongkir.xml @@ -24,4 +24,156 @@ + + + + Kurir RajaOngkir + rajaongkir.kurir + + + + + + + + + + + + + Kurir RajaOngkir + ir.actions.act_window + rajaongkir.kurir + tree,form + + + + + + jne + 51 + True + + + pos + 53 + True + + + tiki + 54 + True + + + rpx + 55 + True + + + pandu + 56 + True + + + wahana + 7 + True + + + sicepat + 27 + True + + + jnt + 57 + True + + + pahala + 58 + True + + + sap + 59 + True + + + jet + 60 + True + + + indah + 61 + True + + + dse + 62 + True + + + slis + 63 + True + + + first + 64 + True + + + ncs + 65 + True + + + star + 66 + True + + + lion + 67 + True + + + idl + 68 + True + + + rex + 69 + True + + + ide + 70 + True + + + sentral + 71 + True + + + anteraja + 72 + True + + + jtl + 73 + True + + \ No newline at end of file -- cgit v1.2.3 From 515addbceca9df25b3aaf440e8687286620d603a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:09:11 +0700 Subject: update virtual product rating to solr --- indoteknik_custom/models/apache_solr.py | 2 +- indoteknik_custom/models/product_template.py | 63 +++++++++++++--------------- indoteknik_custom/views/product_template.xml | 1 + 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ebe516a0..72584a8f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -73,7 +73,7 @@ class ApacheSolr(models.Model): 'display_name_s': template.display_name, 'name_s': template.name, 'default_code_s': template.default_code or '', - 'product_rating_f': template.product_rating, + 'product_rating_f': template.virtual_rating, 'product_id_i': template.id, 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), 'price_f': price_excl, diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 74b4edb1..a43d8dc2 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -29,6 +29,7 @@ class ProductTemplate(models.Model): have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?") product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website", default=0.0) + virtual_rating = fields.Float('Virtual Rating', compute='_compute_virtual_rating', help="Column Virtual untuk product rating, digunakan oleh Solr", default=0.0) last_calculate_rating = fields.Datetime("Last Calculate Rating") web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0) virtual_qty = fields.Float(string='Virtual Qty', default=0) @@ -53,6 +54,21 @@ class ProductTemplate(models.Model): # vals['solr_flag'] = 2 # return super().write(vals) + def _compute_virtual_rating(self): + for product in self: + rate = 0 + if product.web_price: + rate += 1 + if product.have_promotion_program: #have discount from pricelist + rate += 1 + if product.image_128: + rate += 5 + if product.website_description: + rate += 1 + if product.product_variant_id.qty_stock_vendor > 0: + rate += 1 + product.virtual_rating = rate + def update_new_product(self): current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -111,21 +127,21 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 1), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) price = product_pricelist_item.fixed_price template.web_price = price def _have_promotion_program(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 4), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) discount = product_pricelist_item.price_discount if discount: template.have_promotion_program = True @@ -134,6 +150,7 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): + #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -141,51 +158,29 @@ class ProductTemplate(models.Model): delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ + '&','&', ('type', '=', 'product'), ('active', '=', True), + '|', ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), # ('id', '=', 22798), - ], limit=100) + ], limit=500) for product in products: # print("Calculate Rating Product ", product) _logger.info("Calculate Rating Product %s" % product.id) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) - rate = 0 - if product.web_price: - rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: - rate += 1 - if product.image_128: - rate += 1 - if product.website_description: - rate += 1 - if product_variant.qty_stock_vendor > 0: - rate += 1 - product.product_rating = rate - product.last_calculate_rating = current_time - - products = self.env['product.template'].search([ - ('type', '=', 'product'), - ('active', '=', True), - ('last_calculate_rating', '<', delta_time), - ], limit=100) - - for product in products: - print("Calculate Rating Product OutOfDate", product) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) + # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) rate = 0 if product.web_price: rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: + if product.have_promotion_program: #have discount from pricelist rate += 1 if product.image_128: - rate += 1 + rate += 5 if product.website_description: rate += 1 - if product_variant.qty_stock_vendor > 0: + if product.product_variant_id.qty_stock_vendor > 0: rate += 1 product.product_rating = rate product.last_calculate_rating = current_time diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 5fcb8b05..558805b1 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -53,6 +53,7 @@ + -- cgit v1.2.3 From 58395396f83290cd36b7faf693c0efafc726ad61 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:39:29 +0700 Subject: change rating product --- indoteknik_custom/models/product_template.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index a43d8dc2..49235ec7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -58,15 +58,15 @@ class ProductTemplate(models.Model): for product in self: rate = 0 if product.web_price: - rate += 1 + rate += 4 if product.have_promotion_program: #have discount from pricelist - rate += 1 - if product.image_128: rate += 5 + if product.image_128: + rate += 3 if product.website_description: rate += 1 if product.product_variant_id.qty_stock_vendor > 0: - rate += 1 + rate += 2 product.virtual_rating = rate def update_new_product(self): -- cgit v1.2.3 From 1b31655209df1642d5c6c5e1106c14debddaddfc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:52:28 +0700 Subject: add update product rating to solr --- indoteknik_custom/models/apache_solr.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 72584a8f..04f83532 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -1,19 +1,44 @@ from odoo import models, api, fields from odoo.exceptions import UserError -from datetime import datetime +from datetime import datetime, timedelta import logging import pysolr import time _logger = logging.getLogger(__name__) +_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) class ApacheSolr(models.Model): _name = 'apache.solr' _order = 'id desc' + def _update_rating_product_to_solr(self, limit=1000): + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + templates = self.env['product.template'].search([ + '&','&', + ('type', '=', 'product'), + ('active', '=', True), + '|', + ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), + ], limit=limit) + documents=[] + for template in templates: + document = { + 'id': template.id, + 'product_rating_f': {'set':template.virtual_rating}, + } + documents.append(document) + template.last_calculate_rating = current_time + _logger.info("[SYNC_PRODUCT_RATING_TO_SOLR] Success Set to solr product %s" % template.id) + _solr.add(documents) + def _sync_product_to_solr(self, limit=500): - _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) # _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() _logger.info('run sync to solr...') -- cgit v1.2.3 From afad42a0a2c19339158499a259bef5bb7062f387 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 17:37:04 +0700 Subject: bug fix update rating to solr --- indoteknik_custom/models/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 04f83532..ce6a4180 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -30,8 +30,8 @@ class ApacheSolr(models.Model): documents=[] for template in templates: document = { - 'id': template.id, - 'product_rating_f': {'set':template.virtual_rating}, + "id": template.id, + "product_rating_f": {"set":template.virtual_rating} } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3 From 1d2a045da635445f5331132b1713c392ecb905fa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 4 May 2023 08:57:48 +0700 Subject: change virtual rating to dict from string --- indoteknik_custom/models/apache_solr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ce6a4180..b59f95cc 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -29,9 +29,10 @@ class ApacheSolr(models.Model): ], limit=limit) documents=[] for template in templates: + rating = {"set":template.virtual_rating} document = { "id": template.id, - "product_rating_f": {"set":template.virtual_rating} + "product_rating_f": rating } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3