123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- # -*- 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')
|