diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-04 12:12:17 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-04 12:12:17 +0700 |
| commit | 39883f829f246f06d981e61431d12c3ef812e202 (patch) | |
| tree | 72c127935933a149bee42d936d1ca499dfd6aa4e /indoteknik_custom/models | |
| parent | 17ec32faaa55f9fd1457622f14cab0b770f64afc (diff) | |
| parent | 1d2a045da635445f5331132b1713c392ecb905fa (diff) | |
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 32 | ||||
| -rw-r--r-- | indoteknik_custom/models/procurement_monitoring_detail.py | 19 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 63 | ||||
| -rw-r--r-- | indoteknik_custom/models/raja_ongkir.py | 8 |
4 files changed, 83 insertions, 39 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ebe516a0..b59f95cc 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -1,19 +1,45 @@ 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: + rating = {"set":template.virtual_rating} + document = { + "id": template.id, + "product_rating_f": 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...') @@ -73,7 +99,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/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index 97d35faf..6031e04a 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) @@ -29,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 ( @@ -53,6 +68,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/models/product_template.py b/indoteknik_custom/models/product_template.py index 74b4edb1..49235ec7 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 += 4 + if product.have_promotion_program: #have discount from pricelist + rate += 5 + if product.image_128: + rate += 3 + if product.website_description: + rate += 1 + if product.product_variant_id.qty_stock_vendor > 0: + rate += 2 + 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) + # 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 - 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) - 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 + 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/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' |
