104 lines
3.9 KiB
Python
104 lines
3.9 KiB
Python
import json
|
|
from odoo import models, fields, api, _
|
|
import copy
|
|
import re
|
|
from odoo.exceptions import ValidationError, UserError
|
|
|
|
class KsDashboardNinjaItems(models.Model):
|
|
_inherit = 'ks_dashboard_ninja.item'
|
|
|
|
ks_to_do_preview = fields.Char("To Do Preview", default="To Do Preview")
|
|
ks_dn_header_lines = fields.One2many('ks_to.do.headers', 'ks_dn_item_id')
|
|
ks_to_do_data = fields.Char(string="To Do Data in JSon", compute='ks_get_to_do_view_data', compute_sudo=False)
|
|
ks_header_bg_color = fields.Char(string="Header Background Color", default="#8e24aa,0.99",
|
|
help=' Select the background color with transparency. ')
|
|
|
|
@api.depends('ks_dn_header_lines', 'ks_dashboard_item_type')
|
|
def ks_get_to_do_view_data(self):
|
|
for rec in self:
|
|
ks_to_do_data = rec._ksGetToDOData()
|
|
rec.ks_to_do_data = ks_to_do_data
|
|
|
|
def getToDoData(self):
|
|
return self._ksGetToDOData()
|
|
|
|
def _ksGetToDOData(self):
|
|
""" @return
|
|
ks_to_do_data = {
|
|
"items":[
|
|
{"item_id": item_id1, "label": label1, "lines": [{"id": id1, "content": content1, "active": active},{"id": id2, "content": content1, "active": active}] ,
|
|
{"item_id": item_id2,"label": label2,"lines": [{"id": id3, "content": content2, "active": active},...],
|
|
]
|
|
}
|
|
|
|
"""
|
|
|
|
if not self.ks_dn_header_lines:
|
|
return False
|
|
ks_to_do_data = {
|
|
'items': [],
|
|
}
|
|
items = []
|
|
for record in self.ks_dn_header_lines:
|
|
lines = []
|
|
for line in record.ks_to_do_description_lines:
|
|
if isinstance(line.id, int):
|
|
line_id = line.id
|
|
else:
|
|
try:
|
|
line_id = line.ids[0]
|
|
except IndexError:
|
|
line_id = 0
|
|
lines.append({
|
|
"id": line_id,
|
|
"ks_description": line.ks_description,
|
|
"ks_active": line.ks_active
|
|
})
|
|
if isinstance(record.id, int):
|
|
record_id = record.id
|
|
else:
|
|
try:
|
|
record_id = record.ids[0]
|
|
except IndexError:
|
|
record_id = 0
|
|
items.append({
|
|
"item_id": record_id,
|
|
"label": record.ks_to_do_header,
|
|
"lines": lines
|
|
})
|
|
ks_to_do_data['items'] = items
|
|
return json.dumps(ks_to_do_data)
|
|
|
|
|
|
class KsToDoheaders(models.Model):
|
|
_name = 'ks_to.do.headers'
|
|
_description = "to do headers"
|
|
|
|
ks_dn_item_id = fields.Many2one('ks_dashboard_ninja.item')
|
|
ks_to_do_header = fields.Char('Header')
|
|
ks_to_do_description_lines = fields.One2many('ks_to.do.description', 'ks_to_do_header_id')
|
|
|
|
@api.constrains('ks_to_do_header')
|
|
def ks_to_do_header_check(self):
|
|
for rec in self:
|
|
if rec.ks_to_do_header:
|
|
ks_check = bool(re.match('^[A-Z, a-z,0-9,_]+$', rec.ks_to_do_header))
|
|
if not ks_check:
|
|
raise ValidationError(_("Special characters are not allowed only string and digits allow for section header"))
|
|
|
|
@api.onchange('ks_to_do_header')
|
|
def ks_to_do_header_onchange(self):
|
|
for rec in self:
|
|
if rec.ks_to_do_header:
|
|
ks_check = bool(re.match('^[A-Z, a-z,0-9,_]+$', rec.ks_to_do_header))
|
|
if not ks_check:
|
|
raise ValidationError(_("Special characters are not allowed only string and digits allow for section header"))
|
|
|
|
class KsToDODescription(models.Model):
|
|
_name = 'ks_to.do.description'
|
|
_description = 'to do description'
|
|
|
|
ks_to_do_header_id = fields.Many2one('ks_to.do.headers')
|
|
ks_description = fields.Text('Description')
|
|
ks_active = fields.Boolean('Active Description', default=True)
|