summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-23 14:41:48 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-23 14:41:48 +0700
commitae475a8d1dc9fa291d079e00d4194c55a0bb408c (patch)
tree82a7d96f161e1c0b2ece24171bd5ac3d4f4484d7 /indoteknik_custom/models
parent6538d8958c541e208df9a5fd83d5bdd5a0ae021c (diff)
parentde4a6c2c2ce115d169a3a85548ff95c8789e25c8 (diff)
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/blog_post.py26
-rwxr-xr-xindoteknik_custom/models/crm_lead.py4
-rwxr-xr-xindoteknik_custom/models/sale_order.py7
-rw-r--r--indoteknik_custom/models/stock_picking.py7
-rw-r--r--indoteknik_custom/models/wati.py90
-rwxr-xr-xindoteknik_custom/models/x_manufactures.py2
7 files changed, 135 insertions, 2 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 55eca2e7..62a024e3 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -48,3 +48,4 @@ from . import website_ads
from . import leads_monitoring
from . import midtrans
from . import ip_lookup
+from . import wati
diff --git a/indoteknik_custom/models/blog_post.py b/indoteknik_custom/models/blog_post.py
index 27f0c125..18844f0f 100644
--- a/indoteknik_custom/models/blog_post.py
+++ b/indoteknik_custom/models/blog_post.py
@@ -1,4 +1,9 @@
from odoo import models, fields
+from odoo.exceptions import UserError
+import logging
+import re
+
+_logger = logging.getLogger(__name__)
class BlogPost(models.Model):
@@ -9,3 +14,24 @@ class BlogPost(models.Model):
thumbnail_256 = fields.Image("Thumbnail 256", related="thumbnail", max_width=256, max_height=256, store=True)
thumbnail_512 = fields.Image("Thumbnail 512", related="thumbnail", max_width=512, max_height=512, store=True)
thumbnail_1024 = fields.Image("Thumbnail 1024", related="thumbnail", max_width=1024, max_height=1024, store=True)
+ replace_click = fields.Boolean(string='Replace Clicked', help='Penanda bahwa Replace Keyword sudah di klik atau belum')
+ category_id = fields.Many2one('product.public.category', string='Product Category', help='Untuk replace keyword sesuai product category yang dipilih')
+
+ def replace_keyword_to_link(self):
+ if not self.category_id:
+ return
+ if self.replace_click:
+ raise UserError('Sudah pernah di klik sekali')
+
+ category_name = self.category_id.name
+ category_name = category_name.replace(' ', '+')
+ link_url = '<a href="https://indoteknik.com/shop/search?product_name=' + category_name + '">' + self.category_id.name + '</a>'
+
+ content = self.content
+ compiled = re.compile(re.escape(self.category_id.name), re.IGNORECASE)
+ res = compiled.sub(link_url, content)
+ # content = content.replace(category.name, link_url)
+ self.content = res
+ _logger.info('Blog: Success Replace text to URL %s' % self.id)
+
+ self.replace_click = True
diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py
index 3c8b842b..0534eb2f 100755
--- a/indoteknik_custom/models/crm_lead.py
+++ b/indoteknik_custom/models/crm_lead.py
@@ -10,6 +10,10 @@ class CrmLead(models.Model):
file_tdp = fields.Binary(string="Tanda Daftar Perusahaan")
file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan")
body_html_lead = fields.Text('Body HTML', compute='compute_body_leads')
+ # for wati only
+ ticket_id = fields.Char('Ticket ID', help='Ticket ID yang ada di WATI')
+ operator_email = fields.Char('Operator Email', help='Operator yang membalas')
+ operator_name = fields.Char('Operator Name', help='Operator yang membalas')
def revert_to_leads(self):
opportunities = self.env['crm.lead'].search([
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index b172b94c..f17ccee5 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -68,6 +68,7 @@ class SaleOrder(models.Model):
('partial_chargeback', 'Partial Chargeback'),
('authorize', 'Authorize'),
], string='Payment Status', help='Payment Gateway Status / Midtrans / Web, https://docs.midtrans.com/en/after-payment/status-cycle')
+ date_doc_kirim = fields.Datetime(string='Tanggal Kirim di SJ', help="Tanggal Kirim di cetakan SJ yang terakhir, tidak berpengaruh ke Accounting")
def _generate_access_token(self, limit):
orders = self.search(['access_token', '=', False], limit=limit)
@@ -111,10 +112,9 @@ class SaleOrder(models.Model):
def calculate_so_status(self):
so_state = ['sale']
- so_status = ['sebagian', 'menunggu']
sales = self.env['sale.order'].search([
('state', 'in', so_state),
- ('so_status', 'in', so_status),
+ ('so_status', '!=', 'terproses'),
])
for sale in sales:
sum_qty_ship = sum_qty_so = 0
@@ -222,6 +222,9 @@ class SaleOrder(models.Model):
raise UserError('Gudang harus Bandengan')
if order.state == 'cancel' or order.state == 'done' or order.state == 'sale':
raise UserError("Status harus draft atau sent")
+ if not order.partner_invoice_id.npwp:
+ raise UserError("NPWP harus diisi di master data konsumen, jika non pkp dapat diisi 00.000.000.0-000.000")
+
if order.partner_id.parent_id:
if not order.partner_id.parent_id.property_payment_term_id:
raise UserError("Payment Term pada Master Data Customer harus diisi")
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 2c75ccbc..1dba31a3 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -56,6 +56,13 @@ class StockPicking(models.Model):
('pengajuan1', 'Approval Accounting'),
('approved', 'Approved'),
], string='Approval Return Status', readonly=True, copy=False, index=True, tracking=3, help="Approval Status untuk Return")
+ date_doc_kirim = fields.Datetime(string='Tanggal Kirim di SJ', help="Tanggal Kirim di cetakan SJ, tidak berpengaruh ke Accounting")
+
+ @api.onchange('date_doc_kirim')
+ def update_date_doc_kirim_so(self):
+ if not self.sale_id:
+ return
+ self.sale_id.date_doc_kirim = self.date_doc_kirim
def action_assign(self):
res = super(StockPicking, self).action_assign()
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py
new file mode 100644
index 00000000..df467ea1
--- /dev/null
+++ b/indoteknik_custom/models/wati.py
@@ -0,0 +1,90 @@
+from odoo import fields, models, api
+from datetime import datetime, timedelta
+import logging
+import json
+
+_logger = logging.getLogger(__name__)
+
+
+class WatiNotification(models.Model):
+ _name = 'wati.notification'
+
+ json_raw = fields.Char(string='JSON Raw Text')
+ is_lead = fields.Boolean(string='To Leads', help='apakah sudah ter-convert jadi leads')
+
+ def _cleanup(self):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=15)
+
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ self.env['wati.notification'].search([
+ ('create_date', '<', delta_time),
+ ('is_lead', '=', True),
+ ]).unlink()
+ _logger.info('Success Cleanup WATI Notification')
+
+
+ def _convert_to_leads(self):
+ query = [
+ ('is_lead', '=', False)
+ ]
+ watis = self.env['wati.notification'].search(query, order='id')
+
+ for wati in watis:
+ _logger.info('Convert to Lead WATI Notification ID %s' % wati.id)
+ ticket_id = json.loads(wati.json_raw)['ticketId']
+ text = json.loads(wati.json_raw)['text']
+
+ current_lead = self.env['crm.lead'].search([('ticket_id', '=', ticket_id)], limit=1)
+ operator_email = json.loads(wati.json_raw)['operatorEmail']
+ operator_name = json.loads(wati.json_raw)['operatorName']
+ event_type = json.loads(wati.json_raw)['eventType']
+
+ if event_type == 'sessionMessageSent':
+ if 'Saya *Eko*' in str(text):
+ sales = 11
+ elif 'Saya *Nabila*' in str(text):
+ sales = 20
+ elif 'Saya *Novita*' in str(text):
+ sales = 377
+ elif 'Saya *Putri*' in str(text):
+ sales = 10
+ elif 'Saya *Heriyanto*' in str(text):
+ sales = 375
+ elif 'Saya *Ade*' in str(text):
+ sales = 9
+ elif 'Saya *Adela*' in str(text):
+ sales = 8
+ elif 'Saya *Jananto*' in str(text):
+ sales = 376
+ elif 'Saya *Dwi*' in str(text):
+ sales = 24
+ else:
+ sales = 25 #System
+ current_lead.description = str(current_lead.description)+ "| i:" + str(text)
+ current_lead.operator_email = operator_email
+ current_lead.operator_name = operator_name
+ current_lead.user_id = sales
+ wati.is_lead = True
+ elif current_lead:
+ # must append internal notes as a reply here
+ current_lead.description = str(current_lead.description) + " | c:" +str(text)
+ current_lead.operator_email = operator_email
+ current_lead.operator_name = operator_name
+ wati.is_lead = True
+ else:
+ # create new leads
+ contact_name = json.loads(wati.json_raw)['senderName']
+ phone = json.loads(wati.json_raw)['waId']
+ name = 'Ada pesan dari WATI '+str(phone)+' '+str(contact_name)
+
+ self.env['crm.lead'].create([{
+ 'name': name,
+ 'ticket_id': ticket_id,
+ 'operator_email': operator_email,
+ 'operator_name': operator_name,
+ 'contact_name': contact_name,
+ 'phone': phone,
+ 'description': "c:" +str(text)
+ }])
+ wati.is_lead = True
diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py
index e6842797..dd6948a9 100755
--- a/indoteknik_custom/models/x_manufactures.py
+++ b/indoteknik_custom/models/x_manufactures.py
@@ -44,6 +44,8 @@ class XManufactures(models.Model):
], string="Cache Reset")
sequence = fields.Integer(string='Sequence', help='Urutan tampil di homepage jika show as new product')
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')
def cache_reset(self):
manufactures = self.env['x_manufactures'].search([