From d1b86303b0934c9f6348e7016822d449349540d3 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 6 Apr 2023 13:27:48 +0700 Subject: integrate flashsale to solr for new website --- indoteknik_api/controllers/api_v1/flash_sale.py | 51 ++++++++++++++++++++++++- indoteknik_api/models/product_pricelist.py | 26 +++++++++++++ indoteknik_api/models/product_product.py | 41 ++++++++++++++++++++ indoteknik_custom/models/apache_solr.py | 14 +++++-- 4 files changed, 128 insertions(+), 4 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py index ea73ab1b..cad2cb61 100644 --- a/indoteknik_api/controllers/api_v1/flash_sale.py +++ b/indoteknik_api/controllers/api_v1/flash_sale.py @@ -10,6 +10,55 @@ _logger = logging.getLogger(__name__) class FlashSale(controller.Controller): prefix = '/api/v1/' + @http.route(prefix + 'flashsale/header', auth='public', methods=['GET']) + @controller.Controller.must_authorized() + def _get_flash_sale_header(self, **kw): + try: + # base_url = request.env['ir.config_parameter'].get_param('web.base.url') + active_flash_sale = request.env['product.pricelist'].get_active_flash_sale() + data = [] + for pricelist in active_flash_sale: + query = [ + ('pricelist_id', '=', pricelist.id) + ] + data.append({ + 'pricelist_id': pricelist.id, + 'option': pricelist.flashsale_option, + 'name': pricelist.name, + 'banner': request.env['ir.attachment'].api_image('product.pricelist', 'banner', pricelist.id), + 'banner_mobile': request.env['ir.attachment'].api_image('product.pricelist', 'banner_mobile', pricelist.id), + 'duration': round((pricelist.end_date - datetime.now()).total_seconds()), + 'product_total': request.env['product.pricelist.item'].search_count(query), + }) + return self.response(data) + except Exception as e: + _logger.info(self.prefix + '/flashsale/header: ' + str(e)) + return self.response(code=500, description='Internal server error') + + @http.route(prefix + 'flashsale/line', auth='public', methods=['GET']) + @controller.Controller.must_authorized() + def _get_flash_sale_line(self, **kw): + try: + # base_url = request.env['ir.config_parameter'].get_param('web.base.url') + pricelist_id = int(kw.get('pricelist_id'),0) + limit = int(kw.get('limit'),0) + offset = int(kw.get('offset'),0) + + if pricelist_id == 0 or limit == 0: + return self.response(code=500, description='Internal Server error') + + pricelist_items = request.env['product.pricelist.item'].search([('pricelist_id', '=', pricelist_id)], limit=limit, offset=offset) + data = { + 'total': request.env['product.pricelist.item'].search_count([('pricelist_id', '=', pricelist_id)]), + 'products': [request.env['product.pricelist.item'].api_single_response(x) for x in pricelist_items] + } + return self.response(data) + + except Exception as e: + _logger.info(self.prefix + '/flashsale/line: ' + str(e)) + return self.response(code=500, description='Internal Server error') + + @http.route(prefix + 'flash_sale', auth='public', methods=['GET']) @controller.Controller.must_authorized() def get_flash_sale(self, **kw): @@ -54,6 +103,6 @@ class FlashSale(controller.Controller): else: return self.response(code=404, description='Data not found') except Exception as e: - _logger.info(self.prefix_url + '/flash_sale: ' + str(e)) + _logger.info(self.prefix + '/flash_sale: ' + str(e)) return self.response(code=500, description='Internal server error') \ No newline at end of file diff --git a/indoteknik_api/models/product_pricelist.py b/indoteknik_api/models/product_pricelist.py index 4e5c9501..f05fa82d 100644 --- a/indoteknik_api/models/product_pricelist.py +++ b/indoteknik_api/models/product_pricelist.py @@ -107,3 +107,29 @@ class ProductPricelist(models.Model): if product_id in pricelist_product_ids: return pricelist.id return False + + +class ProductPricelistItem(models.Model): + _inherit = 'product.pricelist.item' + + def api_single_response(self, item): + data = { + 'id': item.product_id.id, + 'parent': { + 'id': item.product_id.product_tmpl_id.id, + 'name': item.product_id.product_tmpl_id.name, + 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', item.product_id.product_tmpl_id.id) + }, + 'code': item.product_id.default_code or item.product_tmpl_id.default_code or '', + 'name': item.product_id.display_name, + 'price':{ + 'price': item.product_id._get_website_price_exclude_tax(), + 'discount': item.product_id._get_website_disc(0), + 'price_discount': item.product_id._get_website_price_after_disc_and_tax() + }, + 'stock': item.product_id.qty_stock_vendor, + 'weight': item.product_id.weight, + 'attributes': [x.name for x in item.product_id.product_template_attribute_value_ids], + 'manufacture': item.product_id.api_manufacture(item.product_id) + } + return data \ No newline at end of file diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 284900de..8c60ce43 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -42,6 +42,14 @@ class ProductProduct(models.Model): } return {} + def _is_have_flashsale(self): + active_flashsale = self.env['product.pricelist'].get_active_flash_sale() + for pricelist in active_flashsale: + found_product = self.env['product.pricelist.item'].search([('pricelist_id', '=', pricelist.id), ('product_id', '=', self.id)]) + if found_product: + return True + return False + def _get_website_price_include_tax(self): default_pricelist_id = int(1) @@ -104,3 +112,36 @@ class ProductProduct(models.Model): price_after_disc = self._get_website_price_after_disc_and_tax() res = price_after_disc * default_percent_tax / 100 return math.floor(res) + + def _get_flashsale_price(self): + # must get active pricelist + active_flash_sale = self.env['product.pricelist'].get_active_flash_sale() + flashsale_id = 0 + flashsale_name = '' + # loop pricelist items + base_price = discount = price_flashsale = 0 + for pricelist in active_flash_sale: + flashsale_id = pricelist.id + flashsale_name = pricelist.name + query = [ + ('pricelist_id', '=', pricelist.id), + ('product_id', '=', self.id), + ] + pricelist_items = self.env['product.pricelist.item'].search(query, limit=1) + for item in pricelist_items: + base_price = self._get_website_price_exclude_tax() + if item.price_discount > 0: + discount = item.price_discount + # base_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', item.base_pricelist_id.id), ('product_id', '=', self.id)], limit=1) + price_flashsale = base_price - (base_price * discount // 100) + elif item.fixed_price > 0: + price_flashsale = item.fixed_price # ask darren for include or exclude + discount = (base_price - price_flashsale) // base_price * 100 + data = { + 'flashsale_id': flashsale_id, + 'flashsale_name': flashsale_name, + 'flashsale_base_price': base_price, + 'flashsale_discount': discount, + 'flashsale_price': price_flashsale + } + return data diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 3ed431ef..0a403b6b 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,9 +13,10 @@ class ApacheSolr(models.Model): _order = 'id desc' 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...') - solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] templates = self.env['product.template'].search(query, limit=limit) @@ -27,6 +28,7 @@ class ApacheSolr(models.Model): variants_name = variants_code = '' if template.product_variant_count > 1: for variant in template.product_variant_ids: + flashsale_data = variant._get_flashsale_price() if price_excl_after_disc == 0: price_excl = variant._get_website_price_exclude_tax() price_excl_after_disc = variant._get_website_price_after_disc_and_tax() @@ -49,6 +51,7 @@ class ApacheSolr(models.Model): discount = template.product_variant_id._get_website_disc(0) price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax() tax = template.product_variant_id._get_website_tax() + flashsale_data = template.product_variant_id._get_flashsale_price() category_id = '' category_name = '' @@ -82,13 +85,18 @@ class ApacheSolr(models.Model): 'variants_name_t': variants_name, 'variants_code_t': variants_code, 'search_rank_i': template.search_rank, - 'search_rank_weekly_i': template.search_rank_weekly + 'search_rank_weekly_i': template.search_rank_weekly, + 'flashsale_id_i': flashsale_data['flashsale_id'] or 0, + 'flashsale_name_s': flashsale_data['flashsale_name'] or '', + 'flashsale_base_price_f': flashsale_data['flashsale_base_price'] or 0, + 'flashsale_discount_f': flashsale_data['flashsale_discount'] or 0, + 'flashsale_price_f': flashsale_data['flashsale_price'] or 0, } documents.append(document) template.solr_flag = 1 # add counter for monitoring _logger.info('[SYNC_PRODUCT_TO_SOLR] %s/%i' % (counter, limit)) _logger.info('[SYNC_PRODUCT_TO_SOLR] Success add to solr product %s' % template.id) - solr.add(documents) + _solr.add(documents) end_time = time.time() _logger.info("[SYNC_PRODUCT_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time)) -- cgit v1.2.3 From 539a2bc4e311ebf5ec3ed8b43d4b0fd433ccecbd Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Apr 2023 13:26:06 +0700 Subject: auto parsing lookup ip and looked last data parsing --- indoteknik_custom/models/ip_lookup.py | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) 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') -- cgit v1.2.3 From 6fc4731e24f1e6f105676273695262f5da059faf Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Apr 2023 15:17:38 +0700 Subject: add group partner and fix automatic purchase --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/automatic_purchase.py | 2 +- indoteknik_custom/models/res_partner.py | 6 +++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/group_partner.xml | 55 ++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 indoteknik_custom/views/group_partner.xml 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..f2e7d9e9 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 vendor['partner_id'][0] == 5571 and (count == 200 or brand_id != product.brand_id.id): count = 0 counter_po_number += 1 new_po = self.env['purchase.order'].create([param_header]) 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/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 @@ + + + + group.partner.tree + group.partner + + + + + + + + + group.partner.form + group.partner + +
+ + + + + + + +
+
+
+ + + group.partner.list.select + group.partner + + + + + + + + + + Group Partner + ir.actions.act_window + group.partner + + tree,form + + + +
\ No newline at end of file -- cgit v1.2.3 From 8415d007f283af56432bcd1435b46c173070f4fc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Apr 2023 15:31:29 +0700 Subject: group partner in xml --- indoteknik_custom/views/res_partner.xml | 1 + 1 file changed, 1 insertion(+) 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 @@ + -- cgit v1.2.3 From cc29232e4b935ab2adcc20e177c2bc313cc5f373 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Apr 2023 15:46:05 +0700 Subject: bug fix split po --- indoteknik_custom/models/automatic_purchase.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index f2e7d9e9..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['partner_id'][0] == 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 = { -- cgit v1.2.3 From 3b5871b8c364e819a2fbaf268e4693e848e6af0a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 13:56:41 +0700 Subject: add validation qty available in sales monitoring --- indoteknik_custom/models/sale_monitoring_detail.py | 1 + 1 file changed, 1 insertion(+) 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 -- cgit v1.2.3 From d753a2b681dc14e47551e4525fddb23820b841af Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 14:02:31 +0700 Subject: change to solr production --- 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 0a403b6b..fe31906f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,8 +13,8 @@ class ApacheSolr(models.Model): _order = 'id desc' 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) + _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...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] -- cgit v1.2.3 From a581095da416f586dd1bceba148cc1d0a4022976 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 16:05:26 +0700 Subject: add log while parsing ip address --- indoteknik_custom/models/ip_lookup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py index 244982c0..9c4beda9 100644 --- a/indoteknik_custom/models/ip_lookup.py +++ b/indoteknik_custom/models/ip_lookup.py @@ -50,6 +50,7 @@ class IpLookup(models.Model): log.lookup = last_data.lookup country = json.loads(last_data.lookup)['country'] timezone = json.loads(last_data)['timezone'] + _logger.info('Parsing IP using last data %s' % log.id) else: ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json() del ipinfo['status'] @@ -57,6 +58,7 @@ class IpLookup(models.Model): log.lookup = lookup_json country = json.loads(lookup_json)['country'] timezone = json.loads(lookup_json)['timezone'] + _logger.info('Parsing IP using API JSON %s' % log.id) log.country = country log.timezone = timezone log.continent = timezone.split('/')[0] -- cgit v1.2.3 From a854c5cca6e374589449e54a2fb9efb7f2c24955 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 16:08:37 +0700 Subject: fix typo parsing ip --- indoteknik_custom/models/ip_lookup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py index 9c4beda9..a708cd94 100644 --- a/indoteknik_custom/models/ip_lookup.py +++ b/indoteknik_custom/models/ip_lookup.py @@ -49,7 +49,7 @@ class IpLookup(models.Model): if last_data: log.lookup = last_data.lookup country = json.loads(last_data.lookup)['country'] - timezone = json.loads(last_data)['timezone'] + timezone = json.loads(last_data.lookup)['timezone'] _logger.info('Parsing IP using last data %s' % log.id) else: ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json() -- cgit v1.2.3 From c29187f2e1be3bed90ab8f4eece5bbc087861522 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 18:47:48 +0700 Subject: add suggestion while sync so to po --- indoteknik_custom/models/purchase_order.py | 6 ++++++ indoteknik_custom/models/purchase_order_line.py | 2 ++ indoteknik_custom/views/purchase_order.xml | 6 ++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 0ef6a9f2..8809d048 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -139,11 +139,17 @@ class PurchaseOrder(models.Model): self.order_line.unlink() for order_line in self.sale_order_id.order_line: if order_line.product_id.id and order_line.product_id.id not in products_exception: + qty_available = order_line.product_id.virtual_available + suggest = 'harus beli' + if order_line.product_id.virtual_available > order_line.product_qty: + suggest = 'masih cukup' values = { 'order_id': self.id, 'product_id': order_line.product_id.id, 'name': order_line.product_id.display_name, 'product_qty': order_line.product_qty, + 'qty_available_store': qty_available, + 'suggest': suggest, } self.env['purchase.order.line'].sudo().create(values) diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 8439df5d..f255095f 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -26,6 +26,8 @@ class PurchaseOrderLine(models.Model): qty_onhand = fields.Float('Qty On Hand', compute='compute_qty_stock') qty_incoming = fields.Float('Qty Incoming', compute='compute_qty_stock') qty_outgoing = fields.Float('Qty Outgoing', compute='compute_qty_stock') + qty_available_store = fields.Float(string='Available') + suggest = fields.Char(string='Suggest') def compute_qty_stock(self): for line in self: diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index fb85f4c1..eb5267e0 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -46,10 +46,8 @@ - - - - + + -- cgit v1.2.3 From 4da2d3ba6ce8e3b52fe8c8bba4a07abe7b14db05 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 12 Apr 2023 10:28:23 +0700 Subject: fix bug sync flashsale to solr --- indoteknik_api/models/product_product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 409b69c2..39cc9b28 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -141,14 +141,14 @@ class ProductProduct(models.Model): # loop pricelist items base_price = discount = price_flashsale = 0 for pricelist in active_flash_sale: - flashsale_id = pricelist.id - flashsale_name = pricelist.name query = [ ('pricelist_id', '=', pricelist.id), ('product_id', '=', self.id), ] pricelist_items = self.env['product.pricelist.item'].search(query, limit=1) for item in pricelist_items: + flashsale_id = pricelist.id + flashsale_name = pricelist.name base_price = self._get_website_price_exclude_tax() if item.price_discount > 0: discount = item.price_discount -- cgit v1.2.3 From 9fd01a2999a88973b583a86f52f120a41571d7d7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 12 Apr 2023 11:25:45 +0700 Subject: bug fix undefined salesperson in leads --- indoteknik_custom/models/crm_lead.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index b34183d8..e3d7d8ed 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -59,7 +59,7 @@ class CrmLead(models.Model): continue 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 + salesperson_id = lead.partner_id.parent_id.user_id.id else: - salesperson_id = lead.partner_id.user_id + salesperson_id = lead.partner_id.user_id.id lead.user_id = salesperson_id -- cgit v1.2.3 From fe8f1c997224aa2c6cdd01e14562668d7cbffaf5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 12 Apr 2023 15:33:33 +0700 Subject: prepare for tiering price api solr --- indoteknik_api/models/product_product.py | 54 ++++++++++++++++++++++++++++++++ indoteknik_custom/models/apache_solr.py | 31 ++++++++++++------ 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 39cc9b28..32bd7c21 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -133,6 +133,60 @@ class ProductProduct(models.Model): res = price_after_disc * default_percent_tax / 100 return math.floor(res) + def _get_pricelist_tier1(self): + default_divide_tax = float(1.11) + base_price = discount = price = 0 + pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15037), ('product_id', '=', self.id)], limit=1) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier1': base_price or 0, + 'discount_tier1': discount or 0, + 'price_tier1': price or 0 + } + return data + + def _get_pricelist_tier2(self): + default_divide_tax = float(1.11) + base_price = discount = price = 0 + pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15038), ('product_id', '=', self.id)], limit=1) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier2': base_price or 0, + 'discount_tier2': discount or 0, + 'price_tier2': price or 0 + } + return data + + def _get_pricelist_tier3(self): + default_divide_tax = float(1.11) + base_price = discount = price = 0 + pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15039), ('product_id', '=', self.id)], limit=1) + if pricelist_item: + # base_price = self._get_website_price_exclude_tax() + base_price_incl = self._get_website_price_include_tax() + discount = pricelist_item.price_discount + price = base_price_incl - (base_price_incl * discount / 100) + price = price / default_divide_tax + price = math.floor(price) + data = { + # 'base_price_tier3': base_price or 0, + 'discount_tier3': discount or 0, + 'price_tier3': price or 0 + } + return data + def _get_flashsale_price(self): # must get active pricelist active_flash_sale = self.env['product.pricelist'].get_active_flash_sale() diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index fe31906f..ee166002 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,8 +13,8 @@ class ApacheSolr(models.Model): _order = 'id desc' 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) + # _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...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] @@ -26,24 +26,28 @@ class ApacheSolr(models.Model): counter += 1 price_excl_after_disc = price_excl = discount = tax = 0 variants_name = variants_code = '' + flashsale_data = tier1 = tier2 = tier3 = {} if template.product_variant_count > 1: for variant in template.product_variant_ids: - flashsale_data = variant._get_flashsale_price() - if price_excl_after_disc == 0: + if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: price_excl = variant._get_website_price_exclude_tax() price_excl_after_disc = variant._get_website_price_after_disc_and_tax() discount = variant._get_website_disc(0) tax = variant._get_website_tax() - elif variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: - price_excl_after_disc = variant._get_website_price_after_disc_and_tax() - price_excl = variant._get_website_price_exclude_tax() - discount = variant._get_website_disc(0) - tax = variant._get_website_tax() + flashsale_data = variant._get_flashsale_price() + # add price tiering for base price, discount, and price after discount (tier 1 - 3) + tier1 = variant._get_pricelist_tier1() + tier2 = variant._get_pricelist_tier2() + tier3 = variant._get_pricelist_tier3() else: price_excl_after_disc = price_excl_after_disc price_excl = price_excl discount = discount tax = tax + flashsale_data = flashsale_data + tier1 = tier1 + tier2 = tier2 + tier3 = tier3 variants_name += variant.display_name or ''+', ' variants_code += variant.default_code or ''+', ' else: @@ -52,6 +56,9 @@ class ApacheSolr(models.Model): price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax() tax = template.product_variant_id._get_website_tax() flashsale_data = template.product_variant_id._get_flashsale_price() + tier1 = template.product_variant_id._get_pricelist_tier1() + tier2 = template.product_variant_id._get_pricelist_tier2() + tier3 = template.product_variant_id._get_pricelist_tier3() category_id = '' category_name = '' @@ -91,6 +98,12 @@ class ApacheSolr(models.Model): 'flashsale_base_price_f': flashsale_data['flashsale_base_price'] or 0, 'flashsale_discount_f': flashsale_data['flashsale_discount'] or 0, 'flashsale_price_f': flashsale_data['flashsale_price'] or 0, + 'discount_tier1_f': tier1['discount_tier1'] or 0, + 'price_tier1_f': tier1['price_tier1'] or 0, + 'discount_tier2_f': tier2['discount_tier2'] or 0, + 'price_tier2_f': tier2['price_tier2'] or 0, + 'discount_tier3_f': tier3['discount_tier3'] or 0, + 'price_tier3_f': tier3['price_tier3'] or 0 } documents.append(document) template.solr_flag = 1 -- cgit v1.2.3 From eba12015d465f1a0ed5f4806460352707f2961f7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 13 Apr 2023 13:10:20 +0700 Subject: custom report picking list --- indoteknik_custom/__manifest__.py | 3 ++- indoteknik_custom/report/report_picking.xml | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/report/report_picking.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 6e67afe1..e2c6eedd 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -74,7 +74,8 @@ 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', 'report/purchase_order.xml', - 'report/report_invoice.xml' + 'report/report_invoice.xml', + 'report/report_picking.xml' ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/report/report_picking.xml b/indoteknik_custom/report/report_picking.xml new file mode 100644 index 00000000..86cad03f --- /dev/null +++ b/indoteknik_custom/report/report_picking.xml @@ -0,0 +1,14 @@ + + + -- cgit v1.2.3 From f76c3426b4f92bb3622a0ce2f012923d876de6c2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 15 Apr 2023 10:36:32 +0700 Subject: fix sales person in leads --- indoteknik_custom/models/crm_lead.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index e3d7d8ed..913c670e 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -45,7 +45,8 @@ class CrmLead(models.Model): leads = self.env['crm.lead'].search([ ('active', '=', True), ('type', '=', 'lead'), - ('tag_ids', '=', False), + # ('tag_ids', '=', False), + ('id', '=', 12523) ], limit=1000) for lead in leads: tags = self.env['crm.tag'].search([('id', '>', 0)]) @@ -57,7 +58,7 @@ class CrmLead(models.Model): if not lead.partner_id: continue - if not lead.user_id or lead.user_id == 2: + if not lead.user_id or lead.user_id.id == 2: if lead.partner_id.parent_id: salesperson_id = lead.partner_id.parent_id.user_id.id else: -- cgit v1.2.3 From 4eb477f655231e39eaacb4453f216692a8355bac Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 17 Apr 2023 11:51:00 +0700 Subject: comment tag leads --- indoteknik_custom/models/crm_lead.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index 913c670e..1f37005d 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -45,8 +45,8 @@ class CrmLead(models.Model): leads = self.env['crm.lead'].search([ ('active', '=', True), ('type', '=', 'lead'), - # ('tag_ids', '=', False), - ('id', '=', 12523) + ('tag_ids', '=', False), + # ('id', '=', 12523) ], limit=1000) for lead in leads: tags = self.env['crm.tag'].search([('id', '>', 0)]) -- cgit v1.2.3