construction_task.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, tools, api
  3. import openerp.addons.decimal_precision as dp
  4. class constructionTask(models.Model):
  5. _name = 'construction.task'
  6. name = fields.Char('name', required=True)
  7. display_name = fields.Char('display_name')
  8. ref = fields.Char('Ref')
  9. code = fields.Char('Code', size=32, required=True, select=True)
  10. active = fields.Boolean('Active', default=True)
  11. comment = fields.Text('Comment', help='Información Adicional')
  12. line_ids = fields.One2many('construction.task.line', 'construction_task', string='task line')
  13. # get constructionTask
  14. @api.model
  15. def get_construction_task(self, orderID):
  16. orderLine = self.env['construction.order.line'].get_construction_order_line(orderID)
  17. ''' code, task_name, uom_id, task_id, task_line_id, qty, amount, amount_total, type, order_ids '''
  18. self.env.cr.execute("SELECT id FROM construction_task ORDER BY id")
  19. '''get order line '''
  20. tasks = []
  21. for task in self.env['construction.task'].browse(map(lambda x: x['id'], self.env.cr.dictfetchall())):
  22. taskIn = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'task')), orderLine)
  23. tasks.append({
  24. 'code': task.code,
  25. 'taskName': task.name,
  26. 'uomId': '',
  27. 'uomName': '',
  28. 'taskId': task.id,
  29. 'taskLineId': '',
  30. 'qty': taskIn[0]['qty'] if(len(taskIn)) else 0,
  31. 'amount': taskIn[0]['amount'] if(len(taskIn)) else 0,
  32. 'amountTotal': taskIn[0]['amountTotal'] if(len(taskIn)) else 0,
  33. 'type': 'task',
  34. 'selected': True if(len(taskIn)) else False,
  35. })
  36. for line in task.line_ids:
  37. taskInLine = filter(lambda x: x['taskLineId'] == line.id, orderLine)
  38. tasks.append({
  39. 'code': line.code,
  40. 'taskName': line.name,
  41. 'uomId': line.construction_uom.id or '',
  42. 'uomName': line.construction_uom.name or '',
  43. 'taskId': task.id,
  44. 'taskLineId': line.id,
  45. 'qty': taskInLine[0]['qty'] if(len(taskInLine)) else 0,
  46. 'amount': taskInLine[0]['amount'] if(len(taskInLine)) else 0,
  47. 'amountTotal': taskInLine[0]['amountTotal'] if(len(taskInLine)) else 0,
  48. 'type': 'activity',
  49. 'selected': True if(len(taskInLine)) else False,
  50. })
  51. return tasks
  52. @api.model
  53. def get_task_order(self, idContractor):
  54. contractor = self.env['construction.order.contractor'].browse(idContractor)
  55. if (not contractor):
  56. return False
  57. tasks = []
  58. lineTaskContractor = []
  59. allContratista = self.env['construction.order.contractor'].search([('budget_id.id', '=', contractor.budget_id.id)])
  60. for orderContractor in allContratista:
  61. for line in orderContractor.line_ids:
  62. lineTaskContractor.append({
  63. 'qty': line.qty,
  64. 'amount': line.amount,
  65. 'amountTotal': line.amount_total,
  66. 'orderContractorIds': orderContractor.id,
  67. 'taskId': line.task_id.id,
  68. 'taskLineId': line.task_line_id.id,
  69. })
  70. orderLine = self.env['construction.order.line'].get_construction_order_line(contractor.budget_id.id)
  71. for task in self.env['construction.task'].search([('id', 'in', map(lambda x: x['taskId'], orderLine))]):
  72. taskIn = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'task')), orderLine)
  73. lineContractor = filter(lambda x: (x['taskId'] == taskIn[0]['taskId']), lineTaskContractor)
  74. tasks.append( {
  75. 'code': task.code,
  76. 'taskName': task.name,
  77. 'uomId': '',
  78. 'uomName': '',
  79. 'taskId': task.id,
  80. 'taskLineId': '',
  81. 'qty': lineContractor[0]['qty'] if(len(lineContractor)) else 0,
  82. 'amount': lineContractor[0]['amount'] if(len(lineContractor)) else 0,
  83. 'amountTotal': lineContractor[0]['amountTotal'] if(len(lineContractor)) else 0,
  84. 'type': 'task',
  85. 'selected': True if(len(lineContractor)) else False,
  86. 'amountBudget': taskIn[0]['amountTotal'] if(len(taskIn)) else 0,
  87. 'contractorId': lineContractor[0]['orderContractorIds'] if(len(lineContractor)) else '',
  88. })
  89. taskLinOrder = filter(lambda x: ((x['taskId'] == task.id) and (x['type'] == 'activity')), orderLine)
  90. for line in self.env['construction.task.line'].search([('id', 'in', map(lambda x: x['taskLineId'], taskLinOrder))]):
  91. taskInLine = filter(lambda x: x['taskLineId'] == line.id, orderLine)
  92. linesContractor = filter(lambda x: (x['taskLineId'] == taskInLine[0]['taskLineId']), lineTaskContractor)
  93. tasks.append({
  94. 'code': line.code,
  95. 'taskName': line.name,
  96. 'uomId': line.construction_uom.id or '',
  97. 'uomName': line.construction_uom.name or '',
  98. 'taskId': task.id,
  99. 'taskLineId': line.id,
  100. 'qty': taskInLine[0]['qty'],
  101. 'amount': linesContractor[0]['amount'] if(len(linesContractor)) else 0,
  102. 'amountTotal': linesContractor[0]['amountTotal'] if(len(linesContractor)) else 0,
  103. 'type': 'activity',
  104. 'amountBudget' :taskInLine[0]['amountTotal'] if(len(taskInLine)) else 0,
  105. 'contractorId':linesContractor[0]['orderContractorIds'] if(len(linesContractor)) else '',
  106. 'selected': True if(len(linesContractor)) else False,
  107. })
  108. return tasks
  109. class constructionTaskLine(models.Model):
  110. _name = "construction.task.line"
  111. construction_uom = fields.Many2one('construction.uom', string='Unidad de medida', ondelete='cascade', index=True, required=True)
  112. construction_task = fields.Many2one('construction.task', string='construction task', ondelete='cascade', index=True, required=True)
  113. name = fields.Char('name', required=True)
  114. display_name = fields.Char('display_name')
  115. ref = fields.Char('Ref')
  116. code = fields.Char('Code', size=32, required=True, select=True)
  117. amount = fields.Float('Amount Unit', digits_compute=dp.get_precision('Account'), required=True, default=0.0)
  118. active = fields.Boolean('Active', default=True)
  119. comment = fields.Text('Comment', help='Información Adicional')