summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-12-08 14:32:46 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-12-08 14:32:46 +0700
commit37c6b37c68f83a1143c8acdf9b89e05d4d8904fe (patch)
treedc55259d1b4d0d98a1efc84c945c2cbc8ab767ee
parent4dcd1e3e1a3e4dced5a2d0d89d2fd4ee3e1fe7d3 (diff)
parent6f93656ef914f40b13abfb320b539d4e54acac20 (diff)
Merge branch 'production' into change/feature/promotion-program
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py1
-rw-r--r--indoteknik_api/controllers/controller.py4
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/crm_lead.py17
-rw-r--r--indoteknik_custom/models/mail_mail.py2
-rw-r--r--indoteknik_custom/models/wati.py162
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv4
-rw-r--r--indoteknik_custom/views/wati_history.xml116
8 files changed, 282 insertions, 25 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 0f236ffb..62f20ed8 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -296,6 +296,7 @@ class SaleOrder(controller.Controller):
if params['value']['type'] == 'sale_order':
parameters['approval_status'] = 'pengajuan1'
sale_order = request.env['sale.order'].create([parameters])
+ sale_order.onchange_partner_contact()
user_id = params['value']['user_id']
user_cart = request.env['website.user.cart']
diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py
index 12305d92..4d6716b2 100644
--- a/indoteknik_api/controllers/controller.py
+++ b/indoteknik_api/controllers/controller.py
@@ -12,7 +12,7 @@ import functools
class Controller(http.Controller):
- jwt_secret_key = "NTNv7j0TuYARvmNMmWXo6fKvM4o6nvaUi9ryX38ZHL1bkrnD1ObOQ8JAUmHCBq7Iy7otZcyAagBLHVKvvYaIpmMuxmARQ97jUVG16Jkpkp1wXOPsrF9zwew6TpczyHkHgX5EuLg2MeBuiTqJACs1J0apruOOJCggOtkjB4c"
+ jwt_secret_key = "NTNv7j0TuYARvmNMmWXo6fKvM4o6nvaUi9ryX38ZHL1bkrnD1ObOQ8JAUmHCBq7Iy7otZcyAagBLHVKvvYaIpmMuxmARQ97jUVG16Jkpkp1wXOPsrF9zwew6TpczyHkHgX5EuLg2MeBuiTqJACs1J0apruOOJCggOtkjB"
@staticmethod
def must_authorized(private=False, private_key=''):
@@ -28,7 +28,7 @@ class Controller(http.Controller):
self.set_user_pricelist_ctx()
if private:
- auth_key = int(auth[private_key])
+ auth_key = None if isinstance(auth, bool) else auth[private_key]
param_key = int(kwargs.get(private_key, -1))
if auth_key != param_key:
return self.unauthorized_response()
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index bc11b346..39e5cdd9 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -103,6 +103,7 @@
'views/account_bank_statement.xml',
'views/stock_warehouse_orderpoint.xml',
'views/customer_commision.xml',
+ 'views/wati_history.xml',
'report/report.xml',
'report/report_banner_banner.xml',
'report/report_banner_banner2.xml',
diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py
index 689cca30..d181c35b 100755
--- a/indoteknik_custom/models/crm_lead.py
+++ b/indoteknik_custom/models/crm_lead.py
@@ -80,26 +80,19 @@ class CrmLead(models.Model):
input_tags.append(1510) #no tag
lead.tag_ids = input_tags
- if not lead.user_id or lead.user_id.id in [2, 25]:
+ if not lead.user_id or lead.user_id.id in [25]:
partner = lead.partner_id.parent_id or lead.partner_id
- if partner.user_id and partner.user_id.id not in [2, 25]:
+ if partner.user_id and partner.user_id.id not in [25]:
salesperson_id = partner.user_id.id
else:
- salesperson_id = 20
+ salesperson_id = 2
else:
partner = lead.partner_id.parent_id or lead.partner_id
- if partner.user_id and partner.user_id.id not in [2, 25]:
+ if partner.user_id and partner.user_id.id not in [25]:
salesperson_id = partner.user_id.id
else:
- salesperson_id = 20
+ salesperson_id = 2
lead.user_id = salesperson_id
- # def _create_testing_tags_leads(self):
- # angka_bulat_acak = random.randint(1, 1000)
- # self.env['crm.lead'].create([{
- # 'name': 'testing',
- # 'partner_id': 69
- # }])
-
diff --git a/indoteknik_custom/models/mail_mail.py b/indoteknik_custom/models/mail_mail.py
index 26f8bf5c..82b1fcca 100644
--- a/indoteknik_custom/models/mail_mail.py
+++ b/indoteknik_custom/models/mail_mail.py
@@ -7,6 +7,6 @@ class MailMail(models.Model):
def retry_send_mail(self):
mails = self.env['mail.mail'].search([
('state', 'in', ['exception', 'cancel']),
- ])
+ ], limit=250)
for mail in mails:
mail.state = 'outgoing'
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py
index 1f694380..aa63fe92 100644
--- a/indoteknik_custom/models/wati.py
+++ b/indoteknik_custom/models/wati.py
@@ -2,6 +2,7 @@ from odoo import fields, models, api
from datetime import datetime, timedelta
import logging
import json
+import requests
_logger = logging.getLogger(__name__)
@@ -17,7 +18,7 @@ class WatiNotification(models.Model):
text_time = fields.Datetime(string='Text Time')
text_type = fields.Char(string='Text Type')
json_raw = fields.Char(string='JSON Raw Text')
- is_parsed = fields.Boolean(string='Is Parsed')
+ is_parsed = fields.Boolean(string='Is Parsed', default=False)
is_lead = fields.Boolean(string='To Leads', help='apakah sudah ter-convert jadi leads')
def _cleanup(self):
@@ -33,7 +34,7 @@ class WatiNotification(models.Model):
def _parse_notification(self, limit = 0):
domain = [('is_parsed', '=', False)]
- notifications = self.search(domain, order='id desc', limit=limit)
+ notifications = self.search(domain, order='id', limit=limit)
notification_not_parsed_count = self.search_count(domain)
i = 0
for notification in notifications:
@@ -43,16 +44,106 @@ class WatiNotification(models.Model):
sender_name = 'Indoteknik'
if 'senderName' in notification_json:
sender_name = notification_json['senderName']
-
- notification.ticket_id = notification_json['ticketId']
- notification.mobile = notification_json['waId']
- notification.sender_name = sender_name
- notification.text = notification_json['text']
- notification.text_time = datetime.fromtimestamp(float(notification_json['timestamp']))
- notification.text_type = notification_json['type']
+
+ ticket_id = notification_json['ticketId']
+ date_wati = float(notification_json['timestamp'])
+ date_wati = datetime.fromtimestamp(date_wati)
+ wati_history = self.env['wati.history'].search([('ticket_id', '=', ticket_id)], limit=1)
+ if wati_history:
+ self._create_wati_history_line(wati_history, ticket_id, sender_name, notification_json, date_wati)
+ else:
+ new_header = self._create_wati_history_header(ticket_id, sender_name, notification_json, date_wati)
+ self._create_wati_history_line(new_header, ticket_id, sender_name, notification_json, date_wati)
notification.is_parsed = True
return
+ def _create_wati_history_header(self, ticket_id, sender_name, notification_json, date_wati):
+ param_header = {
+ 'ticket_id': ticket_id,
+ 'conversation_id': notification_json['conversationId'],
+ 'sender_name': sender_name,
+ 'wa_id': notification_json['waId'],
+ 'text': notification_json['text'],
+ 'date_wati': date_wati or '',
+ }
+ new_header = self.env['wati.history'].create([param_header])
+ return new_header
+
+ def _create_wati_history_line(self, new_header, ticket_id, sender_name, notification_json, date_wati):
+ text_body = notification_json['text'] or ''
+ param_line = {
+ "wati_history_id": new_header.id,
+ "conversation_id": notification_json['conversationId'],
+ "data": notification_json['data'] or '',
+ "event_type": notification_json['eventType'] or '',
+ # "list_reply": notification_json['listReply'] or '',
+ # "message_contact": notification_json['messageContact'] or '',
+ "operator_email": notification_json['operatorEmail'] or '',
+ "operator_name": notification_json['operatorName'] or '',
+ "sender_name": sender_name or '',
+ # "source_url": notification_json['sourceUrl'] or '',
+ "status_string": notification_json['statusString'] or '',
+ "text": text_body,
+ "ticket_id": ticket_id,
+ "type": notification_json['type'] or '',
+ "wa_id": notification_json['waId'] or '',
+ "date_wati": date_wati or '',
+ }
+ self.env['wati.history.line'].create([param_line])
+ self._update_header_after_create_line(new_header, sender_name, date_wati, text_body)
+ return
+
+ def _update_header_after_create_line(self, new_header, sender_name, date_wati, text_body):
+ new_header.last_reply_by = sender_name
+ new_header.last_reply_date = date_wati
+ new_header.last_reply_text = text_body
+ if sender_name == 'Indoteknik':
+ current_time = date_wati
+ delta_time = current_time + timedelta(days=1)
+ new_header.expired_date = delta_time
+ if not new_header.perusahaan or not new_header.email:
+ self._get_attribute_wati(new_header)
+ return
+
+ def _get_attribute_wati(self, new_header):
+ # url = 'https://live-server-2106.wati.io/api/v1/getContacts'
+
+ # cookies = {
+ # 'affinity': '1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008',
+ # }
+
+ # headers = {
+ # 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3MGM5ZmJhNy00MWRlLTRkMWEtYjY2NS1hM2Q5ODc2ZjhlZWIiLCJ1bmlxdWVfbmFtZSI6InR5YXNAaW5kb3Rla25pay5jb20iLCJuYW1laWQiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiZW1haWwiOiJ0eWFzQGluZG90ZWtuaWsuY29tIiwiYXV0aF90aW1lIjoiMTEvMjkvMjAyMyAwNDoxNzo0NyIsImRiX25hbWUiOiIyMTA2IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQURNSU5JU1RSQVRPUiIsImV4cCI6MjUzNDAyMzAwODAwLCJpc3MiOiJDbGFyZV9BSSIsImF1ZCI6IkNsYXJlX0FJIn0.--KHv4GCOG2MM3lNW9Nm-0-d8OAVpn5kbcSX4JKqATQ',
+ # # 'Cookie': 'affinity=1701232090.884.1520.321410|ff187ffce9bc0bae13542bb446e41008',
+ # }
+
+ # files = {
+ # 'pageSize': (None, '1'),
+ # 'pageNumber': (None, '1'),
+ # 'name': (None, ''),
+ # 'attribute': (None, '[{name: "phone", operator: "contain", value: "6285751430014"}]'),
+ # 'createdDate': (None, ''),
+ # }
+
+ # response = requests.get(url, cookies=cookies, headers=headers, files=files)
+ # print(response.json())
+ wati_api = self.env['wati.api']
+ params = {
+ 'pageSize':1,
+ 'pageNumber':1,
+ 'attribute':[{'name': "phone", 'operator': "contain", 'value': "6285751430014"}],
+ }
+ wati_contacts = wati_api.http_get('/api/v1/getContacts', params)
+ if wati_contacts['result'] != 'success':
+ return
+ # print (wati_contacts)
+ json_dump = json.dumps(wati_contacts, indent=4, sort_keys=True)
+ contact_list = json.loads(json_dump)['contact_list']
+ id = json.loads(contact_list)['id']
+ print(id)
+
+ return
+
def _convert_to_leads(self):
query = [
('is_lead', '=', False)
@@ -116,3 +207,56 @@ class WatiNotification(models.Model):
}])
wati.is_lead = True
wati.lead_id = current_lead.id
+
+
+class WatiHistory(models.Model):
+ _name = 'wati.history'
+ _order = 'id desc'
+
+ ticket_id = fields.Char(string='Ticket ID')
+ conversation_id = fields.Char(string='Conversation ID')
+ sender_name = fields.Char(string='Sender Name')
+ wa_id = fields.Char(string='WA ID')
+ text = fields.Char(string='Text')
+ date_wati = fields.Datetime(string='Date WATI')
+ wati_lines = fields.One2many('wati.history.line', 'wati_history_id', string='Lines', auto_join=True)
+ last_reply_by = fields.Char(string='Last Reply by')
+ last_reply_text = fields.Char(string='Last Reply Text')
+ last_reply_date = fields.Datetime(string='Last Reply Date')
+ expired_date = fields.Datetime(string='Expired Date')
+ email = fields.Char(string='Email')
+ perusahaan = fields.Char(string='Perusahaan')
+
+ # @api.onchange('last_reply_date')
+ # def _compute_expired_date(self):
+ # if self.last_reply_by == 'Indoteknik':
+ # return
+ # else:
+ # print(1)
+ # current_time = self.last_reply_date
+ # # current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S')
+ # delta_time = current_time + timedelta(days=1)
+ # # delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ # self.expired_date = delta_time
+ # return
+
+class WatiHistoryLine(models.Model):
+ _name = 'wati.history.line'
+
+ #sender
+ wati_history_id = fields.Many2one('ref', required=True, ondelete='cascade', index=True, copy=False)
+ conversation_id = fields.Char(string='Conversation ID')
+ data = fields.Char(string='data')
+ event_type = fields.Char(string='Event Type')
+ list_reply = fields.Char(string='List Reply')
+ message_contact = fields.Char(string='Message Contact')
+ operator_email = fields.Char(string='Operator Email')
+ operator_name = fields.Char(string='Operator Name')
+ sender_name = fields.Char(string='Sender Name')
+ source_url = fields.Char(string='Source URL')
+ status_string = fields.Char(string='Status String')
+ text = fields.Char(string='Text')
+ ticket_id = fields.Char(string='Ticket ID')
+ type = fields.Char(string='Type')
+ wa_id = fields.Char(string='WA ID')
+ date_wati = fields.Datetime(string='Date WATI')
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index ff467204..56d00b3e 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -81,4 +81,6 @@ access_quotation_so_multi_update,access.quotation.so.multi_update,model_quotatio
access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1
access_customer_commision,access.customer.commision,model_customer_commision,,1,1,1,1
access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1
-access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1 \ No newline at end of file
+access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1
+access_wati_history,access.wati.history,model_wati_history,,1,1,1,1
+access_wati_history_line,access.wati.history.line,model_wati_history_line,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/wati_history.xml b/indoteknik_custom/views/wati_history.xml
new file mode 100644
index 00000000..28698643
--- /dev/null
+++ b/indoteknik_custom/views/wati_history.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="wati_history_tree" model="ir.ui.view">
+ <field name="name">wati.history.tree</field>
+ <field name="model">wati.history</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="date_wati" readonly="1"/>
+ <field name="ticket_id" readonly="1"/>
+ <field name="conversation_id" readonly="1" optional="hide"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="wa_id" readonly="1"/>
+ <field name="text" readonly="1"/>
+ <field name="email" readonly="1" optional="hide"/>
+ <field name="perusahaan" readonly="1" optional="hide"/>
+ <field name="last_reply_by" readonly="1" optional="hide"/>
+ <field name="last_reply_date" readonly="1" optional="hide"/>
+ <field name="last_reply_text" readonly="1" optional="hide"/>
+ <field name="expired_date" readonly="1" optional="hide"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="wati_history_line_tree" model="ir.ui.view">
+ <field name="name">wati.history.line.tree</field>
+ <field name="model">wati.history.line</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="date_wati" readonly="1"/>
+ <field name="conversation_id" readonly="1" optional="hide"/>
+ <field name="data" readonly="1" optional="hide"/>
+ <field name="event_type" readonly="1" optional="hide"/>
+ <field name="list_reply" readonly="1" optional="hide"/>
+ <field name="message_contact" readonly="1" optional="hide"/>
+ <field name="operator_email" readonly="1"/>
+ <field name="operator_name" readonly="1"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="source_url" readonly="1" optional="hide"/>
+ <field name="status_string" readonly="1"/>
+ <field name="text" readonly="1"/>
+ <field name="ticket_id" readonly="1" optional="hide"/>
+ <field name="type" readonly="1" optional="hide"/>
+ <field name="wa_id" readonly="1" optional="hide"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="wati_history_form" model="ir.ui.view">
+ <field name="name">wati.history.form</field>
+ <field name="model">wati.history</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet string="Wati">
+ <div class="oe_button_box" name="button_box"/>
+ <group>
+ <group>
+ <field name="date_wati" readonly="1"/>
+ <field name="ticket_id" readonly="1"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="text" readonly="1"/>
+ <field name="wa_id" readonly="1"/>
+
+ </group>
+ <group>
+ <field name="conversation_id" readonly="1"/>
+ <field name="last_reply_by" readonly="1"/>
+ <field name="last_reply_date" readonly="1"/>
+ <field name="expired_date" readonly="1"/>
+ <field name="last_reply_text" readonly="1"/>
+ </group>
+ </group>
+ <notebook>
+ <page string="Lines">
+ <field name="wati_lines"/>
+ </page>
+ <page string="Others">
+ <group>
+ <field name="email"/>
+ <field name="perusahaan"/>
+ </group>
+ </page>
+ </notebook>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="view_wati_history_filter" model="ir.ui.view">
+ <field name="name">wati.history.list.select</field>
+ <field name="model">wati.history</field>
+ <field name="priority" eval="15"/>
+ <field name="arch" type="xml">
+ <search string="Search Wati">
+ <field name="sender_name"/>
+ <field name="wa_id"/>
+ <field name="text"/>
+ </search>
+ </field>
+ </record>
+
+ <record id="wati_history_action" model="ir.actions.act_window">
+ <field name="name">Wati History</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">wati.history</field>
+ <field name="search_view_id" ref="view_wati_history_filter"/>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem id="menu_wati_history"
+ name="Wati History"
+ action="wati_history_action"
+ parent="sale.product_menu_catalog"
+ sequence="103"
+ />
+
+</odoo> \ No newline at end of file