From edbe1a8e8571b8e6694e34929bdc29997b269332 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 18 Apr 2023 14:57:00 +0700 Subject: fix undefined salesperson in leads --- indoteknik_custom/models/crm_lead.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index 1f37005d..bd5cdd26 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -59,8 +59,10 @@ class CrmLead(models.Model): if not lead.partner_id: continue if not lead.user_id or lead.user_id.id == 2: - if lead.partner_id.parent_id: + if lead.partner_id.parent_id.user_id: salesperson_id = lead.partner_id.parent_id.user_id.id - else: + elif lead.partner_id.user_id: salesperson_id = lead.partner_id.user_id.id + else: + salesperson_id = 2 lead.user_id = salesperson_id -- cgit v1.2.3 From aad3d92f97ad443c9288a5b51e618a112deb981e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 26 Apr 2023 14:30:06 +0700 Subject: add rajaongkir id --- indoteknik_api/models/res_users.py | 1 + indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/raja_ongkir.py | 16 ++++++++++++++++ indoteknik_custom/views/raja_ongkir.xml | 27 +++++++++++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 indoteknik_custom/models/raja_ongkir.py create mode 100644 indoteknik_custom/views/raja_ongkir.xml diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py index 5032f3af..84edb2b1 100644 --- a/indoteknik_api/models/res_users.py +++ b/indoteknik_api/models/res_users.py @@ -38,6 +38,7 @@ class ResUsers(models.Model): 'industry_id': user.industry_id.id or None, 'tax_name': user.nama_wajib_pajak or '', 'npwp': user.npwp or '', + 'rajaongkir_city_id': user.kota_id.rajaongkir_id or 0, } if user.kota_id: diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index e2c6eedd..cff7d212 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -70,6 +70,7 @@ 'views/wati.xml', 'views/midtrans.xml', 'views/automatic_purchase.xml', + 'views/raja_ongkir.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 679004d1..d6c88f7d 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -58,3 +58,4 @@ from . import uangmuka_penjualan from . import uangmuka_pembelian from . import automatic_purchase from . import apache_solr +from . import raja_ongkir diff --git a/indoteknik_custom/models/raja_ongkir.py b/indoteknik_custom/models/raja_ongkir.py new file mode 100644 index 00000000..a9ef2e83 --- /dev/null +++ b/indoteknik_custom/models/raja_ongkir.py @@ -0,0 +1,16 @@ +from odoo import fields, models, api +import logging +import json + +_logger = logging.getLogger(__name__) + +class State(models.Model): + _inherit = 'res.country.state' + + rajaongkir_id = fields.Integer(string='RajaOngkir_ID', help='mapping dengan rajaongkir berdasarkan ID') + + +class Kota(models.Model): + _inherit = 'vit.kota' + + rajaongkir_id = fields.Integer(string='RajaOngkir_ID', help='mapping dengan rajaongkir berdasarkan ID') diff --git a/indoteknik_custom/views/raja_ongkir.xml b/indoteknik_custom/views/raja_ongkir.xml new file mode 100644 index 00000000..4eb19b02 --- /dev/null +++ b/indoteknik_custom/views/raja_ongkir.xml @@ -0,0 +1,27 @@ + + + + + State + res.country.state + + + + + + + + + + + Kota + vit.kota + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 04216fb6fc1ecc1bba78b7f0ed50195d3876b287 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 27 Apr 2023 10:41:15 +0700 Subject: add menu procurement monitoring --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + .../models/procurement_monitoring_detail.py | 55 ++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- .../views/procurement_monitoring_detail.xml | 41 ++++++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/procurement_monitoring_detail.py create mode 100644 indoteknik_custom/views/procurement_monitoring_detail.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index cff7d212..df74375f 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -71,6 +71,7 @@ 'views/midtrans.xml', 'views/automatic_purchase.xml', 'views/raja_ongkir.xml', + 'views/procurement_monitoring_detail.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 d6c88f7d..68b7df93 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -59,3 +59,4 @@ from . import uangmuka_pembelian from . import automatic_purchase from . import apache_solr from . import raja_ongkir +from . import procurement_monitoring_detail diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py new file mode 100644 index 00000000..348fce68 --- /dev/null +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -0,0 +1,55 @@ +from odoo import fields, models, api, tools +import logging + +_logger = logging.getLogger(__name__) + + +class SaleMonitoringDetail(models.Model): + _name = 'procurement.monitoring.detail' + _auto = False + _rec_name = 'sale_order_id' + + id = fields.Integer() + sale_order_id = fields.Many2one("sale.order", string="Sale Order") + partner_id = fields.Many2one("res.partner", string="Customer") + user_id = fields.Many2one("res.users", string="Salesperson") + product_id = fields.Many2one("product.product", string="Product") + qty_so = fields.Integer(string="Qty SO") + qty_reserved = fields.Integer(string="Qty Reserved") + qty_available = fields.Integer(string="Qty Available") + qty_po = fields.Integer(string="Qty PO") + date_order = fields.Datetime(string="Date Order") + status = fields.Char(string="Status") + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS ( + SELECT + *, + a.qty_so-a.qty_reserved as qty_po, + case when a.qty_so-a.qty_reserved > 0 then 'harus beli' + else 'cukup' end as status + FROM + ( + SELECT + sol.id AS id, + so.id AS sale_order_id, + so.partner_id as partner_id, + so.user_id, + p.id AS product_id, + sol.product_uom_qty AS qty_so, + get_qty_available(sol.product_id) as qty_available, + get_qty_reserved(so.id, sol.product_id) as qty_reserved, + so.date_order AS date_order + FROM sale_order so + JOIN sale_order_line sol ON sol.order_id = so.id + JOIN product_product p ON p.id = sol.product_id + JOIN product_template pt ON pt.id = p.product_tmpl_id + WHERE pt.type IN ('consu','product') + AND so.state IN ('sale','done') + AND so.create_date >= '2022-08-10' + and so.so_status not in ('terproses') + ) a + ) + """ % self._table) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index f7de6d3f..4abfa123 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -45,4 +45,5 @@ access_automatic_purchase,access.automatic.purchase,model_automatic_purchase,,1, access_automatic_purchase_line,access.automatic.purchase.line,model_automatic_purchase_line,,1,1,1,1 access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_purchase_match,,1,1,1,1 access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1 -access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 \ No newline at end of file +access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 +access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/procurement_monitoring_detail.xml b/indoteknik_custom/views/procurement_monitoring_detail.xml new file mode 100644 index 00000000..4819fccd --- /dev/null +++ b/indoteknik_custom/views/procurement_monitoring_detail.xml @@ -0,0 +1,41 @@ + + + + procurement.monitoring.detail.tree + procurement.monitoring.detail + + + + + + + + + + + + + + + + + + Procurement Monitoring Detail + ir.actions.act_window + procurement.monitoring.detail + tree,form + + + + + \ No newline at end of file -- cgit v1.2.3 From 0de73173e682928c11949fe40babeb64e1a7b2f8 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 27 Apr 2023 11:24:08 +0700 Subject: fix procurement monitoring --- indoteknik_custom/models/procurement_monitoring_detail.py | 7 +++++-- indoteknik_custom/views/procurement_monitoring_detail.xml | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index 348fce68..97d35faf 100644 --- a/indoteknik_custom/models/procurement_monitoring_detail.py +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -17,7 +17,8 @@ class SaleMonitoringDetail(models.Model): qty_so = fields.Integer(string="Qty SO") qty_reserved = fields.Integer(string="Qty Reserved") qty_available = fields.Integer(string="Qty Available") - qty_po = fields.Integer(string="Qty PO") + qty_suggest = fields.Integer(string="Qty Suggest") + qty_po = fields.Integer(string='Qty PO') date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") @@ -27,7 +28,7 @@ class SaleMonitoringDetail(models.Model): CREATE OR REPLACE VIEW %s AS ( SELECT *, - a.qty_so-a.qty_reserved as qty_po, + a.qty_so-a.qty_reserved as qty_suggest, case when a.qty_so-a.qty_reserved > 0 then 'harus beli' else 'cukup' end as status FROM @@ -41,6 +42,7 @@ class SaleMonitoringDetail(models.Model): sol.product_uom_qty AS qty_so, get_qty_available(sol.product_id) as qty_available, get_qty_reserved(so.id, sol.product_id) as qty_reserved, + get_qty_po(so.id, sol.product_id) AS qty_po, so.date_order AS date_order FROM sale_order so JOIN sale_order_line sol ON sol.order_id = so.id @@ -51,5 +53,6 @@ class SaleMonitoringDetail(models.Model): AND so.create_date >= '2022-08-10' and so.so_status not in ('terproses') ) a + where a.qty_po < a.qty_so ) """ % self._table) diff --git a/indoteknik_custom/views/procurement_monitoring_detail.xml b/indoteknik_custom/views/procurement_monitoring_detail.xml index 4819fccd..b3785d14 100644 --- a/indoteknik_custom/views/procurement_monitoring_detail.xml +++ b/indoteknik_custom/views/procurement_monitoring_detail.xml @@ -13,6 +13,7 @@ + Date: Thu, 27 Apr 2023 14:33:12 +0700 Subject: set maturity date if change date in account move --- indoteknik_custom/models/account_move.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index db4886f4..56f3e82c 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -36,6 +36,10 @@ class AccountMove(models.Model): res = super(AccountMove, self).action_post() # if not self.env.user.is_accounting: # raise UserError('Hanya Accounting yang bisa Posting') + if self._name == 'account.move': + for entry in self: + for line in entry.line_ids: + line.date_maturity = entry.date return res def _compute_invoice_day_to_due(self): -- cgit v1.2.3 From 2179e0bad2e1d95f2c3e9e990cc58895e7878628 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Apr 2023 09:07:46 +0700 Subject: fix error syntax --- indoteknik_api/controllers/controller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 5b20f7d4..d4afb672 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -76,7 +76,8 @@ class Controller(http.Controller): alias = next((r.replace('alias:', '') for r in rules if r.startswith('alias:')), key) default = next((r.replace('default:', '') for r in rules if r.startswith('default:')), None) - if (value := kw.get(key, '')) in ['null', 'undefined']: + value = kw.get(key, '') + if value in ['null', 'undefined']: value = '' if 'required' in rules and not value: result['reason'].append(f"{key} is required") -- cgit v1.2.3 From a34aee6c9d0dd732d99f6b52c2697781a9bb4cd0 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Apr 2023 09:20:59 +0700 Subject: solr --- indoteknik_custom/models/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 3709e88a..4f30d6f6 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,8 +13,8 @@ class ApacheSolr(models.Model): _order = 'id desc' def _sync_product_to_solr(self, limit=500): - # _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) - _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) + _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) + # _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() _logger.info('run sync to solr...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] -- cgit v1.2.3 From 8439e05c346afb0e282ff172528b7292756f3823 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Apr 2023 09:48:16 +0700 Subject: fix error login api --- indoteknik_api/controllers/api_v1/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 5edb208e..d82152b7 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -16,7 +16,7 @@ class User(controller.Controller): ]) def response_with_token(self, user): - data = request.env['res.users'].api_single_response(user) + data = request.env['res.users'].sudo().api_single_response(user) data['token'] = self.create_user_token(user) return data -- cgit v1.2.3 From 508147aa709a936acbb7a7d0d988660ea553d58c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 28 Apr 2023 10:23:50 +0700 Subject: add outgoing and incoming qty product --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/views/product_product.xml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 indoteknik_custom/views/product_product.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index df74375f..c6b20e38 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -72,6 +72,7 @@ 'views/automatic_purchase.xml', 'views/raja_ongkir.xml', 'views/procurement_monitoring_detail.xml', + 'views/product_product.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/views/product_product.xml b/indoteknik_custom/views/product_product.xml new file mode 100644 index 00000000..d3ef3e15 --- /dev/null +++ b/indoteknik_custom/views/product_product.xml @@ -0,0 +1,16 @@ + + + + + Product Product + product.product + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 9a293f7f718e5536dfaf57926657ad1d6dd5c581 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 28 Apr 2023 13:47:19 +0700 Subject: add field for top banner in flash sale --- indoteknik_api/controllers/api_v1/flash_sale.py | 1 + indoteknik_custom/models/product_pricelist.py | 1 + indoteknik_custom/views/product_pricelist.xml | 3 +++ 3 files changed, 5 insertions(+) diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py index a0aaa44e..dc7c3928 100644 --- a/indoteknik_api/controllers/api_v1/flash_sale.py +++ b/indoteknik_api/controllers/api_v1/flash_sale.py @@ -27,6 +27,7 @@ class FlashSale(controller.Controller): 'name': pricelist.name, 'banner': request.env['ir.attachment'].api_image('product.pricelist', 'banner', pricelist.id), 'banner_mobile': request.env['ir.attachment'].api_image('product.pricelist', 'banner_mobile', pricelist.id), + 'banner_top': request.env['ir.attachment'].api_image('product.pricelist', 'banner_top', pricelist.id), 'duration': round((pricelist.end_date - datetime.now()).total_seconds()), 'product_total': request.env['product.pricelist.item'].search_count(query), }) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index a309945d..2edaeb80 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -14,6 +14,7 @@ class ProductPricelist(models.Model): ('all', 'For All User'), ('registered_user', 'Only for Registered User') ], string='Flashsale Option') + banner_top = fields.Binary(string='Banner Top') class ProductPricelistItem(models.Model): diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 4cf06e18..0ad9e200 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -17,6 +17,9 @@ + Date: Fri, 28 Apr 2023 16:24:09 +0700 Subject: add banner color field --- indoteknik_api/controllers/api_v1/banner.py | 1 + indoteknik_custom/models/x_banner_banner.py | 1 + indoteknik_custom/views/x_banner_banner.xml | 1 + 3 files changed, 3 insertions(+) diff --git a/indoteknik_api/controllers/api_v1/banner.py b/indoteknik_api/controllers/api_v1/banner.py index 4db320ed..1bd0fea6 100644 --- a/indoteknik_api/controllers/api_v1/banner.py +++ b/indoteknik_api/controllers/api_v1/banner.py @@ -31,6 +31,7 @@ class Banner(controller.Controller): data.append({ 'name': banner.x_name, 'url': banner.x_url_banner, + 'background_color': banner.background_color, 'image': request.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banner.id), }) diff --git a/indoteknik_custom/models/x_banner_banner.py b/indoteknik_custom/models/x_banner_banner.py index bc80e2a9..c34b7634 100755 --- a/indoteknik_custom/models/x_banner_banner.py +++ b/indoteknik_custom/models/x_banner_banner.py @@ -8,6 +8,7 @@ class XBannerBanner(models.Model): x_name = fields.Char(string="Name") x_url_banner = fields.Char(string="URL Banner") + background_color = fields.Char(string="Background Color") x_banner_image = fields.Binary(string="Image") x_banner_category = fields.Many2one('x_banner.category', string="Banner Category") x_relasi_manufacture = fields.Many2one('x_manufactures', string="Relasi Merek") diff --git a/indoteknik_custom/views/x_banner_banner.xml b/indoteknik_custom/views/x_banner_banner.xml index a83ae5ab..4f3f1911 100755 --- a/indoteknik_custom/views/x_banner_banner.xml +++ b/indoteknik_custom/views/x_banner_banner.xml @@ -30,6 +30,7 @@ + -- cgit v1.2.3 From 3285da702db176851e78db9d8afe7af866c31b94 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 29 Apr 2023 10:37:22 +0700 Subject: add po id in procurement monitoring --- .../models/procurement_monitoring_detail.py | 16 +++++++++++++++- .../views/procurement_monitoring_detail.xml | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index 97d35faf..e9da8147 100644 --- a/indoteknik_custom/models/procurement_monitoring_detail.py +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -21,6 +21,20 @@ class SaleMonitoringDetail(models.Model): qty_po = fields.Integer(string='Qty PO') date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") + po_ids = fields.Many2many('purchase.order', string='PO', compute='_compute_po') + + def _compute_po(self): + for line in self: + query = [ + ('order_id.sale_order_id', '=', line.sale_order_id.id), + ('order_id.approval_status', '=', 'approved'), + ('product_id', '=', line.product_id.id), + ] + pos = self.env['purchase.order.line'].search(query) + po_ids = [] + for po in pos: + po_ids.append(po.order_id.id) + line.po_ids = po_ids def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -53,6 +67,6 @@ class SaleMonitoringDetail(models.Model): AND so.create_date >= '2022-08-10' and so.so_status not in ('terproses') ) a - where a.qty_po < a.qty_so + --where a.qty_po < a.qty_so ) """ % self._table) diff --git a/indoteknik_custom/views/procurement_monitoring_detail.xml b/indoteknik_custom/views/procurement_monitoring_detail.xml index b3785d14..8f3827c1 100644 --- a/indoteknik_custom/views/procurement_monitoring_detail.xml +++ b/indoteknik_custom/views/procurement_monitoring_detail.xml @@ -14,6 +14,7 @@ + Date: Tue, 2 May 2023 09:45:45 +0700 Subject: add status validation in procurement monitoring detail --- indoteknik_custom/models/procurement_monitoring_detail.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py index e9da8147..6031e04a 100644 --- a/indoteknik_custom/models/procurement_monitoring_detail.py +++ b/indoteknik_custom/models/procurement_monitoring_detail.py @@ -43,7 +43,8 @@ class SaleMonitoringDetail(models.Model): SELECT *, a.qty_so-a.qty_reserved as qty_suggest, - case when a.qty_so-a.qty_reserved > 0 then 'harus beli' + case when a.qty_po >= a.qty_so then 'cukup' + when a.qty_so-a.qty_reserved > 0 then 'harus beli' else 'cukup' end as status FROM ( -- cgit v1.2.3 From 02d95b8fbc4faf0045d293514ce63de358fa7645 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 2 May 2023 15:16:54 +0700 Subject: add kurir rajaongkir --- indoteknik_api/controllers/api_v1/__init__.py | 1 + indoteknik_api/controllers/api_v1/courier.py | 26 +++++ indoteknik_custom/models/raja_ongkir.py | 8 ++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/raja_ongkir.xml | 152 +++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 indoteknik_api/controllers/api_v1/courier.py diff --git a/indoteknik_api/controllers/api_v1/__init__.py b/indoteknik_api/controllers/api_v1/__init__.py index 5d5f723b..d05cdf3a 100644 --- a/indoteknik_api/controllers/api_v1/__init__.py +++ b/indoteknik_api/controllers/api_v1/__init__.py @@ -23,3 +23,4 @@ from . import customer from . import content from . import midtrans from . import wati +from . import courier diff --git a/indoteknik_api/controllers/api_v1/courier.py b/indoteknik_api/controllers/api_v1/courier.py new file mode 100644 index 00000000..cd3e35c0 --- /dev/null +++ b/indoteknik_api/controllers/api_v1/courier.py @@ -0,0 +1,26 @@ +from .. import controller +from odoo import http +from odoo.http import request + + +class Courier(controller.Controller): + prefix = '/api/v1/' + + @http.route(prefix + 'courier', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_courier(self): + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + query = [ + ('publish', '=', True), + ] + + couriers = request.env['rajaongkir.kurir'].search(query) + data = [] + for courier in couriers: + data.append({ + 'id': courier.delivery_carrier_id.id, + 'name': courier.name, + 'image': base_url + 'api/image/rajaongkir.kurir/image/'+str(courier.id) + }) + return self.response(data) + \ No newline at end of file diff --git a/indoteknik_custom/models/raja_ongkir.py b/indoteknik_custom/models/raja_ongkir.py index a9ef2e83..fa02a6bf 100644 --- a/indoteknik_custom/models/raja_ongkir.py +++ b/indoteknik_custom/models/raja_ongkir.py @@ -4,6 +4,14 @@ import json _logger = logging.getLogger(__name__) +class Kurir(models.Model): + _name = 'rajaongkir.kurir' + + delivery_carrier_id = fields.Many2one('delivery.carrier', String='Odoo Carrier', help='dimapping dengan bawaan delivery carrier di odoo') + name = fields.Char(string='Name', help='nama kurir sesuai dengan data yang ada di API RajaOngkir') + publish = fields.Boolean(string='Publish') + image = fields.Binary(string='Image') + class State(models.Model): _inherit = 'res.country.state' diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 4abfa123..2a5d9879 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -46,4 +46,5 @@ access_automatic_purchase_line,access.automatic.purchase.line,model_automatic_pu access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_purchase_match,,1,1,1,1 access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1 access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 -access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 \ No newline at end of file +access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 +access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/raja_ongkir.xml b/indoteknik_custom/views/raja_ongkir.xml index 4eb19b02..124a91ae 100644 --- a/indoteknik_custom/views/raja_ongkir.xml +++ b/indoteknik_custom/views/raja_ongkir.xml @@ -24,4 +24,156 @@ + + + + Kurir RajaOngkir + rajaongkir.kurir + + + + + + + + + + + + + Kurir RajaOngkir + ir.actions.act_window + rajaongkir.kurir + tree,form + + + + + + jne + 51 + True + + + pos + 53 + True + + + tiki + 54 + True + + + rpx + 55 + True + + + pandu + 56 + True + + + wahana + 7 + True + + + sicepat + 27 + True + + + jnt + 57 + True + + + pahala + 58 + True + + + sap + 59 + True + + + jet + 60 + True + + + indah + 61 + True + + + dse + 62 + True + + + slis + 63 + True + + + first + 64 + True + + + ncs + 65 + True + + + star + 66 + True + + + lion + 67 + True + + + idl + 68 + True + + + rex + 69 + True + + + ide + 70 + True + + + sentral + 71 + True + + + anteraja + 72 + True + + + jtl + 73 + True + + \ No newline at end of file -- cgit v1.2.3 From 515addbceca9df25b3aaf440e8687286620d603a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:09:11 +0700 Subject: update virtual product rating to solr --- indoteknik_custom/models/apache_solr.py | 2 +- indoteknik_custom/models/product_template.py | 63 +++++++++++++--------------- indoteknik_custom/views/product_template.xml | 1 + 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ebe516a0..72584a8f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -73,7 +73,7 @@ class ApacheSolr(models.Model): 'display_name_s': template.display_name, 'name_s': template.name, 'default_code_s': template.default_code or '', - 'product_rating_f': template.product_rating, + 'product_rating_f': template.virtual_rating, 'product_id_i': template.id, 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), 'price_f': price_excl, diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 74b4edb1..a43d8dc2 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -29,6 +29,7 @@ class ProductTemplate(models.Model): have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?") product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website", default=0.0) + virtual_rating = fields.Float('Virtual Rating', compute='_compute_virtual_rating', help="Column Virtual untuk product rating, digunakan oleh Solr", default=0.0) last_calculate_rating = fields.Datetime("Last Calculate Rating") web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0) virtual_qty = fields.Float(string='Virtual Qty', default=0) @@ -53,6 +54,21 @@ class ProductTemplate(models.Model): # vals['solr_flag'] = 2 # return super().write(vals) + def _compute_virtual_rating(self): + for product in self: + rate = 0 + if product.web_price: + rate += 1 + if product.have_promotion_program: #have discount from pricelist + rate += 1 + if product.image_128: + rate += 5 + if product.website_description: + rate += 1 + if product.product_variant_id.qty_stock_vendor > 0: + rate += 1 + product.virtual_rating = rate + def update_new_product(self): current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -111,21 +127,21 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 1), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) price = product_pricelist_item.fixed_price template.web_price = price def _have_promotion_program(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 4), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) discount = product_pricelist_item.price_discount if discount: template.have_promotion_program = True @@ -134,6 +150,7 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): + #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -141,51 +158,29 @@ class ProductTemplate(models.Model): delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ + '&','&', ('type', '=', 'product'), ('active', '=', True), + '|', ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), # ('id', '=', 22798), - ], limit=100) + ], limit=500) for product in products: # print("Calculate Rating Product ", product) _logger.info("Calculate Rating Product %s" % product.id) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) - rate = 0 - if product.web_price: - rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: - rate += 1 - if product.image_128: - rate += 1 - if product.website_description: - rate += 1 - if product_variant.qty_stock_vendor > 0: - rate += 1 - product.product_rating = rate - product.last_calculate_rating = current_time - - products = self.env['product.template'].search([ - ('type', '=', 'product'), - ('active', '=', True), - ('last_calculate_rating', '<', delta_time), - ], limit=100) - - for product in products: - print("Calculate Rating Product OutOfDate", product) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) + # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) rate = 0 if product.web_price: rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: + if product.have_promotion_program: #have discount from pricelist rate += 1 if product.image_128: - rate += 1 + rate += 5 if product.website_description: rate += 1 - if product_variant.qty_stock_vendor > 0: + if product.product_variant_id.qty_stock_vendor > 0: rate += 1 product.product_rating = rate product.last_calculate_rating = current_time diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 5fcb8b05..558805b1 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -53,6 +53,7 @@ + -- cgit v1.2.3 From 58395396f83290cd36b7faf693c0efafc726ad61 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:39:29 +0700 Subject: change rating product --- indoteknik_custom/models/product_template.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index a43d8dc2..49235ec7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -58,15 +58,15 @@ class ProductTemplate(models.Model): for product in self: rate = 0 if product.web_price: - rate += 1 + rate += 4 if product.have_promotion_program: #have discount from pricelist - rate += 1 - if product.image_128: rate += 5 + if product.image_128: + rate += 3 if product.website_description: rate += 1 if product.product_variant_id.qty_stock_vendor > 0: - rate += 1 + rate += 2 product.virtual_rating = rate def update_new_product(self): -- cgit v1.2.3 From 1b31655209df1642d5c6c5e1106c14debddaddfc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:52:28 +0700 Subject: add update product rating to solr --- indoteknik_custom/models/apache_solr.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 72584a8f..04f83532 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -1,19 +1,44 @@ from odoo import models, api, fields from odoo.exceptions import UserError -from datetime import datetime +from datetime import datetime, timedelta import logging import pysolr import time _logger = logging.getLogger(__name__) +_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) class ApacheSolr(models.Model): _name = 'apache.solr' _order = 'id desc' + def _update_rating_product_to_solr(self, limit=1000): + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + templates = self.env['product.template'].search([ + '&','&', + ('type', '=', 'product'), + ('active', '=', True), + '|', + ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), + ], limit=limit) + documents=[] + for template in templates: + document = { + 'id': template.id, + 'product_rating_f': {'set':template.virtual_rating}, + } + documents.append(document) + template.last_calculate_rating = current_time + _logger.info("[SYNC_PRODUCT_RATING_TO_SOLR] Success Set to solr product %s" % template.id) + _solr.add(documents) + def _sync_product_to_solr(self, limit=500): - _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) # _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() _logger.info('run sync to solr...') -- cgit v1.2.3 From afad42a0a2c19339158499a259bef5bb7062f387 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 17:37:04 +0700 Subject: bug fix update rating to solr --- indoteknik_custom/models/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 04f83532..ce6a4180 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -30,8 +30,8 @@ class ApacheSolr(models.Model): documents=[] for template in templates: document = { - 'id': template.id, - 'product_rating_f': {'set':template.virtual_rating}, + "id": template.id, + "product_rating_f": {"set":template.virtual_rating} } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3 From 1d2a045da635445f5331132b1713c392ecb905fa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 4 May 2023 08:57:48 +0700 Subject: change virtual rating to dict from string --- indoteknik_custom/models/apache_solr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ce6a4180..b59f95cc 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -29,9 +29,10 @@ class ApacheSolr(models.Model): ], limit=limit) documents=[] for template in templates: + rating = {"set":template.virtual_rating} document = { "id": template.id, - "product_rating_f": {"set":template.virtual_rating} + "product_rating_f": rating } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3 From 5d0266a4f843a1ba21127a6536a8c37d59c01647 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 4 May 2023 10:27:02 +0700 Subject: new window brand vendor for procurement --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/brand_vendor.py | 13 ++++++ indoteknik_custom/models/x_manufactures.py | 9 ++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/brand_vendor.xml | 60 ++++++++++++++++++++++++++ indoteknik_custom/views/x_manufactures.xml | 1 + 7 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/brand_vendor.py create mode 100644 indoteknik_custom/views/brand_vendor.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index c6b20e38..d9e98975 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -73,6 +73,7 @@ 'views/raja_ongkir.xml', 'views/procurement_monitoring_detail.xml', 'views/product_product.xml', + 'views/brand_vendor.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 68b7df93..5dc9ce9e 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -60,3 +60,4 @@ from . import automatic_purchase from . import apache_solr from . import raja_ongkir from . import procurement_monitoring_detail +from . import brand_vendor \ No newline at end of file diff --git a/indoteknik_custom/models/brand_vendor.py b/indoteknik_custom/models/brand_vendor.py new file mode 100644 index 00000000..0fd122ca --- /dev/null +++ b/indoteknik_custom/models/brand_vendor.py @@ -0,0 +1,13 @@ +from odoo import models, fields +import logging + +_logger = logging.getLogger(__name__) + + +class BrandVendor(models.Model): + _name = 'brand.vendor' + _order = 'id asc' + + x_manufacture_id = fields.Many2one('x_manufactures', string='Manufacture') + partner_id = fields.Many2one('res.partner', string='Vendor') + priority = fields.Integer(string='Priority', default=0) diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index dd6948a9..710bfe8a 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -46,6 +46,15 @@ class XManufactures(models.Model): show_as_new_product = fields.Boolean(string='Show as New Product', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') parent_id = fields.Many2one('x_manufactures', string='Parent', help='Parent Brand tersebut') category_ids = fields.Many2many('product.public.category', string='Category', help='Brand tsb memiliki Category apa saja') + vendor_ids = fields.Many2many('res.partner', string='Vendor', compute='_compute_vendor_ids') + + def _compute_vendor_ids(self): + for manufacture in self: + vendor_ids = [] + brand_vendors = self.env['brand.vendor'].search([('x_manufacture_id', '=', manufacture.id)], order='priority') + for vendor in brand_vendors: + vendor_ids.append(vendor.partner_id.id) + manufacture.vendor_ids = vendor_ids def cache_reset(self): manufactures = self.env['x_manufactures'].search([ diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 2a5d9879..39504393 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -47,4 +47,5 @@ access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_ access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1 access_group_partner,access.group.partner,model_group_partner,,1,1,1,1 access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_procurement_monitoring_detail,,1,1,1,1 -access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 \ No newline at end of file +access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 +access_brand_vendor,access.brand.vendor,model_brand_vendor,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/brand_vendor.xml b/indoteknik_custom/views/brand_vendor.xml new file mode 100644 index 00000000..ee253748 --- /dev/null +++ b/indoteknik_custom/views/brand_vendor.xml @@ -0,0 +1,60 @@ + + + + brand.vendor.tree + brand.vendor + + + + + + + + + + + brand.vendor.form + brand.vendor + +
+ + + + + + + + + +
+
+
+ + + brand.vendor.filter + brand.vendor + + + + + + + + + + + Brand Vendor + ir.actions.act_window + brand.vendor + + tree,form + + + +
\ No newline at end of file diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index ce00c980..a88c5d34 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -49,6 +49,7 @@ + -- cgit v1.2.3 From 17ec32faaa55f9fd1457622f14cab0b770f64afc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 4 May 2023 12:12:10 +0700 Subject: fix lowest price product api --- indoteknik_api/models/product_template.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index b9df0f5f..c3df97a5 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -68,10 +68,17 @@ class ProductTemplate(models.Model): } if with_detail != '': + variants = [self.env['product.product'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids] + lowest_price = variants[0]['price'] + for variant in variants: + if variant["price"]["price_discount"] < lowest_price["price_discount"]: + lowest_price = variant['price'] + data_with_detail = { + 'lowest_price': lowest_price, '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'].v2_api_single_response(variant, pricelist=pricelist) for variant in product_template.product_variant_ids], + 'variants': variants, 'description': product_template.website_description or '', } data.update(data_with_detail) -- cgit v1.2.3 From fdb223d9f940f252470b316cbb01fdc8d209d3c9 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 4 May 2023 14:42:54 +0700 Subject: fix function get_partner_child_ids --- indoteknik_api/controllers/controller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index d4afb672..b850bdde 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -158,6 +158,7 @@ class Controller(http.Controller): partner_child_ids = [x['id'] for x in partner.child_ids] + [partner.id] if partner.parent_id: partner_child_ids += [x['id'] for x in partner.parent_id.child_ids] + partner_child_ids += [partner.parent_id.id] return partner_child_ids @http.route('/api/token', auth='public', methods=['GET', 'OPTIONS']) -- cgit v1.2.3 From f716974b222fdbaeb41ef95c391451e993b9825e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 5 May 2023 13:57:17 +0700 Subject: change salesperson sales order if salesperson in lead changes and add tag for website --- indoteknik_custom/models/crm_lead.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index bd5cdd26..b40bed6e 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -18,6 +18,11 @@ class CrmLead(models.Model): operator_name = fields.Char('Operator Name', help='Operator yang membalas') order_id = fields.Many2one('sale.order', string='Sales Order', help='Link ke sales order id') + @api.onchange('user_id') + def _change_salesperson_so(self): + if self.order_id: + self.order_id.user_id = self.user_id + def revert_to_leads(self): opportunities = self.env['crm.lead'].search([ ('type', '=', 'opportunity'), @@ -49,12 +54,16 @@ class CrmLead(models.Model): # ('id', '=', 12523) ], limit=1000) for lead in leads: - tags = self.env['crm.tag'].search([('id', '>', 0)]) input_tags = [] - for tag in tags: - if tag.name.lower() in lead.body_html_lead.lower(): - input_tags.append(tag.id) - lead.tag_ids = input_tags + if "Ada Quotation dari Website" in lead.name: + input_tags.append(1509) + lead.tag_ids = input_tags + else: + tags = self.env['crm.tag'].search([('id', '>', 0)]) + for tag in tags: + if tag.name.lower() in lead.body_html_lead.lower(): + input_tags.append(tag.id) + lead.tag_ids = input_tags if not lead.partner_id: continue -- cgit v1.2.3 From d97277a0847bc57c0bc704c5ea62f75fadb461dc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 5 May 2023 15:23:50 +0700 Subject: fix speed compute tag in leads --- indoteknik_custom/models/crm_lead.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index b40bed6e..e7af4b1c 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -1,4 +1,7 @@ from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) class CrmLead(models.Model): @@ -54,16 +57,27 @@ class CrmLead(models.Model): # ('id', '=', 12523) ], limit=1000) for lead in leads: + _logger.info('processing tagged lead %s' % lead.id) input_tags = [] - if "Ada Quotation dari Website" in lead.name: - input_tags.append(1509) - lead.tag_ids = input_tags + if lead.order_id: + last_manufacture_id = 0 + for line in lead.order_id.order_line: + tag = self.env['crm.tag'].search([('name', 'ilike', line.product_id.product_tmpl_id.x_manufacture.x_name)], limit=1) + if tag and tag.id != last_manufacture_id: + last_manufacture_id = tag.id + input_tags.append(tag.id) + input_tags.append(1509) #Website hastag + lead.tag_ids = input_tags else: tags = self.env['crm.tag'].search([('id', '>', 0)]) for tag in tags: if tag.name.lower() in lead.body_html_lead.lower(): input_tags.append(tag.id) - lead.tag_ids = input_tags + if input_tags: + lead.tag_ids = input_tags + else: + input_tags.append(1510) #no tag + lead.tag_ids = input_tags if not lead.partner_id: continue -- cgit v1.2.3