Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] okr: Migration to 17.0 #167

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions okr_module/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions okr_module/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
'name': 'OKR Module',
'version': "17.0.1.0.0",
'category': 'Base',
'sequence': 14,
'summary': '',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'images': [
],
'depends': ['contacts'
],
'data': ['security/ir.model.access.csv',
'views/okr_base.xml',
'views/menu.xml',
],
'demo': [
],
'installable': True,
'auto_install': False,
'application': True,
}
1 change: 1 addition & 0 deletions okr_module/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import okr_base
50 changes: 50 additions & 0 deletions okr_module/models/okr_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from odoo import api, models, fields

class OkrBase(models.Model):
_description = 'OKR BASE'
_name = "okr.base"

name = fields.Char(required=True)
description = fields.Char()
user_id = fields.Many2one('res.users')
completed_percentage = fields.Float(compute='_compute_completed_percentage')
type = fields.Selection(selection=[('commitment', 'commitment'),('inspirational', 'inspirational')], required=True)
kr_line_ids = fields.One2many('okr.base.line', 'okr_base_id')

def _compute_completed_percentage(self):
for kr in self:
if kr.kr_line_ids:
w_cum = 0
sum_weigh = 0
for krl in kr.kr_line_ids:
w_cum += krl.completed_percentage*krl.weight
sum_weigh += krl.weight
if sum_weigh>0:
kr.completed_percentage = w_cum/sum_weigh
else:
kr.completed_percentage = 0
else:
kr.completed_percentage = 0



class OkrBaseLine(models.Model):
_description = 'OKR LINE'
_name = "okr.base.line"

name = fields.Char()
description = fields.Char()
user_id = fields.Many2one('res.users')
okr_base_id = fields.Many2one(comodel_name='okr.base', required=True)
actual_value = fields.Float()
weight = fields.Float()
target = fields.Float()
completed_percentage = fields.Float(compute='_compute_completed_percentage_line')

def _compute_completed_percentage_line(self):
for kr in self:
kr.completed_percentage = 0
if kr.actual_value>0 and kr.actual_value<kr.target:
kr.completed_percentage = (kr.actual_value/kr.target)
else:
kr.completed_percentage = 1
3 changes: 3 additions & 0 deletions okr_module/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
okr_module.access_okr_base,access_okr_base,okr_module.model_okr_base,base.group_user,1,1,1,1
okr_module.access_okr_base_line,access_okr_base_line,okr_module.model_okr_base_line,base.group_user,1,1,1,1
19 changes: 19 additions & 0 deletions okr_module/views/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<odoo>
<menuitem
id="okr_menu"
name="OKR"
sequence="80"/>

<menuitem
id="okr_main"
name="OKR"
action="okr_menu_action"
parent="okr_menu"
sequence="10"/>
<menuitem
id="okr_line"
name="OKR lines"
action="okr_line_menu_action"
parent="okr_menu"
sequence="20"/>
</odoo>
100 changes: 100 additions & 0 deletions okr_module/views/okr_base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<odoo>

<record id="tree_okr_base" model="ir.ui.view">
<field name="name">Tree OKR</field>
<field name="model">okr.base</field>
<field name="arch" type="xml">
<tree create="1">
<field name="name"/>
<field name="user_id" string="User in charge"/>
<field name="completed_percentage"/>
</tree>
</field>
</record>

<record id="tree_okr_base_line" model="ir.ui.view">
<field name="name">Tree OKR Line</field>
<field name="model">okr.base.line</field>
<field name="arch" type="xml">
<tree create="1">
<field name="name"/>
<field name="okr_base_id" string="Main OKR"/>
<field name="user_id" string="User in charge"/>
<field name="completed_percentage"/>
</tree>
</field>
</record>

<record id="form_okr_base" model="ir.ui.view">
<field name="name">Form OKR</field>
<field name="model">okr.base</field>
<field name="arch" type="xml">
<form create="1">
<group>
<group>
<field name="name"/>
<field name="type"/>
<field name="user_id"/>
<field name="completed_percentage"/>
</group>
</group>
<field name="kr_line_ids">
<tree create="1">
<field name="name"/>
<field name="actual_value"/>
<field name="target"/>
<field name="completed_percentage"/>
<field name="weight"/>
<field name="user_id"/>
</tree>
</field>
</form>
</field>
</record>

<record id="okr_base_search" model="ir.ui.view">
<field name="name">okr.base.search_view</field>
<field name="model">okr.base</field>
<field name="arch" type="xml">
<search>
<group expand="0" string="Group By">
<filter string="User in Charge" name="user_id" domain="[]" context="{'group_by':'user_id'}"/>
</group>
</search>
</field>
</record>

<record id="okr_base_line_search" model="ir.ui.view">
<field name="name">okr.base.line.search_view</field>
<field name="model">okr.base.line</field>
<field name="arch" type="xml">
<search>
<filter name="user_id"/>
<group expand="0" string="Group By">
<filter string="Main OKR" name="okr_base_id" domain="[]" context="{'group_by':'okr_base_id'}"/>
<filter string="User in Charge" name="user_id" domain="[]" context="{'group_by':'user_id'}"/>
</group>
</search>
</field>
</record>

<record id="okr_menu_action" model="ir.actions.act_window">
<field name="name">Menu OKR</field>
<field name="res_model">okr.base</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Segui tus OKR</p>
</field>
</record>
<record id="okr_line_menu_action" model="ir.actions.act_window">
<field name="name">OKR lines</field>
<field name="res_model">okr.base.line</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Segui tus OKR</p>
</field>
</record>

</odoo>