From 4cec68ef40a33071d949c33c1592c146779f1abe Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 11:43:41 +0700 Subject: add delivered validation system parameter and add sequence for new product template scheduler --- indoteknik_custom/models/product_template.py | 48 +++++++++++++++++----------- indoteknik_custom/models/stock_picking.py | 4 ++- indoteknik_custom/views/x_manufactures.xml | 1 + 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 9f0410f4..ef0ead1b 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -46,12 +46,34 @@ class ProductTemplate(models.Model): material = fields.Char(string='Material') is_new_product = fields.Boolean(string='Produk Baru', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') + seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') # def write(self, vals): # if 'solr_flag' not in vals and self.solr_flag == 1: # vals['solr_flag'] = 2 # return super().write(vals) + def update_new_product(self): + 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') + + products = self.env['product.template'].search([ + ('type', '=', 'product'), + ('active', '=', True), + ('product_rating', '>', 3), + ('create_date', '>=', delta_time), + ], limit=1000) + + seq = 0 + for product in products: + seq += 1 + product.is_new_product = True + product.seq_new_product = seq + _logger.info('Updated New Product %s' % product.name) + def update_internal_reference(self): templates_without_variant = self.env['product.template'].search([ ('default_code', '=', False), @@ -92,33 +114,21 @@ class ProductTemplate(models.Model): for template in self: product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) - # product_pricelist_default = self.env['ir.config_parameter'].sudo().get_param('product.pricelist.default') - # product_pricelist_disc = self.env['product.pricelist.item'].search([ - # ('pricelist_id', '=', product_pricelist_default.int()), - # ('product_id', '=', product.id)], limit=1) - # disc = product_pricelist_disc.price_discount - product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 1), ('product_id', '=', product.id)], limit=1) price = product_pricelist_item.fixed_price - # - # if not disc and not price: - # template.web_price = 0 - # elif not disc: template.web_price = price - # else: - # price_disc = price - (price * disc / 100) - # template.web_price = price_disc def _have_promotion_program(self): for template in self: - domain = [ - ('rule_products_domain', 'ilike', template.x_manufacture.x_name), - ('active', '=', True) - ] - coupon_program = self.env['coupon.program'].search(domain, limit=1) - if coupon_program: + 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) + discount = product_pricelist_item.price_discount + if discount: template.have_promotion_program = True else: template.have_promotion_program = False diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 84a374c5..d19214d2 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -145,8 +145,10 @@ class StockPicking(models.Model): continue raise UserError('Sudah pernah dikirim kalender') + is_delivered_validation = self.env['ir.config_parameter'].get_param( + 'stock_picking.qty_delivered_validation') for line in self.move_line_ids_without_package: - if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing': + if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing' and is_delivered_validation == 'Y': if line.move_id.sale_line_id.qty_delivered + line.qty_done > line.move_id.sale_line_id.product_uom_qty: raise UserError("Qty Delivered akan lebih dari Qty SO") diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index c7cedd9c..cc8fd10c 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -65,6 +65,7 @@ + -- cgit v1.2.3 From f0caad5740ae914391dbe7650977c00df2379f52 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 13:08:22 +0700 Subject: change limit to 100 --- indoteknik_custom/models/product_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index ef0ead1b..caf7ea3a 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -146,7 +146,7 @@ class ProductTemplate(models.Model): ('active', '=', True), ('last_calculate_rating', '=', False), # ('id', '=', 22798), - ], limit=10000) + ], limit=100) for product in products: # print("Calculate Rating Product ", product) @@ -171,7 +171,7 @@ class ProductTemplate(models.Model): ('type', '=', 'product'), ('active', '=', True), ('last_calculate_rating', '<', delta_time), - ], limit=10000) + ], limit=100) for product in products: print("Calculate Rating Product OutOfDate", product) -- cgit v1.2.3 From 09cfa10a6ac0335b4342665707269cc5aa7bbcf8 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 13:22:47 +0700 Subject: revert --- indoteknik_custom/models/stock_picking.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index d19214d2..84a374c5 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -145,10 +145,8 @@ class StockPicking(models.Model): continue raise UserError('Sudah pernah dikirim kalender') - is_delivered_validation = self.env['ir.config_parameter'].get_param( - 'stock_picking.qty_delivered_validation') for line in self.move_line_ids_without_package: - if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing' and is_delivered_validation == 'Y': + if line.move_id.sale_line_id and self.picking_type_id.code == 'outgoing': if line.move_id.sale_line_id.qty_delivered + line.qty_done > line.move_id.sale_line_id.product_uom_qty: raise UserError("Qty Delivered akan lebih dari Qty SO") -- cgit v1.2.3 From 83ead9edac739720168d615f6282e3978634e461 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 15:44:51 +0700 Subject: fix generate dunning run --- indoteknik_custom/models/dunning_run.py | 75 ++++++++++++++++++--------------- indoteknik_custom/views/dunning_run.xml | 31 ++++++++++++-- 2 files changed, 68 insertions(+), 38 deletions(-) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index ed9aa7c0..56a33578 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -17,8 +17,37 @@ class DunningRun(models.Model): required=True, change_default=True, index=True, tracking=1) dunning_line = fields.One2many('dunning.run.line', 'dunning_id', string='Dunning Lines', auto_join=True) # dunning_level = fields.Integer(string='Dunning Level', default=30, help='30 hari sebelum jatuh tempo invoice') + date_kirim_tukar_faktur = fields.Date(string='Kirim Faktur') + resi_tukar_faktur = fields.Char(string='Resi Faktur') + date_terima_tukar_faktur = fields.Date(string='Terima Faktur') + shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') + is_validated = fields.Boolean(string='Validated') + + def copy_date_faktur(self): + if not self.is_validated: + raise UserError('Harus di validate dulu') + for line in self.dunning_line: + invoice = line.invoice_id + if not invoice.date_kirim_tukar_faktur: + invoice.date_kirim_tukar_faktur = self.date_kirim_tukar_faktur + if not invoice.resi_tukar_faktur: + invoice.resi_tukar_faktur = self.resi_tukar_faktur + if not invoice.date_terima_tukar_faktur: + invoice.date_terima_tukar_faktur = self.date_terima_tukar_faktur + if not invoice.shipper_faktur_id: + invoice.shipper_faktur_id = self.shipper_faktur_id + + def validate_dunning(self): + if not self.dunning_line: + raise UserError('Dunning Line masih kosong, generate dulu') + else: + self.is_validated = True def generate_dunning_line(self): + if self.is_validated: + raise UserError('Sudah di validate, tidak bisa digenerate ulang') + if self.dunning_line: + raise UserError('Harus hapus semua line jika ingin generate ulang') if self.partner_id.parent_id: raise UserError('Harus pilih parent company') @@ -29,21 +58,26 @@ class DunningRun(models.Model): for partner in partners: query = [ ('move_type', '=', 'out_invoice'), + ('state', '=', 'posted'), ('partner_id', '=', partner.id), - ('outstanding_amount', '>', 0), + ('amount_residual_signed', '>', 0), ] invoices = self.env['account.move'].search(query, order='invoice_date') + count = 0 for invoice in invoices: - parameter_line = { + self.env['dunning.run.line'].create([{ 'dunning_id': self.id, - 'partner_id': invoice.partner_id, + 'partner_id': invoice.partner_id.id, 'invoice_id': invoice.id, 'date_invoice': invoice.invoice_date, - 'efaktur_id': invoice.efaktur_id, + 'efaktur_id': invoice.efaktur_id.id, 'reference': invoice.ref, - 'open_amt': invoice.outstanding_amount - } - self.env['dunning.run.line'].create([parameter_line]) + 'total_amt': invoice.amount_total, + 'open_amt': invoice.amount_residual_signed, + 'due_date': invoice.invoice_date_due + }]) + count += 1 + _logger.info("Dunning Line generated %s" % count) @api.model def create(self, vals): @@ -51,33 +85,6 @@ class DunningRun(models.Model): result = super(DunningRun, self).create(vals) return result - def generate_dunning_line(self): - # validation - if not self.partner_id: - raise UserError('Customer harus diisi') - - invoices = self.env['account.move'].search([ - ('amount_residual_signed', '>', 0), - ('partner_id', '=', self.partner_id.id), - ('move_type', '=', 'out_invoice'), - ('state', '=', 'posted'), - ]) - count = 0 - for invoice in invoices: - self.env['dunning.run.line'].create([{ - 'dunning_id': self.id, - 'partner_id': invoice.partner_id.id, - 'invoice_id': invoice.id, - 'date_invoice': invoice.invoice_date, - 'efaktur_id': invoice.efaktur_id.id, - 'reference': invoice.ref, - 'total_amt': invoice.amount_total, - 'open_amt': invoice.amount_residual_signed, - 'due_date': invoice.invoice_date_due - }]) - count += 1 - _logger.info("Dunning Line generated %s" % count) - class DunningRunLine(models.Model): _name = 'dunning.run.line' diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index ab01d476..c251b206 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -5,10 +5,14 @@ dunning.run - + + + + + @@ -39,14 +43,33 @@
- - - +
+ + + +
+ + + + + +
-- cgit v1.2.3 From f960f1c092cdb7669152f8caca7afad314a59877 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 16 Jan 2023 17:00:16 +0700 Subject: change logic api new product --- indoteknik_api/controllers/api_v1/product.py | 39 +++++++++++++++++++++++----- indoteknik_custom/models/product_template.py | 3 +-- indoteknik_custom/views/x_manufactures.xml | 3 --- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 28a63ed5..2e8e0226 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +from datetime import datetime, timedelta import ast @@ -12,20 +13,44 @@ class Product(controller.Controller): if not self.authenticate(): return self.response(code=401, description='Unauthorized') base_url = request.env['ir.config_parameter'].get_param('web.base.url') - query = [('show_as_new_product', '=', True)] - brands = request.env['x_manufactures'].search(query, order='sequence') + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + query_products = [ + ('type', '=', 'product'), + ('active', '=', True), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), + ] + new_products = request.env['product.template'].search(query_products, order='name', limit=500) + brands = [] + for product in new_products: + brands.append(product.x_manufacture) + brands = list(dict.fromkeys(brands)) + data = [] + count = 0 for brand in brands: - query_products = [ - ('is_new_product', '=', True), + count += 1 + if count == 11: + break + query = [ + ('type', '=', 'product'), + ('active', '=', True), ('x_manufacture', '=', brand.id), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query_products, order='name') + products = request.env['product.template'].search(query, order='name', limit=36) data.append({ 'manufacture_id': brand.id, - 'sequence': brand.sequence, + 'sequence': brand.sequence if brand.sequence else count, 'name': brand.x_name, - 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '', + 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str( + brand.id) if brand.x_logo_manufacture else '', 'products': [request.env['product.template'].api_single_response(x) for x in products] }) return self.response(data) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index caf7ea3a..74b4edb1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -57,7 +57,6 @@ class ProductTemplate(models.Model): 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') products = self.env['product.template'].search([ @@ -65,7 +64,7 @@ class ProductTemplate(models.Model): ('active', '=', True), ('product_rating', '>', 3), ('create_date', '>=', delta_time), - ], limit=1000) + ], limit=100) seq = 0 for product in products: diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index cc8fd10c..e51cb6a7 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -43,7 +43,6 @@ - @@ -64,8 +63,6 @@ - - -- cgit v1.2.3 From 379389bb98d2980ed583a564a3d7d0754e63ad52 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:25:23 +0700 Subject: update api new product --- indoteknik_api/controllers/api_v1/product.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 2e8e0226..bf3505e4 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -3,6 +3,9 @@ from odoo import http from odoo.http import request from datetime import datetime, timedelta import ast +import logging + +_logger = logging.getLogger(__name__) class Product(controller.Controller): @@ -33,7 +36,6 @@ class Product(controller.Controller): data = [] count = 0 for brand in brands: - count += 1 if count == 11: break query = [ @@ -44,15 +46,21 @@ class Product(controller.Controller): ('website_description', '!=', False), ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query, order='name', limit=36) + count_products = request.env['product.template'].search_count(query) + if count_products < 5: + _logger.info('Brand Skipped %s' % brand.x_name) + continue + products = request.env['product.template'].search(query, order='name', limit=6) data.append({ 'manufacture_id': brand.id, 'sequence': brand.sequence if brand.sequence else count, 'name': brand.x_name, 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str( brand.id) if brand.x_logo_manufacture else '', + 'products_total': count_products, 'products': [request.env['product.template'].api_single_response(x) for x in products] }) + count += 1 return self.response(data) @http.route(prefix + 'product', auth='public', methods=['GET', 'OPTIONS']) -- cgit v1.2.3 From 27f620c8b98cd2689f46b4c2f2f19c1c1424aa43 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:41:35 +0700 Subject: add param for brand only in new product segment --- indoteknik_api/controllers/api_v1/product.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index bf3505e4..264c3443 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -12,9 +12,12 @@ class Product(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'new_product', auth='public', methods=['GET', 'OPTIONS']) - def get_new_product(self): + def get_new_product(self, **kw): if not self.authenticate(): return self.response(code=401, description='Unauthorized') + + is_brand_only = int(kw.get('is_brand_only', 0)) + base_url = request.env['ir.config_parameter'].get_param('web.base.url') current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -27,7 +30,7 @@ class Product(controller.Controller): ('website_description', '!=', False), ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='name', limit=500) + new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) brands = [] for product in new_products: brands.append(product.x_manufacture) @@ -36,6 +39,16 @@ class Product(controller.Controller): data = [] count = 0 for brand in brands: + if is_brand_only == 1: + data.append({ + 'manufacture_id': brand.id, + 'sequence': brand.sequence if brand.sequence else count, + 'name': brand.x_name, + 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str( + brand.id) if brand.x_logo_manufacture else '', + }) + continue + if count == 11: break query = [ @@ -50,7 +63,7 @@ class Product(controller.Controller): if count_products < 5: _logger.info('Brand Skipped %s' % brand.x_name) continue - products = request.env['product.template'].search(query, order='name', limit=6) + products = request.env['product.template'].search(query, order='name', limit=12) data.append({ 'manufacture_id': brand.id, 'sequence': brand.sequence if brand.sequence else count, -- cgit v1.2.3 From 8f844b005d70dfb473730274ca980a84ae3eb9d7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 09:48:35 +0700 Subject: change min product to 6 in new product api --- indoteknik_api/controllers/api_v1/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 264c3443..ba02b624 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -60,7 +60,7 @@ class Product(controller.Controller): ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) - if count_products < 5: + if count_products < 6: _logger.info('Brand Skipped %s' % brand.x_name) continue products = request.env['product.template'].search(query, order='name', limit=12) -- cgit v1.2.3 From b9724e5d77c702c7418673bac3c711a60e1309d0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 10:26:21 +0700 Subject: remove filter by date in new product --- indoteknik_api/controllers/api_v1/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index ba02b624..7e86bafd 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -28,7 +28,7 @@ class Product(controller.Controller): ('active', '=', True), ('image_128', '!=', False), ('website_description', '!=', False), - ('create_date', '>=', delta_time), + # ('create_date', '>=', delta_time), ] new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) brands = [] @@ -57,7 +57,7 @@ class Product(controller.Controller): ('x_manufacture', '=', brand.id), ('image_128', '!=', False), ('website_description', '!=', False), - ('create_date', '>=', delta_time), + # ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) if count_products < 6: -- cgit v1.2.3 From f77362c452e04c67927d4572a29157922932d6c7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 10:31:02 +0700 Subject: descending new product --- indoteknik_api/controllers/api_v1/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 7e86bafd..fc8e2610 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -30,7 +30,7 @@ class Product(controller.Controller): ('website_description', '!=', False), # ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='create_date', limit=250) + new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) brands = [] for product in new_products: brands.append(product.x_manufacture) @@ -63,7 +63,7 @@ class Product(controller.Controller): if count_products < 6: _logger.info('Brand Skipped %s' % brand.x_name) continue - products = request.env['product.template'].search(query, order='name', limit=12) + products = request.env['product.template'].search(query, order='create_date desc', limit=12) data.append({ 'manufacture_id': brand.id, 'sequence': brand.sequence if brand.sequence else count, -- cgit v1.2.3 From 78b151a7e90e84dfa3898b75cf4440c714ba9305 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 17 Jan 2023 10:38:01 +0700 Subject: change logic generate dunning line --- indoteknik_custom/models/dunning_run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index 56a33578..ed5d7bb5 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -60,7 +60,8 @@ class DunningRun(models.Model): ('move_type', '=', 'out_invoice'), ('state', '=', 'posted'), ('partner_id', '=', partner.id), - ('amount_residual_signed', '>', 0), + # ('amount_residual_signed', '>', 0), + ('date_kirim_tukar_faktur', '=', False), ] invoices = self.env['account.move'].search(query, order='invoice_date') count = 0 -- cgit v1.2.3 From 65929f7a9c00639a7b1c360ebc9870b221aa5339 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 08:22:29 +0700 Subject: remove useless code, add last seen products, add compile product in user activity log --- indoteknik_api/controllers/api_v1/customer.py | 38 +++++++++++++++++++++++++++ indoteknik_api/controllers/api_v1/product.py | 6 ++--- indoteknik_custom/models/user_activity_log.py | 28 +++++++++++++++++++- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/customer.py b/indoteknik_api/controllers/api_v1/customer.py index f6d6d40d..57120751 100644 --- a/indoteknik_api/controllers/api_v1/customer.py +++ b/indoteknik_api/controllers/api_v1/customer.py @@ -7,6 +7,44 @@ import ast class CustomerReview(controller.Controller): prefix = '/api/v1/' + @http.route(prefix + 'last_seen_products', auth='public', methods=['GET', 'OPTIONS']) + def get_last_seen_products(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + + email = str(kw.get('email', '')) + if not email: + return self.response(code=401, description='Unauthorized') + + activity_logs = request.env['user.activity.log'].search([ + ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), + ('email', '=', email), + ], order='create_date desc', limit=5) + + data = [] + templates = [] + for activity_log in activity_logs: + strip_index = i = 0 + for c in activity_log.url: + if c == '-': + strip_index = i + i += 1 + template_id = activity_log.url[strip_index + 1:len(activity_log.url)] + if '#' in template_id: + continue + if any(ch.isalpha() for ch in template_id): + continue + template = request.env['product.template'].search([('id', '=', template_id)]) + templates.append(template) + + data.append({ + 'email': email, + 'products': [request.env['product.template'].api_single_response(x) for x in templates] + }) + return self.response(data) + + + @http.route(prefix + 'customer_review', auth='public', methods=['GET', 'OPTIONS']) def get_customer_review(self, **kw): if not self.authenticate(): diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index fc8e2610..78b03203 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -19,10 +19,10 @@ class Product(controller.Controller): is_brand_only = int(kw.get('is_brand_only', 0)) base_url = request.env['ir.config_parameter'].get_param('web.base.url') - current_time = datetime.now() - delta_time = current_time - timedelta(days=30) + # current_time = datetime.now() + # delta_time = current_time - timedelta(days=30) - delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') query_products = [ ('type', '=', 'product'), ('active', '=', True), diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index bf1414db..3cf7bd58 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -14,14 +14,40 @@ class UserActivityLog(models.Model): res_user_id = fields.Many2one("res.users", string="User") email = fields.Char(string="Email") update_product = fields.Boolean(string="Update Product") + product_id = fields.Many2one('product.template', string='Product') + + def compile_product(self): + logs = self.env['user.activity.log'].search([ + ('email', '!=', False), + ('product_id', '=', False), + ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), + ('url', 'not ilike', 'shopping') + ], limit=1000, order='create_date desc') + for log in logs: + _logger.info(log.url) + strip_index = i = 0 + for c in log.url: + if c == '-': + strip_index = i + i += 1 + product_id = log.url[strip_index + 1:len(log.url)] + if '#' in product_id: + continue + if any(ch.isalpha() for ch in product_id): + continue + product = self.env['product.template'].search([ + ('id', '=', product_id) + ]) + log.product_id = product def clean_activity_log(self): current_time = datetime.now() - delta_time = current_time - timedelta(days=60) + delta_time = current_time - timedelta(days=180) delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') self.env['user.activity.log'].search([ ('create_date', '<', delta_time), + ('email', '=', 'False'), ]).unlink() def reset_rank_search_weekly(self): -- cgit v1.2.3 From f5eecb48f361dd0bc45c2d8b4cf12f34aea5f243 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 13:49:11 +0700 Subject: add brand image in category homepage api --- indoteknik_api/controllers/api_v1/category.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py index 36e67e01..62faff85 100644 --- a/indoteknik_api/controllers/api_v1/category.py +++ b/indoteknik_api/controllers/api_v1/category.py @@ -35,7 +35,8 @@ class Category(controller.Controller): 'name': category.category_id.name, 'image': base_url + 'api/image/website.categories.homepage/image/' + str(category.id) if category.image else '', 'url': category.url, - 'brands': [y.x_name for y in brands], + # 'brands': [y.x_name for y in brands], + 'brands': [request.env['x_manufactures'].api_single_response(y) for y in brands], 'products': [request.env['product.template'].api_single_response(x) for x in products] }) return self.response(data) -- cgit v1.2.3 From 780f1a71a5fe3d053b0163f7be495497c84349d7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 14:34:26 +0700 Subject: add salesname, and achievement in sales target --- indoteknik_custom/models/sales_target.py | 18 ++++++++++++++++++ indoteknik_custom/views/sales_target.xml | 21 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py index ac6405e5..9069fa6a 100644 --- a/indoteknik_custom/models/sales_target.py +++ b/indoteknik_custom/models/sales_target.py @@ -16,6 +16,24 @@ class SalesTarget(models.Model): ongoing_omset_adempiere = fields.Float(string='Omset Berjalan ADempiere') ongoing_omset_total = fields.Float(string='Total Omset', compute='_compute_total_omset') target = fields.Float(string='Target') + ach_per_year = fields.Float(string='Ach/Year%', compute='_compute_achievement') + ach_per_month = fields.Float(string='Ach/Month%', compute='_compute_achievement') + sales_id = fields.Many2one('res.users', string='Salesperson', compute='_compute_salesperson') + + def _compute_salesperson(self): + for sales_target in self: + sales_target.sales_id = sales_target.partner_id.user_id + + def _compute_achievement(self): + for sales_target in self: + if not sales_target.target or sales_target.target <= 0: + sales_target.ach_per_year = 0 + sales_target.ach_per_month = 0 + return + current_time = datetime.now() + current_month = current_time.month + sales_target.ach_per_year = sales_target.ongoing_omset_total/sales_target.target*100 + sales_target.ach_per_month = sales_target.ongoing_omset_total/((sales_target.target/12)*current_month) def _compute_total_omset(self): for target in self: diff --git a/indoteknik_custom/views/sales_target.xml b/indoteknik_custom/views/sales_target.xml index 6ccea260..b77ea5d4 100644 --- a/indoteknik_custom/views/sales_target.xml +++ b/indoteknik_custom/views/sales_target.xml @@ -1,26 +1,39 @@ + + sales.target.list.select + sales.target + + + + + + + + Sales Target sales.target + tree,form - Sales Target sales.target + + + - Sales Target sales.target @@ -30,12 +43,16 @@ + + + + -- cgit v1.2.3 From 09c074be5de4fc10f6322303236b5919ff8234fb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 14:37:50 +0700 Subject: add reference number in sales target --- indoteknik_custom/models/sales_target.py | 6 ++++-- indoteknik_custom/views/sales_target.xml | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py index 9069fa6a..c31a4470 100644 --- a/indoteknik_custom/models/sales_target.py +++ b/indoteknik_custom/models/sales_target.py @@ -18,11 +18,13 @@ class SalesTarget(models.Model): target = fields.Float(string='Target') ach_per_year = fields.Float(string='Ach/Year%', compute='_compute_achievement') ach_per_month = fields.Float(string='Ach/Month%', compute='_compute_achievement') - sales_id = fields.Many2one('res.users', string='Salesperson', compute='_compute_salesperson') + sales_id = fields.Many2one('res.users', string='Salesperson', compute='_compute_partner') + reference = fields.Char(string='Reference', compute='_compute_partner') - def _compute_salesperson(self): + def _compute_partner(self): for sales_target in self: sales_target.sales_id = sales_target.partner_id.user_id + sales_target.reference = sales_target.partner_id.reference_number def _compute_achievement(self): for sales_target in self: diff --git a/indoteknik_custom/views/sales_target.xml b/indoteknik_custom/views/sales_target.xml index b77ea5d4..08218913 100644 --- a/indoteknik_custom/views/sales_target.xml +++ b/indoteknik_custom/views/sales_target.xml @@ -43,6 +43,7 @@ + -- cgit v1.2.3 From b33103dea998552d110d029d7f50ed08f58ce192 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 15:57:33 +0700 Subject: add payment term validation in sales order and add website ads --- indoteknik_api/controllers/api_v1/content.py | 20 ++++++++ indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_order.py | 4 ++ indoteknik_custom/models/website_ads.py | 18 +++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/website_ads.xml | 69 ++++++++++++++++++++++++++ 7 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/website_ads.py create mode 100644 indoteknik_custom/views/website_ads.xml diff --git a/indoteknik_api/controllers/api_v1/content.py b/indoteknik_api/controllers/api_v1/content.py index 3d5b15e5..3d4e443a 100644 --- a/indoteknik_api/controllers/api_v1/content.py +++ b/indoteknik_api/controllers/api_v1/content.py @@ -6,6 +6,26 @@ from odoo.http import request class WebsiteContent(controller.Controller): prefix = '/api/v1/' + @http.route(prefix + 'product_ads', auth='public', methods=['GET', 'OPTIONS']) + def get_product_ads(self, **kw): + if not self.authenticate(): + return self.response(code=401, description='Unauthorized') + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + query = [ + ('page', '=', 'product'), + ('status', '=', 'tayang') + ] + ads = request.env['website.ads'].search(query, order='sequence') + data = [] + for ad in ads: + data.append({ + 'id': ad.id, + 'name': ad.name, + 'image': base_url + 'api/image/website.ads/image/' + str(ad.id) if ad.image else '', + 'url': ad.url, + }) + return self.response(data) + @http.route(prefix + 'video_content', auth='public', methods=['GET', 'OPTIONS']) def get_video_content(self, **kw): if not self.authenticate(): diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 908e74df..66184081 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -57,6 +57,7 @@ 'views/website_content_channel.xml', 'views/website_content.xml', 'views/custom_mail_marketing.xml', + 'views/website_ads.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 8ada3b95..5d5ad0ec 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -44,3 +44,4 @@ from . import x_biaya_kirim from . import x_manufactures from . import x_partner_purchase_order from . import x_product_tags +from . import website_ads diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index c8937ca4..5a4a653b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -197,11 +197,15 @@ class SaleOrder(models.Model): raise UserError("Payment Term pada Master Data Customer harus diisi") if not order.partner_id.parent_id.active_limit: raise UserError("Credit Limit pada Master Data Customer harus diisi") + if order.payment_term_id != order.partner_id.parent_id.property_payment_term_id: + raise UserError("Payment Term berbeda pada Master Data Customer") else: if not order.partner_id.property_payment_term_id: raise UserError("Payment Term pada Master Data Customer harus diisi") if not order.partner_id.active_limit: raise UserError("Credit Limit pada Master Data Customer harus diisi") + if order.payment_term_id != order.partner_id.property_payment_term_id: + raise UserError("Payment Term berbeda pada Master Data Customer") if not order.sales_tax_id: raise UserError("Tax di Header harus diisi") if not order.carrier_id: diff --git a/indoteknik_custom/models/website_ads.py b/indoteknik_custom/models/website_ads.py new file mode 100644 index 00000000..ec360294 --- /dev/null +++ b/indoteknik_custom/models/website_ads.py @@ -0,0 +1,18 @@ +from odoo import fields, models + + +class WebsiteAds(models.Model): + _name = 'website.ads' + + sequence = fields.Integer(string='Sequence') + name = fields.Char(string='Name') + image = fields.Binary(string='Image') + url = fields.Char(string='URL') + page = fields.Selection([ + ('product', 'Product'), + ('homepage', 'Home Page') + ], string='Page') + status = fields.Selection([ + ('tayang', 'Tayang'), + ('tidak_tayang', 'Tidak Tayang') + ], string='Status') diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 5eefa618..9349a566 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -25,4 +25,5 @@ access_customer_review,access.customer.review,model_customer_review,,1,1,1,1 access_website_content_channel,access.website.content.channel,model_website_content_channel,,1,1,1,1 access_website_content,access.website.content,model_website_content,,1,1,1,1 access_invoice_reklas,access.invoice.reklas,model_invoice_reklas,,1,1,1,1 -access_custom_mail_marketing,access.custom.mail.marketing,model_custom_mail_marketing,,1,1,1,1 \ No newline at end of file +access_custom_mail_marketing,access.custom.mail.marketing,model_custom_mail_marketing,,1,1,1,1 +access_website_ads,access.website.ads,model_website_ads,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/website_ads.xml b/indoteknik_custom/views/website_ads.xml new file mode 100644 index 00000000..b66b0346 --- /dev/null +++ b/indoteknik_custom/views/website_ads.xml @@ -0,0 +1,69 @@ + + + + + website.ads.list.select + website.ads + + + + + + + + + + + + + Website Ads + website.ads + + tree,form + + + + Website Ads + website.ads + + + + + + + + + + + + + + Website Ads + website.ads + +
+ + + + + + + + + + + + +
+
+
+ + +
+
\ No newline at end of file -- cgit v1.2.3 From 064a4c0462e68edf89eadee6b5bc7c6508fe30eb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 10:59:33 +0700 Subject: new product must have manufacture id (brand) --- indoteknik_api/controllers/api_v1/product.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 78b03203..cfa2dbef 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -28,6 +28,8 @@ class Product(controller.Controller): ('active', '=', True), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) @@ -57,6 +59,8 @@ class Product(controller.Controller): ('x_manufacture', '=', brand.id), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) -- cgit v1.2.3 From 74e22ea21d16389937fe8d571a475218fda7ffa5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 11:59:23 +0700 Subject: add cache reset stock vendor --- indoteknik_custom/models/stock_vendor.py | 24 +++++++++++++++++++----- indoteknik_custom/views/stock_vendor.xml | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index 1a6b4a64..07b0e5b6 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -11,6 +11,20 @@ class StockVendor(models.Model): product_variant_id = fields.Many2one("product.product", string="Product Variant") quantity = fields.Integer(string="Quantity") + cache_reset_status = fields.Selection([ + ('reset', 'Reset'), + ('done', 'Done') + ], string="Cache Reset") + + def cache_reset(self): + stocks = self.env['stock.vendor'].search([ + ('cache_reset_status', '=', 'reset'), + ]) + for stock in stocks: + if stock.product_variant_id.product_tmpl_id.solr_flag == 1: + stock.product_variant_id.product_tmpl_id.solr_flag = 2 + _logger.info('Update Solr Flag to 2 %s' % stock.product_variant_id.product_tmpl_id.name) + stock.cache_reset_status = 'done' def update_product_template(self): updated_virtual_qty_product_template = self.env['ir.config_parameter'].search([('key', '=', 'updated_virtual_qty_product_template')], limit=1) @@ -30,8 +44,8 @@ class StockVendor(models.Model): template.virtual_qty = template.qty_stock_vendor or 0 _logger.info("Update Stock Product Template %s : %s" % (template.id, template.virtual_qty)) - @api.onchange('quantity') - def update_solr_flag(self): - for stock in self: - if stock.product_variant_id.product_tmpl_id.solr_flag == 1: - stock.product_variant_id.product_tmpl_id.solr_flag = 2 + # @api.onchange('quantity') + # def update_solr_flag(self): + # for stock in self: + # if stock.product_variant_id.product_tmpl_id.solr_flag == 1: + # stock.product_variant_id.product_tmpl_id.solr_flag = 2 diff --git a/indoteknik_custom/views/stock_vendor.xml b/indoteknik_custom/views/stock_vendor.xml index ebf63a6a..35931750 100755 --- a/indoteknik_custom/views/stock_vendor.xml +++ b/indoteknik_custom/views/stock_vendor.xml @@ -18,6 +18,7 @@ +
@@ -33,6 +34,7 @@ + -- cgit v1.2.3 From cf29c503c23a76cfe0038fa7faa7be36d5f969ae Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 14:47:10 +0700 Subject: back to leads scheduler --- indoteknik_custom/models/crm_lead.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index e0a90d9c..3c8b842b 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -11,6 +11,15 @@ class CrmLead(models.Model): file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan") body_html_lead = fields.Text('Body HTML', compute='compute_body_leads') + def revert_to_leads(self): + opportunities = self.env['crm.lead'].search([ + ('type', '=', 'opportunity'), + ('active', '=', True), + ('user_id', '=', False), + ]) + for opportunity in opportunities: + opportunity.type = 'lead' + @api.onchange('stage_id') def update_stars(self): for lead in self: -- cgit v1.2.3 From cf92957930fde29f7c04859593cb296bd8699c61 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 20 Jan 2023 14:24:04 +0700 Subject: add cache reset for stock vendor (solr_flag) --- indoteknik_custom/models/stock_vendor.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index 07b0e5b6..1e5bce16 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -20,26 +20,32 @@ class StockVendor(models.Model): stocks = self.env['stock.vendor'].search([ ('cache_reset_status', '=', 'reset'), ]) + + templates = [] for stock in stocks: - if stock.product_variant_id.product_tmpl_id.solr_flag == 1: - stock.product_variant_id.product_tmpl_id.solr_flag = 2 - _logger.info('Update Solr Flag to 2 %s' % stock.product_variant_id.product_tmpl_id.name) - stock.cache_reset_status = 'done' + templates.append(stock.product_variant_id.product_tmpl_id) + # stock.cache_reset_status = 'done' + templates = list(dict.fromkeys(templates)) + + for template in templates: + if template.solr_flag == 1: + template.solr_flag = 2 + _logger.info('Update Solr Flag to 2 %s' % template.name) def update_product_template(self): updated_virtual_qty_product_template = self.env['ir.config_parameter'].search([('key', '=', 'updated_virtual_qty_product_template')], limit=1) updated_virtual_qty_product_template_value = int(updated_virtual_qty_product_template.value) - + limit = 10000 query = [('active', '=', True), ('type', '=', 'product')] templates = self.env['product.template'].search(query, limit=limit, offset=updated_virtual_qty_product_template_value) template_count = self.env['product.template'].search_count(query) - + if (updated_virtual_qty_product_template_value + limit) > template_count: updated_virtual_qty_product_template.value = '0' else: updated_virtual_qty_product_template.value = str(limit + updated_virtual_qty_product_template_value) - + for template in templates: template.virtual_qty = template.qty_stock_vendor or 0 _logger.info("Update Stock Product Template %s : %s" % (template.id, template.virtual_qty)) -- cgit v1.2.3 From c54083f55d4d1990d8325fff063896b3bc0f6fb2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 08:54:07 +0700 Subject: add condition search rank weekly --- indoteknik_custom/models/user_activity_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 3cf7bd58..16084037 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -70,6 +70,7 @@ class UserActivityLog(models.Model): activity_logs = self.env['user.activity.log'].search([ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), ('create_date', '>', delta_time), + ('url', 'not ilike', 'shopping'), ], limit=4000) for activity_log in activity_logs: _logger.info(activity_log.url) -- cgit v1.2.3 From 4bc68435bc20d7da0f38bd2370057481cb995584 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 10:52:49 +0700 Subject: add dynamic limit for new product --- indoteknik_api/controllers/api_v1/product.py | 4 +++- indoteknik_custom/models/user_activity_log.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index cfa2dbef..23dcf48e 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -19,6 +19,8 @@ class Product(controller.Controller): is_brand_only = int(kw.get('is_brand_only', 0)) base_url = request.env['ir.config_parameter'].get_param('web.base.url') + limit_new_products = request.env['ir.config_parameter'].get_param('limit.new.product') + limit_new_products = int(limit_new_products) # current_time = datetime.now() # delta_time = current_time - timedelta(days=30) @@ -32,7 +34,7 @@ class Product(controller.Controller): ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) + new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=limit_new_products) brands = [] for product in new_products: brands.append(product.x_manufacture) diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 16084037..32b389a1 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -71,7 +71,7 @@ class UserActivityLog(models.Model): ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), ('create_date', '>', delta_time), ('url', 'not ilike', 'shopping'), - ], limit=4000) + ], limit=1000) for activity_log in activity_logs: _logger.info(activity_log.url) strip_index = i = 0 -- cgit v1.2.3 From 8af5ee591aabc2d5d946c0eece93a5caab989975 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 23 Jan 2023 14:44:12 +0700 Subject: Fix get api image logic --- indoteknik_api/models/product_product.py | 8 +++----- indoteknik_api/models/product_template.py | 13 ++++++------- indoteknik_api/models/x_manufactures.py | 6 +++--- indoteknik_custom/models/ir_attachment.py | 15 ++++++++++++++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 6b02d91e..2e84b9f4 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -5,7 +5,6 @@ class ProductProduct(models.Model): _inherit = 'product.product' def api_single_response(self, product_product): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id') product_pricelist_default_discount_id = int(product_pricelist_default_discount_id) product_template = product_product.product_tmpl_id @@ -14,7 +13,7 @@ class ProductProduct(models.Model): 'parent': { 'id': product_template.id, 'name': product_template.name, - 'image': base_url + 'api/image/product.template/image_256/' + str(product_template.id) if product_template.image_256 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id), }, 'code': product_product.default_code or '', 'name': product_product.display_name, @@ -27,13 +26,12 @@ class ProductProduct(models.Model): return data def api_manufacture(self, product_template): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') if product_template.x_manufacture: manufacture = product_template.x_manufacture return { 'id': manufacture.id, 'name': manufacture.x_name, - 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '', - 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '', + 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), + 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } return {} \ No newline at end of file diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index 9e8d04bc..72dda17f 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -5,12 +5,11 @@ class ProductTemplate(models.Model): _inherit = 'product.template' def api_single_response(self, product_template, with_detail=''): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id') product_pricelist_default_discount_id = int(product_pricelist_default_discount_id) data = { 'id': product_template.id, - 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id), 'code': product_template.default_code or '', 'name': product_template.name, 'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default_discount_id), @@ -23,7 +22,7 @@ class ProductTemplate(models.Model): if with_detail != '': data_with_detail = { - 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id), 'display_name': product_template.display_name, 'variants': [self.env['product.product'].api_single_response(variant) for variant in product_template.product_variant_ids], 'description': product_template.website_description or '', @@ -31,12 +30,13 @@ class ProductTemplate(models.Model): data.update(data_with_detail) if with_detail == 'SOLR': + is_image_found = self.env['ir.attachment'].is_found('product.template', 'image_128', product_template.id) rate = 0 if data['lowest_price']['price'] > 0: rate += 1 if product_template.have_promotion_program: rate += 1 - if product_template.image_128: + if is_image_found: rate += 1 if product_template.website_description: rate += 1 @@ -52,14 +52,13 @@ class ProductTemplate(models.Model): return data def api_manufacture(self, product_template): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') if product_template.x_manufacture: manufacture = product_template.x_manufacture return { 'id': manufacture.id, 'name': manufacture.x_name, - 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '', - 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '', + 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), + 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } return {} diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py index 19fdcb9c..988d7a45 100644 --- a/indoteknik_api/models/x_manufactures.py +++ b/indoteknik_api/models/x_manufactures.py @@ -8,16 +8,16 @@ class Manufactures(models.Model): base_url = self.env['ir.config_parameter'].get_param('web.base.url') data = { 'id': manufacture.id, - 'logo': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(manufacture.id) if manufacture.x_logo_manufacture else '', + 'logo': self.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', manufacture.id), 'name': manufacture.x_name } if with_detail: data_with_detail = { 'description': manufacture.x_short_desc, 'banners': [ - base_url + 'api/image/x_banner.banner/x_banner_image/' + str(x.id) + self.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', x.id) for x in manufacture.x_manufactures_banners - if x.x_status_banner == 'tayang' and x.x_banner_image + if x.x_status_banner == 'tayang' ] } data.update(data_with_detail) diff --git a/indoteknik_custom/models/ir_attachment.py b/indoteknik_custom/models/ir_attachment.py index 278eb938..fd86ab1b 100644 --- a/indoteknik_custom/models/ir_attachment.py +++ b/indoteknik_custom/models/ir_attachment.py @@ -9,4 +9,17 @@ class Attachment(models.Model): @api.autovacuum def _gc_file_store(self): - _logger.info("filestore gc checked, removed - override") \ No newline at end of file + _logger.info("filestore gc checked, removed - override") + + def is_found(self, model, field, id): + attachment = self.search([ + ('res_model', '=', model), + ('res_field', '=', field), + ('res_id', '=', int(id)) + ]) + return True if attachment else False + + def api_image(self, model, field, id): + base_url = self.env['ir.config_parameter'].get_param('web.base.url') + is_found = self.is_found(model, field, id) + return base_url + 'api/image/' + model + '/' + field + '/' + str(id) if is_found else '' \ No newline at end of file -- cgit v1.2.3