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 ++- 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'indoteknik_custom/models') 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") -- 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(-) (limited to 'indoteknik_custom/models') 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(-) (limited to 'indoteknik_custom/models') 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 ++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 34 deletions(-) (limited to 'indoteknik_custom/models') 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' -- 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_custom/models/product_template.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indoteknik_custom/models') 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: -- 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(-) (limited to 'indoteknik_custom/models') 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_custom/models/user_activity_log.py | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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 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 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'indoteknik_custom/models') 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: -- 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 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') 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: -- 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_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_order.py | 4 ++++ indoteknik_custom/models/website_ads.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 indoteknik_custom/models/website_ads.py (limited to 'indoteknik_custom/models') 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') -- 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 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models') 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 -- 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(+) (limited to 'indoteknik_custom/models') 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(-) (limited to 'indoteknik_custom/models') 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(+) (limited to 'indoteknik_custom/models') 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_custom/models/user_activity_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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_custom/models/ir_attachment.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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