Skip to content

Commit

Permalink
[8.0]-IMP-Stages as clickable in BR (#227)
Browse files Browse the repository at this point in the history
* [IMP]Added Stages as clickble removed buttons

* [IMP]Improved code

* [IMP]Improved code

* [IMP]Improved code

* [Added docstring in readgroup method]
  • Loading branch information
YogeshMahera-SerpentCS authored and elicoidal committed Aug 4, 2017
1 parent 1d6d7ca commit d312426
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 195 deletions.
110 changes: 72 additions & 38 deletions business_requirement/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from openerp import api, fields, models, _
from openerp.exceptions import except_orm
from openerp.exceptions import Warning as UserError


class BusinessRequirement(models.Model):
Expand Down Expand Up @@ -300,44 +301,6 @@ def name_search(self, name, args=None, operator='ilike', limit=100):
# Merge both results
return list(set(names) | set(descriptions))[:limit]

@api.multi
def action_button_confirm(self):
self.write({'state': 'confirmed'})
self.confirmed_id = self.env.user
self.confirmation_date = fields.Datetime.now()

@api.multi
def action_button_back_draft(self):
self.write({'state': 'draft'})
self.confirmed_id = self.approved_id = []
self.confirmation_date = self.approval_date = ''

@api.multi
def action_button_approve(self):
self.write({'state': 'approved'})
self.approved_id = self.env.user
self.approval_date = fields.Datetime.now()

@api.multi
def action_button_stakeholder_approval(self):
self.write({'state': 'stakeholder_approval'})

@api.multi
def action_button_in_progress(self):
self.write({'state': 'in_progress'})

@api.multi
def action_button_done(self):
self.write({'state': 'done'})

@api.multi
def action_button_cancel(self):
self.write({'state': 'cancel'})

@api.multi
def action_button_drop(self):
self.write({'state': 'drop'})

@api.cr_uid_ids_context
def message_post(self, cr, uid, thread_id, body='', subject=None,
type='notification', subtype=None, parent_id=False,
Expand All @@ -359,6 +322,77 @@ def message_post(self, cr, uid, thread_id, body='', subject=None,
)
return res

@api.model
def read_group(self, domain, fields, groupby, offset=0,
limit=None, orderby=False, lazy=True):
""" Read group customization in order to display all the stages in the
kanban view. if the stages values are there it will group by state.
"""
if groupby and groupby[0] == "state":
states = self.env['business.requirement'].\
fields_get(['state']).get('state').get('selection')
read_group_all_states = [{'__context': {'group_by': groupby[1:]},
'__domain': domain + [('state', '=',
state_value)],
'state': state_value,
'state_count': 0}
for state_value, state_name in states]
# Get standard results
read_group_res = super(BusinessRequirement, self).\
read_group(domain, fields, groupby, offset=offset,
limit=limit, orderby=orderby)
# Update standard results with default results
result = []
for state_value, state_name in states:
res = filter(lambda x: x['state'] == state_value,
read_group_res)
if not res:
res = filter(lambda x: x['state'] == state_value,
read_group_all_states)
res[0]['state'] = [state_value, state_name]
result.append(res[0])
return result
else:
return super(BusinessRequirement, self).\
read_group(domain, fields, groupby,
offset=offset, limit=limit, orderby=orderby)

@api.multi
def write(self, vals):
for r in self:
if vals.get('state'):
ir_obj = self.env['ir.model.data']
br_xml_id = ir_obj.\
get_object('business_requirement',
'group_business_requirement_manager')
user = self.env['res.users']
grps = [grp.id for grp in user.browse(self._uid).groups_id]
date = fields.Datetime.now()
if vals['state'] == 'confirmed':
vals.update({'confirmed_id': user,
'confirmation_date': date})
if vals['state'] == 'draft':
vals.update({'confirmed_id': False,
'approved_id': False,
'confirmation_date': False,
'approval_date': False
})
if vals['state'] == 'approved':
if br_xml_id.id in grps:
vals.update({'approved_id': user,
'approval_date': date})
else:
raise UserError(_('You can only move to the '
'following stage: draft/confirmed'
'/cancel/drop.'))
if vals['state'] in ('stakeholder_approval', 'in_progress',
'done'):
if br_xml_id.id not in grps:
raise UserError(_('You can only move to the'
'following stage: draft/'
'confirmed/cancel/drop.'))
return super(BusinessRequirement, self).write(vals)


class BusinessRequirementCategory(models.Model):
_name = "business.requirement.category"
Expand Down
127 changes: 87 additions & 40 deletions business_requirement/tests/test_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,59 @@
class BusinessRequirementTestCase(common.TransactionCase):
def setUp(self):
super(BusinessRequirementTestCase, self).setUp()
self.ProjectObj = self.env['project.project']

self.AnalyticAccountObject = self.env['account.analytic.account']
# Configure unit of measure.
self.categ_wtime = self.ref('product.uom_categ_wtime')
self.categ_kgm = self.ref('product.product_uom_categ_kgm')

self.UomObj = self.env['product.uom']
self.uom_hours = self.UomObj.create({
'name': 'Test-Hours',
'category_id': self.categ_wtime,
'factor': 8,
'uom_type': 'smaller'})
self.uom_days = self.UomObj.create({
'name': 'Test-Days',
'category_id': self.categ_wtime,
'factor': 1})
self.uom_kg = self.UomObj.create({
'name': 'Test-KG',
'category_id': self.categ_kgm,
'factor_inv': 1,
'factor': 1,
'uom_type': 'reference',
'rounding': 0.000001})

self.AnalyticAccount = self.AnalyticAccountObject.create(
{'name': 'AnalyticAccount for Test',
'state': 'draft'})

self.projectA = self.ProjectObj. \
create({'name': 'Test Project A', 'partner_id': 1, 'parent_id': 1,
'analytic_account_id': self.AnalyticAccount.id})
self.br = self.env['business.requirement']

vals = {
'description': 'test',
'project_id': self.projectA.id
}
# Product Created A, B, C, D
self.ProductObj = self.env['product.product']
self.productA = self.ProductObj.create(
{'name': 'Product A', 'uom_id': self.uom_hours.id,
'uom_po_id': self.uom_hours.id,
'standard_price': 450})
self.productB = self.ProductObj. \
create({'name': 'Product B', 'uom_id': self.uom_hours.id,
'uom_po_id': self.uom_hours.id,
'standard_price': 550})

self.brA = self.env['business.requirement'].create(vals)
self.brB = self.env['business.requirement'].create(vals)
self.brC = self.env['business.requirement'].create(vals)

def test_get_level(self):
br_vals1 = {
'name': ' test',
Expand Down Expand Up @@ -43,46 +94,6 @@ def test_get_level(self):
level3 = br3.level
self.assertEqual(level3, 3)

def test_action_button_confirm(self):
br_vals = {
'name': ' test',
'description': 'test',
'parent_id': False,
}
br = self.br.create(br_vals)
br.action_button_confirm()
self.assertEqual(br.state, 'confirmed')

def test_action_button_back_draft(self):
br_vals = {
'name': 'test',
'description': 'test',
'parent_id': False,
}
br = self.br.create(br_vals)
br.action_button_back_draft()
self.assertEqual(br.state, 'draft')

def test_action_button_approve(self):
br_vals = {
'name': ' test',
'description': 'test',
'parent_id': False,
}
br = self.br.create(br_vals)
br.action_button_approve()
self.assertEqual(br.state, 'approved')

def test_action_button_done(self):
br_vals = {
'name': ' test',
'description': 'test',
'parent_id': False,
}
br = self.br.create(br_vals)
br.action_button_done()
self.assertEqual(br.state, 'done')

def test_br_name_search(self):
br_vals = {
'name': ' test',
Expand All @@ -92,3 +103,39 @@ def test_br_name_search(self):
self.br.create(br_vals)
brs = self.br.name_search(name='test')
self.assertEqual(bool(brs), True)

def test_br_read_group(self):
self.env['business.requirement'].read_group(
[],
['state'], ['state'])[0]
self.env['business.requirement'].read_group(
[],
[], [])[0]

def test_br_state_generate_project_wizard(self):
# test when state=draft
self.brA.state = 'draft'
self.brB.state = 'draft'
self.brC.state = 'draft'

# test when state=confirmed
self.brA.state = 'confirmed'
self.brB.state = 'confirmed'
self.brC.state = 'confirmed'

self.brB.state = 'confirmed'
self.brC.state = 'draft'

# test when state=stakeholder_approval
self.brA.state = 'stakeholder_approval'
self.brB.state = 'approved'
self.brC.state = 'approved'

# test when state=done
self.brA.state = 'done'
self.brB.state = 'approved'
self.brC.state = 'approved'

# test when state=cancel
self.brB.state = 'approved'
self.brC.state = 'approved'
10 changes: 1 addition & 9 deletions business_requirement/views/business_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@
<field name="arch" type="xml">
<form string="Business Requirement">
<header>
<button name="action_button_confirm" states="draft" string="Confirm" type="object" groups="business_requirement.group_business_requirement_user" class="oe_highlight"/>
<button name="action_button_back_draft" string="Back To Draft" type="object" attrs="{'invisible': [('state', 'in', ('draft','done'))]}" groups="business_requirement.group_business_requirement_user" class="oe_highlight"/>
<button name="action_button_approve" states="confirmed" string="Approve" type="object" groups="business_requirement.group_business_requirement_manager" class="oe_highlight"/>
<button name="action_button_stakeholder_approval" states="approved" string="Stakeholder Approval" type="object" groups="business_requirement.group_business_requirement_manager" class="oe_highlight"/>
<button name="action_button_in_progress" states="stakeholder_approval" string="In Progress" type="object" groups="business_requirement.group_business_requirement_manager" class="oe_highlight"/>
<button name="action_button_done" states="in_progress" string="Done" type="object" groups="business_requirement.group_business_requirement_manager" class="oe_highlight"/>
<button name="action_button_cancel" string="Cancel" type="object" attrs="{'invisible': [('state', 'in', ('done','cancel'))]}" groups="business_requirement.group_business_requirement_user" class="oe_highlight"/>
<button name="action_button_drop" string="Drop" type="object" attrs="{'invisible': [('state', 'in', ('done','drop','cancel'))]}" groups="business_requirement.group_business_requirement_user" class="oe_highlight"/>
<field name="state" widget="statusbar"
<field name="state" widget="statusbar" clickable="True"
statusbar_visible="draft,confirmed,approved,stakeholder_approval,in_progress,done,cancel,drop"/>
</header>
<sheet>
Expand Down
71 changes: 1 addition & 70 deletions business_requirement_deliverable_project/models/business.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# © 2016 Elico Corp (https://www.elico-corp.com).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models, _
from openerp.exceptions import Warning as UserError
from openerp import api, fields, models


class BusinessRequirement(models.Model):
Expand Down Expand Up @@ -83,74 +82,6 @@ def compute_all_project_generated(self):
else:
rec.all_project_generated = False

@api.model
def read_group(self, domain, fields, groupby, offset=0,
limit=None, orderby=False, lazy=True):
if groupby and groupby[0] == "state":
states = self.env['business.requirement'].\
fields_get(['state']).get('state').get('selection')
read_group_all_states = [{'__context': {'group_by': groupby[1:]},
'__domain': domain + [('state', '=',
state_value)],
'state': state_value,
'state_count': 0}
for state_value, state_name in states]
# Get standard results
read_group_res = super(BusinessRequirement, self).\
read_group(domain, fields, groupby, offset=offset,
limit=limit, orderby=orderby)
# Update standard results with default results
result = []
for state_value, state_name in states:
res = filter(lambda x: x['state'] == state_value,
read_group_res)
if not res:
res = filter(lambda x: x['state'] == state_value,
read_group_all_states)
res[0]['state'] = [state_value, state_name]
result.append(res[0])
return result
else:
return super(BusinessRequirement, self).\
read_group(domain, fields, groupby,
offset=offset, limit=limit, orderby=orderby)

@api.multi
def write(self, vals):
for r in self:
if vals.get('state'):
ir_obj = self.env['ir.model.data']
br_xml_id = ir_obj.\
get_object('business_requirement',
'group_business_requirement_manager')
user = self.env['res.users']
grps = [grp.id for grp in user.browse(self._uid).groups_id]
date = fields.Datetime.now()
if vals['state'] == 'confirmed':
vals.update({'confirmed_id': user,
'confirmation_date': date})
if vals['state'] == 'draft':
vals.update({'confirmed_id': False,
'approved_id': False,
'confirmation_date': False,
'approval_date': False
})
if vals['state'] == 'approved':
if br_xml_id.id in grps:
vals.update({'approved_id': user,
'approval_date': date})
else:
raise UserError(_('You can only move to the '
'following stage: draft/confirmed'
'/cancel/drop.'))
if vals['state'] in ('stakeholder_approval', 'in_progress',
'done'):
if br_xml_id.id not in grps:
raise UserError(_('You can only move to the'
'following stage: draft/'
'confirmed/cancel/drop.'))
return super(BusinessRequirement, self).write(vals)

@api.multi
@api.depends('task_ids')
def _compute_task_count(self):
Expand Down
Loading

0 comments on commit d312426

Please sign in to comment.