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 | |
| parent | 17ec32faaa55f9fd1457622f14cab0b770f64afc (diff) | |
| parent | 1d2a045da635445f5331132b1713c392ecb905fa (diff) | |
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
| -rw-r--r-- | indoteknik_api/controllers/api_v1/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/courier.py | 26 | ||||
| -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 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/procurement_monitoring_detail.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/product_template.xml | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/raja_ongkir.xml | 152 |
10 files changed, 266 insertions, 40 deletions
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/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' 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/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 @@ <field name="qty_reserved"/> <field name="qty_available"/> <field name="qty_suggest"/> + <field name="po_ids" widget="many2many_tags"/> <field name="qty_po"/> <field name="status" widget="badge" 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 @@ <field name="usage"/> <field name="specification"/> <field name="material"/> + <field name="virtual_rating"/> <field name="search_rank"/> <field name="solr_flag"/> </field> 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 @@ </field> </record> </data> + + <data> + <record id="rajaongkir_kurir_tree" model="ir.ui.view"> + <field name="name">Kurir RajaOngkir</field> + <field name="model">rajaongkir.kurir</field> + <field name="arch" type="xml"> + <tree> + <field name="delivery_carrier_id"/> + <field name="name"/> + <field name="image"/> + <field name="publish"/> + </tree> + </field> + </record> + </data> + + <record id="rajaongkir_kurir_action" model="ir.actions.act_window"> + <field name="name">Kurir RajaOngkir</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">rajaongkir.kurir</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem + id="menu_kurir_rajaongkir" + name="Kurir RajaOngkir" + parent="delivery.menu_delivery" + sequence="150" + action="rajaongkir_kurir_action" + /> + + <record id="rajaongkir_jne" model="rajaongkir.kurir"> + <field name="name">jne</field> + <field name="delivery_carrier_id">51</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pos" model="rajaongkir.kurir"> + <field name="name">pos</field> + <field name="delivery_carrier_id">53</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_tiki" model="rajaongkir.kurir"> + <field name="name">tiki</field> + <field name="delivery_carrier_id">54</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_rpx" model="rajaongkir.kurir"> + <field name="name">rpx</field> + <field name="delivery_carrier_id">55</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pandu" model="rajaongkir.kurir"> + <field name="name">pandu</field> + <field name="delivery_carrier_id">56</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_wahana" model="rajaongkir.kurir"> + <field name="name">wahana</field> + <field name="delivery_carrier_id">7</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sicepat" model="rajaongkir.kurir"> + <field name="name">sicepat</field> + <field name="delivery_carrier_id">27</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jnt" model="rajaongkir.kurir"> + <field name="name">jnt</field> + <field name="delivery_carrier_id">57</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pahala" model="rajaongkir.kurir"> + <field name="name">pahala</field> + <field name="delivery_carrier_id">58</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sap" model="rajaongkir.kurir"> + <field name="name">sap</field> + <field name="delivery_carrier_id">59</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jet" model="rajaongkir.kurir"> + <field name="name">jet</field> + <field name="delivery_carrier_id">60</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_indah" model="rajaongkir.kurir"> + <field name="name">indah</field> + <field name="delivery_carrier_id">61</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_dse" model="rajaongkir.kurir"> + <field name="name">dse</field> + <field name="delivery_carrier_id">62</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_slis" model="rajaongkir.kurir"> + <field name="name">slis</field> + <field name="delivery_carrier_id">63</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_first" model="rajaongkir.kurir"> + <field name="name">first</field> + <field name="delivery_carrier_id">64</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_ncs" model="rajaongkir.kurir"> + <field name="name">ncs</field> + <field name="delivery_carrier_id">65</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_star" model="rajaongkir.kurir"> + <field name="name">star</field> + <field name="delivery_carrier_id">66</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_lion" model="rajaongkir.kurir"> + <field name="name">lion</field> + <field name="delivery_carrier_id">67</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_idl" model="rajaongkir.kurir"> + <field name="name">idl</field> + <field name="delivery_carrier_id">68</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_rex" model="rajaongkir.kurir"> + <field name="name">rex</field> + <field name="delivery_carrier_id">69</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_ide" model="rajaongkir.kurir"> + <field name="name">ide</field> + <field name="delivery_carrier_id">70</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sentral" model="rajaongkir.kurir"> + <field name="name">sentral</field> + <field name="delivery_carrier_id">71</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_anteraja" model="rajaongkir.kurir"> + <field name="name">anteraja</field> + <field name="delivery_carrier_id">72</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jtl" model="rajaongkir.kurir"> + <field name="name">jtl</field> + <field name="delivery_carrier_id">73</field> + <field name="publish">True</field> + </record> + </odoo>
\ No newline at end of file |
