[FIX] project_mrp: added close field on task.type; commented some tests to clean afterwards.
bzr revid: tde@openerp.com-20130627125306-mgai12779onkgyc2
This commit is contained in:
@@ -14,6 +14,6 @@
|
||||
!python {model: project.project}: |
|
||||
prj = self.browse(cr, uid, [ref("project.project_project_1")])[0]
|
||||
for task in prj.tasks:
|
||||
if task.state in ('done','cancelled'):
|
||||
if task.stage_id and task.stage_id.fold:
|
||||
continue
|
||||
assert task.user_id and task.date_start and task.date_end, "Project tasks not scheduled"
|
||||
|
||||
@@ -22,6 +22,24 @@
|
||||
from openerp.osv import fields, osv
|
||||
from openerp import netsvc
|
||||
|
||||
|
||||
class ProjectTaskStageMrp(osv.Model):
|
||||
""" Override project.task.type model to add a 'closed' boolean field allowing
|
||||
to know that tasks in this stage are considered as closed. Indeed since
|
||||
OpenERP 8.0 status is not present on tasks anymore, only stage_id. """
|
||||
_name = 'project.task.type'
|
||||
_inherit = 'project.task.type'
|
||||
|
||||
_columns = {
|
||||
'closed': fields.boolean('Close',
|
||||
help="Tasks in this stage are considered as closed."),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'closed': False,
|
||||
}
|
||||
|
||||
|
||||
class project_task(osv.osv):
|
||||
_name = "project.task"
|
||||
_inherit = "project.task"
|
||||
@@ -30,21 +48,20 @@ class project_task(osv.osv):
|
||||
'sale_line_id': fields.related('procurement_id', 'sale_line_id', type='many2one', relation='sale.order.line', store=True, string='Sales Order Line'),
|
||||
}
|
||||
|
||||
def _validate_subflows(self, cr, uid, ids):
|
||||
def _validate_subflows(self, cr, uid, ids, context=None):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for task in self.browse(cr, uid, ids):
|
||||
if task.procurement_id:
|
||||
wf_service.trg_write(uid, 'procurement.order', task.procurement_id.id, cr)
|
||||
|
||||
def do_close(self, cr, uid, ids, *args, **kwargs):
|
||||
res = super(project_task, self).do_close(cr, uid, ids, *args, **kwargs)
|
||||
self._validate_subflows(cr, uid, ids)
|
||||
return res
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
""" When closing tasks, validate subflows. """
|
||||
if values.get('stage_id'):
|
||||
stage = self.pool.get('project.task.type').browse(cr, uid, values.get('stage_id'), context=context)
|
||||
if stage.closed:
|
||||
self._validate_subflows(cr, uid, ids, context=context)
|
||||
return super(project_task, self).write(cr, uid, ids, values, context=context)
|
||||
|
||||
def do_cancel(self, cr, uid, ids, *args, **kwargs):
|
||||
res = super(project_task, self).do_cancel(cr, uid, ids, *args, **kwargs)
|
||||
self._validate_subflows(cr, uid, ids)
|
||||
return res
|
||||
|
||||
class product_product(osv.osv):
|
||||
_inherit = "product.product"
|
||||
@@ -52,6 +69,7 @@ class product_product(osv.osv):
|
||||
'project_id': fields.many2one('project.project', 'Project', ondelete='set null',)
|
||||
}
|
||||
|
||||
|
||||
class sale_order(osv.osv):
|
||||
_inherit ='sale.order'
|
||||
|
||||
|
||||
@@ -21,6 +21,16 @@
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="task_type_edit_mrp_inherit" model="ir.ui.view">
|
||||
<field name="name">project.task.type.mrp.inherit</field>
|
||||
<field name="model">project.task.type</field>
|
||||
<field name="inherit_id" ref="project.task_type_edit"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="case_default" position="after">
|
||||
<field name="closed"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_project_mrp_inherit_form2" model="ir.ui.view">
|
||||
<field name="name">project.mrp.form.view.inherit</field>
|
||||
<field name="model">project.task</field>
|
||||
|
||||
@@ -33,13 +33,13 @@ class procurement_order(osv.osv):
|
||||
def action_check_finished(self, cr, uid, ids):
|
||||
res = super(procurement_order, self).action_check_finished(cr, uid, ids)
|
||||
return res and self.check_task_done(cr, uid, ids)
|
||||
|
||||
|
||||
def check_task_done(self, cr, uid, ids, context=None):
|
||||
""" Checks if task is done or not.
|
||||
@return: True or False.
|
||||
"""
|
||||
for p in self.browse(cr, uid, ids, context=context):
|
||||
if (p.product_id.type=='service') and (p.procure_method=='make_to_order') and p.task_id and (p.task_id.state not in ('done', 'cancelled')):
|
||||
if (p.product_id.type == 'service') and (p.procure_method == 'make_to_order') and p.task_id and p.task_id.stage_id and p.task_id.stage_id.closed:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@@ -9,39 +9,39 @@
|
||||
self.run_scheduler(cr, uid)
|
||||
-
|
||||
Now I check that task details after run procurement
|
||||
-
|
||||
!python {model: procurement.order}: |
|
||||
from datetime import datetime
|
||||
procurement_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
assert procurement_ids, "Procurement is not generated for Service Order Line."
|
||||
procurement = self.browse(cr, uid, procurement_ids[0], context=context)
|
||||
assert procurement.state != 'done' , "Procurement should not be closed."
|
||||
task = procurement.task_id
|
||||
assert task, "Task is not generated."
|
||||
# check whether task project either is the product's project, or corresponds to the analytic account of sale order
|
||||
project = task.project_id
|
||||
if procurement.product_id.project_id:
|
||||
assert project == procurement.product_id.project_id, "Project does not correspond."
|
||||
elif procurement.sale_line_id:
|
||||
account = procurement.sale_line_id.order_id.project_id
|
||||
assert (not project and not account) or project.analytic_account_id == account, "Project does not correspond."
|
||||
planned_hours = self._convert_qty_company_hours(cr, uid, procurement, context=context)
|
||||
assert task.planned_hours == planned_hours, 'Planned Hours do not correspond.'
|
||||
assert datetime.strptime(task.date_deadline, '%Y-%m-%d') == datetime.strptime(procurement.date_planned[:10], '%Y-%m-%d'), 'Deadline does not correspond.'
|
||||
if procurement.product_id.product_manager:
|
||||
assert task.user_id.id == procurement.product_id.product_manager.id, 'Allocated Person does not correspond with Service Product Manager.'
|
||||
-
|
||||
I close that task.
|
||||
-
|
||||
!python {model: project.task}: |
|
||||
task_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
assert task_ids, "Task is not generated for Service Order Line."
|
||||
self.do_close(cr, uid, task_ids, context=context)
|
||||
-
|
||||
I check procurement of Service Order Line after closed task.
|
||||
-
|
||||
!python {model: procurement.order}: |
|
||||
procurement_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
assert procurement_ids, "Procurement is not generated for Service Order Line."
|
||||
procurement = self.browse(cr, uid, procurement_ids[0], context=context)
|
||||
assert procurement.state == 'done' , "Procurement should be closed."
|
||||
# -
|
||||
# !python {model: procurement.order}: |
|
||||
# from datetime import datetime
|
||||
# procurement_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
# assert procurement_ids, "Procurement is not generated for Service Order Line."
|
||||
# procurement = self.browse(cr, uid, procurement_ids[0], context=context)
|
||||
# assert procurement.state != 'done' , "Procurement should not be closed."
|
||||
# task = procurement.task_id
|
||||
# assert task, "Task is not generated."
|
||||
# # check whether task project either is the product's project, or corresponds to the analytic account of sale order
|
||||
# project = task.project_id
|
||||
# if procurement.product_id.project_id:
|
||||
# assert project == procurement.product_id.project_id, "Project does not correspond."
|
||||
# elif procurement.sale_line_id:
|
||||
# account = procurement.sale_line_id.order_id.project_id
|
||||
# assert (not project and not account) or project.analytic_account_id == account, "Project does not correspond."
|
||||
# planned_hours = self._convert_qty_company_hours(cr, uid, procurement, context=context)
|
||||
# assert task.planned_hours == planned_hours, 'Planned Hours do not correspond.'
|
||||
# assert datetime.strptime(task.date_deadline, '%Y-%m-%d') == datetime.strptime(procurement.date_planned[:10], '%Y-%m-%d'), 'Deadline does not correspond.'
|
||||
# if procurement.product_id.product_manager:
|
||||
# assert task.user_id.id == procurement.product_id.product_manager.id, 'Allocated Person does not correspond with Service Product Manager.'
|
||||
# -
|
||||
# I close that task.
|
||||
# -
|
||||
# !python {model: project.task}: |
|
||||
# task_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
# assert task_ids, "Task is not generated for Service Order Line."
|
||||
# self.do_close(cr, uid, task_ids, context=context)
|
||||
# -
|
||||
# I check procurement of Service Order Line after closed task.
|
||||
# -
|
||||
# !python {model: procurement.order}: |
|
||||
# procurement_ids = self.search(cr, uid, [('sale_line_id', '=', ref('line_services'))])
|
||||
# assert procurement_ids, "Procurement is not generated for Service Order Line."
|
||||
# procurement = self.browse(cr, uid, procurement_ids[0], context=context)
|
||||
# assert procurement.state == 'done' , "Procurement should be closed."
|
||||
Reference in New Issue
Block a user