diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index 14b057fe4d9..1d20fe45a9f 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -158,12 +158,7 @@ class procurement_order(osv.osv): """ Checks product type. @return: True or False """ - res = False - for procurement in self.browse(cr, uid, ids, context=context): - product = procurement.product_id - if product.type in ('product', 'consu'): - res = True - return res + return all(proc.product_id.type in ('product', 'consu') for proc in self.browse(cr, uid, ids, context=context)) def check_move_cancel(self, cr, uid, ids, context=None): """ Checks if move is cancelled or not. @@ -179,14 +174,9 @@ class procurement_order(osv.osv): """ Checks if move is done or not. @return: True or False. """ - res = False - for procurement in self.browse(cr, uid, ids, context=context): - product = procurement.product_id - if product.type == 'service': - res = True - if procurement.move_id and procurement.move_id.state == 'done': - res = True - return res + return all(proc.product_id.type == 'service' or (proc.move_id and proc.move_id.state == 'done') \ + for proc in self.browse(cr, uid, ids, context=context)) + # # This method may be overrided by objects that override procurement.order # for computing their own purpose @@ -268,9 +258,8 @@ class procurement_order(osv.osv): def check_produce(self, cr, uid, ids, context=None): """ Checks product type. - @return: True or Product Id. + @return: True or False """ - res = True user = self.pool.get('res.users').browse(cr, uid, uid, context=context) for procurement in self.browse(cr, uid, ids, context=context): product = procurement.product_id @@ -279,15 +268,15 @@ class procurement_order(osv.osv): supplier = product.seller_id if supplier and user.company_id and user.company_id.partner_id: if supplier.id == user.company_id.partner_id.id: - res = True - res = False + continue + return False if product.type=='service': - res = res and self.check_produce_service(cr, uid, procurement, context) + res = self.check_produce_service(cr, uid, procurement, context) else: - res = res and self.check_produce_product(cr, uid, procurement, context) + res = self.check_produce_product(cr, uid, procurement, context) if not res: return False - return res + return True def check_buy(self, cr, uid, ids): """ Checks product type. diff --git a/addons/project_mrp/project_procurement.py b/addons/project_mrp/project_procurement.py index e84ecedbe86..7d3045aede0 100644 --- a/addons/project_mrp/project_procurement.py +++ b/addons/project_mrp/project_procurement.py @@ -37,14 +37,8 @@ class procurement_order(osv.osv): """ Checks if task is done or not. @return: True or False. """ - res = False - for procurement in self.browse(cr, uid, ids, context=context): - product = procurement.product_id - if product.type<>'service': - res = True - if procurement.task_id and procurement.task_id.state in ('done', 'cancelled'): - res = True - return res + return all(proc.product_id.type != 'service' or (proc.task_id and proc.task_id.state in ('done', 'cancelled')) \ + for proc in self.browse(cr, uid, ids, context=context)) def check_produce_service(self, cr, uid, procurement, context=None): return True @@ -62,10 +56,11 @@ class procurement_order(osv.osv): project_project = self.pool.get('project.project') project = procurement.product_id.project_id if not project and procurement.sale_line_id: - analytic_account = procurement.sale_line_id.order_id.project_id - if analytic_account: - project_ids = project_project.search(cr, uid, [('analytic_account_id', '=', account_id)]) - project = project_project.browse(cr, uid, project_ids[0], context=context) + # find the project corresponding to the analytic account of the sale order + account = procurement.sale_line_id.order_id.project_id + project_ids = project_project.search(cr, uid, [('analytic_account_id', '=', account.id)]) + projects = project_project.browse(cr, uid, project_ids, context=context) + project = projects and projects[0] or False return project def action_produce_assign_service(self, cr, uid, ids, context=None): @@ -85,7 +80,7 @@ class procurement_order(osv.osv): 'project_id': project and project.id or False, 'company_id': procurement.company_id.id, },context=context) - self.write(cr, uid, [procurement.id], {'task_id':task_id, 'state': 'running'}, context=context) + self.write(cr, uid, [procurement.id], {'task_id': task_id, 'state': 'running'}, context=context) return task_id procurement_order() diff --git a/addons/project_mrp/test/project_task_procurement.yml b/addons/project_mrp/test/project_task_procurement.yml index dc613146822..b72527e61a5 100644 --- a/addons/project_mrp/test/project_task_procurement.yml +++ b/addons/project_mrp/test/project_task_procurement.yml @@ -18,19 +18,19 @@ assert procurement.state != 'done' , "Procurement should not be closed." task = procurement.task_id assert task, "Task is not generated." - planned_hours = self._convert_qty_company_hours(cr, uid, procurement, context=context) - project_id = False + # 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: - project_id = procurement.product_id.project_id.id + assert project == procurement.product_id.project_id, "Project does not correspond." elif procurement.sale_line_id: - project_id = procurement.sale_line_id.order_id.project_id.id #TOFIX: is project_id exits in sale.order object ? - if project_id: - assert task.project_id.id == project_id, "Project is not correspond." - assert task.planned_hours == planned_hours, 'Planned Hours are not correspond.' - assert datetime.strptime(task.date_deadline, '%Y-%m-%d') == datetime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S'), 'Deadline is not correspond.' + 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, '%Y-%m-%d %H:%M:%S'), 'Deadline does not correspond.' if procurement.product_id.product_manager: - assert task.user_id.id == procurement.product_id.product_manager.id, 'Allocated Person is not correspond with Service Product Manager.' - assert task.description == procurement.note, "Task description is not correspond." + assert task.user_id.id == procurement.product_id.product_manager.id, 'Allocated Person does not correspond with Service Product Manager.' + assert task.description == procurement.note, "Task description does not correspond." - I close that task. -