summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-22 15:52:47 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-22 15:52:47 +0700
commit73f5869798fc5ec69d84306139de55acaca06489 (patch)
treea3436043447db0619bba3fa854b95474f9a3f463 /indoteknik_custom/models
parent2a5d4886d2924ef9dae451c841dc3bae9478f9ab (diff)
parentb9eddb17ac8eeed2b8af734844bb1149ec4184eb (diff)
Merge branch 'staging' of bitbucket.org:altafixco/indoteknik-addons into staging
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rwxr-xr-xindoteknik_custom/models/crm_lead.py4
-rw-r--r--indoteknik_custom/models/midtrans.py25
-rwxr-xr-xindoteknik_custom/models/sale_order.py9
-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, 136 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/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/midtrans.py b/indoteknik_custom/models/midtrans.py
index 76dee447..c99c8410 100644
--- a/indoteknik_custom/models/midtrans.py
+++ b/indoteknik_custom/models/midtrans.py
@@ -1,5 +1,6 @@
from odoo import fields, models, api
import logging
+import json
_logger = logging.getLogger(__name__)
@@ -25,6 +26,30 @@ class MidtransNotification(models.Model):
], string='Payment Status',
help='Payment Gateway Status / Midtrans / Web, https://docs.midtrans.com/en/after-payment/status-cycle')
+ def _parse_notification(self):
+ query = [
+ ('payment_status', '=', False)
+ ]
+ notifications = self.env['midtrans.notification'].search(query, order='id')
+ for notif in notifications:
+ payment_status = json.loads(notif.json_raw)['transaction_status']
+ payment_type = json.loads(notif.json_raw)['payment_type']
+ gross_amount = json.loads(notif.json_raw)['gross_amount']
+ order_id = json.loads(notif.json_raw)['order_id']
+
+ orders = order_id.split('_')
+ order = orders[0].replace('-', '/')
+ sale_order = self.env['sale.order'].search([('name', '=', order)], limit=1)
+
+ notif.payment_status = payment_status
+ notif.sale_order_id = sale_order.id
+
+ sale_order.payment_type = payment_type
+ sale_order.gross_amount = gross_amount
+ sale_order.payment_status = payment_status
+
+ _logger.info('Success Parsing Midtrans Notification %s' % notif.id)
+
class MidtransRecurring(models.Model):
_name = 'midtrans.recurring'
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index f21554f7..35f1af8e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -66,6 +66,9 @@ 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")
+ payment_type = fields.Char(string='Payment Type', help='Jenis pembayaran dengan Midtrans')
+ gross_amount = fields.Float(string='Gross Amount', help='Jumlah pembayaran yang dilakukan dengan Midtrans')
def calculate_line_no(self):
line_no = 0
@@ -103,10 +106,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
@@ -214,6 +216,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([