# -*- coding: utf-8 -*- from openerp import models, fields, tools, api import openerp.addons.decimal_precision as dp class constructionTask(models.Model): _name = 'construction.task' name = fields.Char('name', required=True) display_name = fields.Char('display_name') ref = fields.Char('Ref') code = fields.Char('Code', size=32, required=True, select=True) active = fields.Boolean('Active', default=True) comment = fields.Text('Comment', help='InformaciĆ³n Adicional') line_ids = fields.One2many('construction.task.line', 'construction_task', string='task line') # get constructionTask @api.model def get_construction_task(self, orderID): orderLine = self.env['construction.order.line'].get_construction_order_line(orderID) ''' code, task_name, uom_id, task_id, task_line_id, qty, amount, amount_total, type, order_ids ''' self.env.cr.execute("SELECT id FROM construction_task ORDER BY id") '''get order line ''' tasks = [] for task in self.env['construction.task'].browse(map(lambda x: x['id'], self.env.cr.dictfetchall())): taskIn = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'task')), orderLine) tasks.append({ 'code': task.code, 'taskName': task.name, 'uomId': '', 'uomName': '', 'taskId': task.id, 'taskLineId': '', 'qty': taskIn[0]['qty'] if(len(taskIn)) else 0, 'amount': taskIn[0]['amount'] if(len(taskIn)) else 0, 'amountTotal': taskIn[0]['amountTotal'] if(len(taskIn)) else 0, 'type': 'task', 'selected': True if(len(taskIn)) else False, }) for line in task.line_ids: taskInLine = filter(lambda x: x['taskLineId'] == line.id, orderLine) tasks.append({ 'code': line.code, 'taskName': line.name, 'uomId': line.construction_uom.id or '', 'uomName': line.construction_uom.name or '', 'taskId': task.id, 'taskLineId': line.id, 'qty': taskInLine[0]['qty'] if(len(taskInLine)) else 0, 'amount': taskInLine[0]['amount'] if(len(taskInLine)) else 0, 'amountTotal': taskInLine[0]['amountTotal'] if(len(taskInLine)) else 0, 'type': 'activity', 'selected': True if(len(taskInLine)) else False, }) return tasks @api.model def get_task_order(self, idContractor): contractor = self.env['construction.order.contractor'].browse(idContractor) if (not contractor): return False tasks = [] lineTaskContractor = [] allContratista = self.env['construction.order.contractor'].search([('budget_id.id', '=', contractor.budget_id.id)]) for orderContractor in allContratista: for line in orderContractor.line_ids: lineTaskContractor.append({ 'qty': line.qty, 'amount': line.amount, 'amountTotal': line.amount_total, 'orderContractorIds': orderContractor.id, 'taskId': line.task_id.id, 'taskLineId': line.task_line_id.id, }) orderLine = self.env['construction.order.line'].get_construction_order_line(contractor.budget_id.id) for task in self.env['construction.task'].search([('id', 'in', map(lambda x: x['taskId'], orderLine))]): taskIn = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'task')), orderLine) lineContractor = filter(lambda x: (x['taskId'] == taskIn[0]['taskId']), lineTaskContractor) tasks.append( { 'code': task.code, 'taskName': task.name, 'uomId': '', 'uomName': '', 'taskId': task.id, 'taskLineId': '', 'qty': lineContractor[0]['qty'] if(len(lineContractor)) else 0, 'amount': lineContractor[0]['amount'] if(len(lineContractor)) else 0, 'amountTotal': lineContractor[0]['amountTotal'] if(len(lineContractor)) else 0, 'type': 'task', 'selected': True if(len(lineContractor)) else False, 'amountBudget': taskIn[0]['amountTotal'] if(len(taskIn)) else 0, 'contractorId': lineContractor[0]['orderContractorIds'] if(len(lineContractor)) else '', }) taskLinOrder = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'activity')), orderLine) for line in self.env['construction.task.line'].search([('id', 'in', map(lambda x: x['taskLineId'], taskLinOrder))]): taskInLine = filter(lambda x: x['taskLineId'] == line.id, orderLine) linesContractor = filter(lambda x: (x['taskLineId'] == taskInLine[0]['taskLineId']), lineTaskContractor) tasks.append({ 'code': line.code, 'taskName': line.name, 'uomId': line.construction_uom.id or '', 'uomName': line.construction_uom.name or '', 'taskId': task.id, 'taskLineId': line.id, 'qty': taskInLine[0]['qty'], 'amount': linesContractor[0]['amount'] if(len(linesContractor)) else 0, 'amountTotal': linesContractor[0]['amountTotal'] if(len(linesContractor)) else 0, 'type': 'activity', 'amountBudget' :taskInLine[0]['amountTotal'] if(len(taskInLine)) else 0, 'contractorId':linesContractor[0]['orderContractorIds'] if(len(linesContractor)) else '', 'selected': True if(len(linesContractor)) else False, }) return tasks class constructionTaskLine(models.Model): _name = "construction.task.line" construction_uom = fields.Many2one('construction.uom', string='Unidad de medida', ondelete='cascade', index=True, required=True) construction_task = fields.Many2one('construction.task', string='construction task', ondelete='cascade', index=True, required=True) name = fields.Char('name', required=True) display_name = fields.Char('display_name') ref = fields.Char('Ref') code = fields.Char('Code', size=32, required=True, select=True) amount = fields.Float('Amount Unit', digits_compute=dp.get_precision('Account'), required=True, default=0.0) active = fields.Boolean('Active', default=True) comment = fields.Text('Comment', help='InformaciĆ³n Adicional')