diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-17 11:52:04 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-04-17 11:52:04 +0700 |
| commit | 015ca8f0ae8ecdaaf388ee08420af54a84fb2d0c (patch) | |
| tree | 6e95bf27732dc9958ab161363a121bd46d68b717 /indoteknik_custom/models | |
| parent | 719dc824379bff729a97007432ef6871954b0980 (diff) | |
| parent | 4eb477f655231e39eaacb4453f216692a8355bac (diff) | |
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 39 | ||||
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/crm_lead.py | 7 | ||||
| -rw-r--r-- | indoteknik_custom/models/ip_lookup.py | 39 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring_detail.py | 1 |
8 files changed, 86 insertions, 20 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 3ed431ef..ee166002 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) @@ -25,23 +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: - 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: @@ -49,6 +55,10 @@ 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() + 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 = '' @@ -82,13 +92,24 @@ 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, + '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 # 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)) 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/crm_lead.py b/indoteknik_custom/models/crm_lead.py index b34183d8..1f37005d 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -46,6 +46,7 @@ class CrmLead(models.Model): ('active', '=', True), ('type', '=', 'lead'), ('tag_ids', '=', False), + # ('id', '=', 12523) ], limit=1000) for lead in leads: tags = self.env['crm.tag'].search([('id', '>', 0)]) @@ -57,9 +58,9 @@ 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 + 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 diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py index 0fbb03ea..a708cd94 100644 --- a/indoteknik_custom/models/ip_lookup.py +++ b/indoteknik_custom/models/ip_lookup.py @@ -41,12 +41,40 @@ 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.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() + 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'] + _logger.info('Parsing IP using API JSON %s' % log.id) + 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 +84,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/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/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 |
