diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-02-10 10:36:16 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-02-10 10:36:16 +0700 |
| commit | bbf176b0ce51ade22b74d0df2023025a4cef3efa (patch) | |
| tree | 24d2d3c7e3fed5c0672a9063a09e3c4d33ba3dac /indoteknik_custom | |
| parent | bd01d7a842c8b6e4aea6a2fc3615a9d57fbcd470 (diff) | |
| parent | b0de64ae769148a009d0a08a957c5c35dee174a9 (diff) | |
Merge branch 'release' into line_no_sales_order
Diffstat (limited to 'indoteknik_custom')
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/dunning_run.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/midtrans.py | 38 | ||||
| -rwxr-xr-x | indoteknik_custom/models/user_activity_log.py | 68 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 5 | ||||
| -rw-r--r-- | indoteknik_custom/views/dunning_run.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/user_activity_log.xml | 22 |
8 files changed, 136 insertions, 6 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index c6fb7d4f..121bd0f4 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -46,3 +46,4 @@ from . import x_partner_purchase_order from . import x_product_tags from . import website_ads from . import leads_monitoring +from . import midtrans diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 54e51dcf..78fa2ddf 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -21,8 +21,8 @@ class AccountMove(models.Model): def action_post(self): res = super(AccountMove, self).action_post() - if not self.env.user.is_accounting: - raise UserError('Hanya Accounting yang bisa Posting') + # if not self.env.user.is_accounting: + # raise UserError('Hanya Accounting yang bisa Posting') return res @api.onchange('date_kirim_tukar_faktur') diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index ee0669ca..98689550 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -23,6 +23,7 @@ class DunningRun(models.Model): 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') + notification = fields.Char(string='Notification') def copy_date_faktur(self): if not self.is_validated: @@ -51,12 +52,14 @@ class DunningRun(models.Model): invoice.invoice_date_due = due_date if not invoice.shipper_faktur_id: invoice.shipper_faktur_id = self.shipper_faktur_id + self.notification = 'Berhasil copy tanggal terima faktur ke setiap invoice %s' % self.date_terima_tukar_faktur def validate_dunning(self): if not self.dunning_line: raise UserError('Dunning Line masih kosong, generate dulu') else: self.is_validated = True + self.notification = 'Jangan lupa klik Copy Date jika sudah ada tanggal kirim / tanggal terima faktur' def generate_dunning_line(self): if self.is_validated: diff --git a/indoteknik_custom/models/midtrans.py b/indoteknik_custom/models/midtrans.py new file mode 100644 index 00000000..76dee447 --- /dev/null +++ b/indoteknik_custom/models/midtrans.py @@ -0,0 +1,38 @@ +from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) + + +class MidtransNotification(models.Model): + _name = 'midtrans.notification' + + json_raw = fields.Char(string='JSON Raw Text') + sale_order_id = fields.Many2one('sale.order', string='Sales Order') + payment_status = fields.Selection([ + ('pending', 'Pending'), + ('capture', 'Capture'), + ('settlement', 'Settlement'), + ('deny', 'Deny'), + ('cancel', 'Cancel'), + ('expire', 'Expire'), + ('failure', 'Failure'), + ('refund', 'Refund'), + ('chargeback', 'Chargeback'), + ('partial_refund', 'Partial Refund'), + ('partial_chargeback', 'Partial Chargeback'), + ('authorize', 'Authorize'), + ], string='Payment Status', + help='Payment Gateway Status / Midtrans / Web, https://docs.midtrans.com/en/after-payment/status-cycle') + + +class MidtransRecurring(models.Model): + _name = 'midtrans.recurring' + + json_raw = fields.Char(string='JSON Raw Text') + + +class MidtransAccount(models.Model): + _name = 'midtrans.account' + + json_raw = fields.Char(string='JSON Raw Text') diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 32b389a1..ef801ca5 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -1,6 +1,9 @@ -from odoo import models, fields +from odoo import models, fields, api +from odoo.http import request from datetime import datetime, timedelta import logging, re +import requests +import json _logger = logging.getLogger(__name__) @@ -11,11 +14,74 @@ class UserActivityLog(models.Model): page_title = fields.Char(string="Judul Halaman") url = fields.Char(string="URL") + ip_address = fields.Char('IP Address') + ip_address_lookup = fields.Text('IP Address Lookup') + ip_location_city = fields.Text('IP Location City') + ip_location_country = fields.Text('IP Location Country') + ip_location_country_code = fields.Text('IP Location Country Code') + ip_location_map = fields.Html('Embedded Map', compute='_compute_ip_location_map', sanitize=False) 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 _parse_json(self, json_string, key): + result = '' + if json_string: + json_object = json.loads(json_string) + if key in json_object: + result = json_object[key] + return result + + def _compute_ip_location_map(self): + self.ip_location_map = "" + ip_location_lat = self._parse_json(self.ip_address_lookup, 'lat') + ip_location_lon = self._parse_json(self.ip_address_lookup, 'lon') + url = 'https://maps.google.com/maps?q=%s,%s&hl=id&z=15&output=embed' % (ip_location_lat, ip_location_lon) + if ip_location_lat and ip_location_lon: + self.ip_location_map = "<iframe width='100%' height='500' frameborder='1' scrolling='no' src='"+ url +"'></iframe>" + + def _parse_ip_location(self): + domain = [ + ('ip_address_lookup', '!=', False), + ('ip_location_city', '=', False), + ('ip_location_country', '=', False), + ('ip_location_country_code', '=', False), + ] + logs = self.search(domain, limit=200, order='create_date asc') + for log in logs: + log.ip_location_city = self._parse_json(log.ip_address_lookup, 'city') + log.ip_location_country = self._parse_json(log.ip_address_lookup, 'country') + log.ip_location_country_code = self._parse_json(log.ip_address_lookup, 'countryCode') + + def _load_ip_address_lookup(self): + domain = [ + ('ip_address', '!=', False), + ('ip_address_lookup', '=', False), + ] + logs = self.search(domain, limit=45, order='create_date asc') + for log in logs: + try: + ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json() + del ipinfo['status'] + log.ip_address_lookup = json.dumps(ipinfo, indent=4, sort_keys=True) + except: + log.ip_address_lookup = '' + self._parse_ip_location() + + def record_activity(self): + try: + httprequest = request.httprequest + if httprequest.remote_addr != '127.0.0.1': + self.env['user.activity.log'].sudo().create([{ + 'page_title': request.env['ir.config_parameter'].get_param('web.base.url'), + 'url': httprequest.base_url, + 'ip_address': httprequest.remote_addr + }]) + return True + except: + return False + def compile_product(self): logs = self.env['user.activity.log'].search([ ('email', '!=', False), diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d469aa1e..83d9e2ed 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -27,4 +27,7 @@ access_website_content,access.website.content,model_website_content,,1,1,1,1 access_invoice_reklas,access.invoice.reklas,model_invoice_reklas,,1,1,1,1 access_custom_mail_marketing,access.custom.mail.marketing,model_custom_mail_marketing,,1,1,1,1 access_website_ads,access.website.ads,model_website_ads,,1,1,1,1 -access_leads_monitoring,access.leads.monitoring,model_leads_monitoring,,1,1,1,1
\ No newline at end of file +access_leads_monitoring,access.leads.monitoring,model_leads_monitoring,,1,1,1,1 +access_midtrans_notification,access.midtrans.notification,model_midtrans_notification,,1,1,1,1 +access_midtrans_recurring,access.midtrans.recurring,model_midtrans_recurring,,1,1,1,1 +access_midtrans_account,access.midtrans.account,model_midtrans_account,,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 6343a79b..cae9cc32 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -63,6 +63,7 @@ <field name="number"/> <field name="partner_id"/> <field name="dunning_date"/> + <field name="notification" readonly="1"/> </group> <group> <field name="is_validated" readonly="1"/> diff --git a/indoteknik_custom/views/user_activity_log.xml b/indoteknik_custom/views/user_activity_log.xml index db242505..91c14b4d 100755 --- a/indoteknik_custom/views/user_activity_log.xml +++ b/indoteknik_custom/views/user_activity_log.xml @@ -4,9 +4,11 @@ <field name="name">user.activity.log.tree</field> <field name="model">user.activity.log</field> <field name="arch" type="xml"> - <tree default_order="create_date desc"> + <tree default_order="create_date desc" create="0" export_xlsx="0"> <field name="create_date"/> <field name="page_title"/> + <field name="ip_address"/> + <field name="ip_location_country"/> <field name="url" widget="url"/> <field name="res_user_id"/> <field name="email"/> @@ -18,7 +20,7 @@ <field name="name">user.activity.log.form</field> <field name="model">user.activity.log</field> <field name="arch" type="xml"> - <form> + <form create="0" edit="0"> <sheet> <group> <group> @@ -27,8 +29,24 @@ <field name="url" widget="url"/> <field name="res_user_id"/> <field name="email"/> + <field name="ip_address"/> </group> </group> + <notebook> + <page string="IP Lookup Detail"> + <group> + <field name="ip_location_city"/> + <field name="ip_location_country"/> + <field name="ip_location_country_code"/> + </group> + </page> + <page string="IP Address Lookup"> + <field name="ip_address_lookup"/> + </page> + <page string="IP Address Location"> + <field name="ip_location_map" widget="html" /> + </page> + </notebook> </sheet> </form> </field> |
