mrp_parser.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # This program is distributed in the hope that it will be useful,
  4. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  5. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6. # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
  7. #
  8. # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
  9. # GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
  10. # If not, see <http://www.gnu.org/licenses/>.
  11. #
  12. ##############################################################################
  13. import datetime
  14. from openerp.osv import osv
  15. from openerp.report import report_sxw
  16. class MrpReport(report_sxw.rml_parse):
  17. def __init__(self, cr, uid, name, context=None):
  18. super(MrpReport, self).__init__(cr, uid, name, context=context)
  19. self.localcontext.update({
  20. 'get_details': self.get_details,
  21. 'get_date': self.get_date,
  22. })
  23. self.context = context
  24. def get_date(self):
  25. date = datetime.datetime.now()
  26. return date
  27. def get_details(self, data):
  28. lines = []
  29. if data['filter'] is True:
  30. if data['filter_user'] is True:
  31. if len(data['product']) > 0 \
  32. and data['stage'] is not False:
  33. for k in range(0, len(data['product'])):
  34. for l in range(0, len(data['responsible'])):
  35. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  36. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  37. if (data['date_from'] <= obj.date_planned) \
  38. and (data['date_to'] >= obj.date_planned) \
  39. and obj.state == data['stage'] \
  40. and obj.product_id.id == data['product'][k] \
  41. and obj.user_id.id == data['responsible'][l]:
  42. lines.append(obj)
  43. elif len(data['product']) == 0 and data['stage'] is not False:
  44. for l in range(0, len(data['responsible'])):
  45. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  46. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  47. if (data['date_from'] <= obj.date_planned) \
  48. and (data['date_to'] >= obj.date_planned) \
  49. and obj.state == data['stage'] \
  50. and obj.user_id.id == data['responsible'][l]:
  51. lines.append(obj)
  52. if len(data['product']) > 0 \
  53. and data['stage'] is False:
  54. for k in range(0, len(data['product'])):
  55. for l in range(0, len(data['responsible'])):
  56. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  57. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  58. if (data['date_from'] <= obj.date_planned) \
  59. and (data['date_to'] >= obj.date_planned) \
  60. and obj.product_id.id == data['product'][k] \
  61. and obj.user_id.id == data['responsible'][l]:
  62. lines.append(obj)
  63. if len(data['product']) == 0 \
  64. and data['stage'] is False:
  65. for l in range(0, len(data['responsible'])):
  66. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  67. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  68. if (data['date_from'] <= obj.date_planned) \
  69. and (data['date_to'] >= obj.date_planned) \
  70. and obj.user_id.id == data['responsible'][l]:
  71. lines.append(obj)
  72. if data['filter_user'] is False:
  73. if len(data['product']) > 0 \
  74. and data['stage'] is not False:
  75. for k in range(0, len(data['product'])):
  76. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  77. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  78. if (data['date_from'] <= obj.date_planned) \
  79. and (data['date_to'] >= obj.date_planned) \
  80. and obj.state == data['stage'] \
  81. and obj.product_id.id == data['product'][k]:
  82. lines.append(obj)
  83. elif len(data['product']) == 0 and data['stage'] is not False:
  84. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  85. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  86. if (data['date_from'] <= obj.date_planned) \
  87. and (data['date_to'] >= obj.date_planned) \
  88. and obj.state == data['stage']:
  89. lines.append(obj)
  90. if len(data['product']) > 0 \
  91. and data['stage'] is False:
  92. for k in range(0, len(data['product'])):
  93. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  94. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  95. if (data['date_from'] <= obj.date_planned) \
  96. and (data['date_to'] >= obj.date_planned) \
  97. and obj.product_id.id == data['product'][k]:
  98. lines.append(obj)
  99. if len(data['product']) == 0 \
  100. and data['stage'] is False:
  101. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  102. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  103. if (data['date_from'] <= obj.date_planned) \
  104. and (data['date_to'] >= obj.date_planned):
  105. lines.append(obj)
  106. if data['filter'] is False:
  107. if data['filter_user'] is True:
  108. if len(data['product']) > 0 \
  109. and data['stage'] is not False:
  110. for k in range(0, len(data['product'])):
  111. for l in range(0, len(data['responsible'])):
  112. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  113. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  114. if obj.state == data['stage'] \
  115. and obj.product_id.id == data['product'][k] \
  116. and obj.user_id.id == data['responsible'][l]:
  117. lines.append(obj)
  118. elif len(data['product']) == 0 and data['stage'] is not False:
  119. for l in range(0, len(data['responsible'])):
  120. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  121. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  122. if obj.state == data['stage'] \
  123. and obj.user_id.id == data['responsible'][l]:
  124. lines.append(obj)
  125. if len(data['product']) > 0 \
  126. and data['stage'] is False:
  127. for k in range(0, len(data['product'])):
  128. for l in range(0, len(data['responsible'])):
  129. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  130. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  131. if obj.product_id.id == data['product'][k] \
  132. and obj.user_id.id == data['responsible'][l]:
  133. lines.append(obj)
  134. if len(data['product']) == 0 \
  135. and data['stage'] is False:
  136. for l in range(0, len(data['responsible'])):
  137. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  138. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  139. if obj.user_id.id == data['responsible'][l]:
  140. lines.append(obj)
  141. if data['filter_user'] is False:
  142. if len(data['product']) > 0 \
  143. and data['stage'] is not False:
  144. for k in range(0, len(data['product'])):
  145. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  146. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  147. if obj.state == data['stage'] \
  148. and obj.product_id.id == data['product'][k]:
  149. lines.append(obj)
  150. elif len(data['product']) == 0 and data['stage'] is not False:
  151. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  152. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  153. if obj.state == data['stage']:
  154. lines.append(obj)
  155. if len(data['product']) > 0 \
  156. and data['stage'] is False:
  157. for k in range(0, len(data['product'])):
  158. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  159. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  160. if obj.product_id.id == data['product'][k]:
  161. lines.append(obj)
  162. if len(data['product']) == 0 \
  163. and data['stage'] is False:
  164. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  165. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  166. lines.append(obj)
  167. return lines
  168. class PrintReport(osv.AbstractModel):
  169. _name = 'report.eirumrp_reports.mrp_pdf'
  170. _inherit = 'report.abstract_report'
  171. _template = 'eirumrp_reports.mrp_pdf'
  172. _wrapped_report_class = MrpReport