diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-13 10:41:41 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-13 10:41:41 +0700 |
| commit | cfa0aa5c242b14332f7bc970bb65f1fbde0a9f3b (patch) | |
| tree | 91f855964cadb0c76094cd2cc6b51f7994ce0c6d /indoteknik_custom | |
| parent | fb04f8f3c533740c79c130ab4bc097b8529cae8e (diff) | |
| parent | 7478616937cff56ccb994138831f90eae904e724 (diff) | |
fix conflict
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 13 | ||||
| -rwxr-xr-x | indoteknik_custom/models/user_activity_log.py | 68 | ||||
| -rw-r--r-- | indoteknik_custom/views/dunning_run.xml | 13 | ||||
| -rwxr-xr-x | indoteknik_custom/views/user_activity_log.xml | 21 |
4 files changed, 112 insertions, 3 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 1e0c56cf..54e51dcf 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -1,4 +1,5 @@ from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError from datetime import timedelta @@ -12,6 +13,18 @@ class AccountMove(models.Model): date_terima_tukar_faktur = fields.Date(string='Terima Faktur') shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') + def button_draft(self): + res = super(AccountMove, self).button_draft() + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa Reset to Draft') + return res + + def action_post(self): + res = super(AccountMove, self).action_post() + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa Posting') + return res + @api.onchange('date_kirim_tukar_faktur') def change_date_kirim_tukar_faktur(self): for invoice in self: diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 32b389a1..9d9694af 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=100, 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/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index c251b206..6343a79b 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -82,10 +82,23 @@ </field> </record> + <record id="view_dunning_run_filter" model="ir.ui.view"> + <field name="name">dunning.run.list.select</field> + <field name="model">dunning.run</field> + <field name="priority" eval="15"/> + <field name="arch" type="xml"> + <search string="Search Dunning Run"> + <field name="number"/> + <field name="partner_id"/> + </search> + </field> + </record> + <record id="dunning_run_action" model="ir.actions.act_window"> <field name="name">Dunning Run</field> <field name="type">ir.actions.act_window</field> <field name="res_model">dunning.run</field> + <field name="search_view_id" ref="view_dunning_run_filter"/> <field name="view_mode">tree,form</field> </record> diff --git a/indoteknik_custom/views/user_activity_log.xml b/indoteknik_custom/views/user_activity_log.xml index db242505..b8792ee8 100755 --- a/indoteknik_custom/views/user_activity_log.xml +++ b/indoteknik_custom/views/user_activity_log.xml @@ -4,9 +4,10 @@ <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="url" widget="url"/> <field name="res_user_id"/> <field name="email"/> @@ -18,7 +19,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 +28,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> |
