eirumrp_report_xls.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 xlwt
  14. import datetime
  15. from openerp.addons.report_xls.report_xls import report_xls
  16. def get_xls(obj):
  17. getvals = {
  18. 'name': obj.name,
  19. 'product': obj.product_id.name,
  20. 'product_qty': obj.product_qty,
  21. 'product_uom': obj.product_uom.name,
  22. 'prod_price_unit': obj.prod_price_unit,
  23. 'product_price': obj.product_price,
  24. 'user_id': obj.user_id.name,
  25. 'date_planned': obj.date_planned,
  26. 'state': obj.state,
  27. }
  28. templist1 = [(1, 3, 0, 'text', getvals['name']),
  29. (2, 3, 0, 'text', getvals['product']),
  30. (3, 2, 0, 'text', getvals['product_qty']),
  31. (4, 2, 0, 'text', getvals['product_uom']),
  32. (5, 2, 0, 'text', getvals['prod_price_unit']),
  33. (6, 2, 0, 'text', getvals['product_price']),
  34. (7, 2, 0, 'text', getvals['user_id']),
  35. (8, 1, 0, 'text', getvals['date_planned']),
  36. (9, 1, 0, 'text', getvals['state']),
  37. ]
  38. return templist1
  39. class MrpXlsReport(report_xls):
  40. def generate_xls_report(self, _p, _xs, data, objects, wb):
  41. report_name = "Ordenes de producción"
  42. ws = wb.add_sheet(report_name[:31])
  43. ws.panes_frozen = True
  44. ws.remove_splits = True
  45. ws.portrait = 1
  46. ws.fit_width_to_pages = 1
  47. row_pos = 0
  48. ws.set_horz_split_pos(row_pos)
  49. ws.header_str = self.xls_headers['standard']
  50. ws.footer_str = self.xls_footers['standard']
  51. _xs.update({
  52. 'xls_title': 'font: bold true, height 350;'
  53. })
  54. _xs.update({
  55. 'xls_sub_title': 'font: bold false, height 250;'
  56. })
  57. cell_style = xlwt.easyxf(_xs['xls_title'] + _xs['center'])
  58. cell_center = xlwt.easyxf(_xs['center'])
  59. cell_center_bold_no = xlwt.easyxf(_xs['center'] + _xs['bold'])
  60. cell_left_b = xlwt.easyxf(_xs['left'] + _xs['bold'])
  61. c_specs = [('report_name', 8, 0, 'text', report_name)]
  62. row_pos += 1
  63. row_data = self.xls_row_template(c_specs, ['report_name'])
  64. row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
  65. ws.row(row_pos - 1).height_mismatch = True
  66. ws.row(row_pos - 1).height = 220 * 2
  67. row_pos += 1
  68. date_report = "Fecha del informe :" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M %p"))
  69. top2 = [('entry1', 3, 0, 'text', date_report)]
  70. row_data = self.xls_row_template(top2, [x[0] for x in top2])
  71. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_left_b)
  72. row_pos += 1
  73. templist = [(1, 3, 0, 'text', 'Referencia'),
  74. (2, 3, 0, 'text', 'Producto'),
  75. (3, 2, 0, 'text', 'Cantidad'),
  76. (4, 2, 0, 'text', 'Unidad'),
  77. (5, 2, 0, 'text', 'Costo unit.'),
  78. (6, 2, 0, 'text', 'Costo Prod.'),
  79. (7, 2, 0, 'text', 'Responsable'),
  80. (8, 1, 0, 'text', 'Fecha inicio'),
  81. (9, 1, 0, 'text', 'Estado'), ]
  82. row_pos += 1
  83. row_data = self.xls_row_template(templist, [x[0] for x in templist])
  84. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center_bold_no)
  85. if data['filter'] is True:
  86. if data['filter_user'] is True:
  87. if len(data['product']) > 0 \
  88. and data['stage'] is not False:
  89. for k in range(0, len(data['product'])):
  90. for l in range(0, len(data['responsible'])):
  91. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  92. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  93. if (data['date_from'] <= obj.date_planned) \
  94. and (data['date_to'] >= obj.date_planned) \
  95. and obj.state == data['stage'] \
  96. and obj.product_id.id == data['product'][k] \
  97. and obj.user_id.id == data['responsible'][l]:
  98. templist1 = get_xls(obj)
  99. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  100. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  101. elif len(data['product']) == 0 and data['stage'] is not False:
  102. for l in range(0, len(data['responsible'])):
  103. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  104. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  105. if (data['date_from'] <= obj.date_planned) \
  106. and (data['date_to'] >= obj.date_planned) \
  107. and obj.state == data['stage'] \
  108. and obj.user_id.id == data['responsible'][l]:
  109. templist1 = get_xls(obj)
  110. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  111. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  112. if len(data['product']) > 0 \
  113. and data['stage'] is False:
  114. for k in range(0, len(data['product'])):
  115. for l in range(0, len(data['responsible'])):
  116. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  117. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  118. if (data['date_from'] <= obj.date_planned) \
  119. and (data['date_to'] >= obj.date_planned) \
  120. and obj.product_id.id == data['product'][k] \
  121. and obj.user_id.id == data['responsible'][l]:
  122. templist1 = get_xls(obj)
  123. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  124. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  125. if len(data['product']) == 0 \
  126. and data['stage'] is False:
  127. for l in range(0, len(data['responsible'])):
  128. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  129. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  130. if (data['date_from'] <= obj.date_planned) \
  131. and (data['date_to'] >= obj.date_planned) \
  132. and obj.user_id.id == data['responsible'][l]:
  133. templist1 = get_xls(obj)
  134. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  135. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  136. if data['filter_user'] is False:
  137. if len(data['product']) > 0 \
  138. and data['stage'] is not False:
  139. for k in range(0, len(data['product'])):
  140. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  141. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  142. if (data['date_from'] <= obj.date_planned) \
  143. and (data['date_to'] >= obj.date_planned) \
  144. and obj.state == data['stage'] \
  145. and obj.product_id.id == data['product'][k]:
  146. templist1 = get_xls(obj)
  147. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  148. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  149. elif len(data['product']) == 0 and data['stage'] is not False:
  150. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  151. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  152. if (data['date_from'] <= obj.date_planned) \
  153. and (data['date_to'] >= obj.date_planned) \
  154. and obj.state == data['stage']:
  155. templist1 = get_xls(obj)
  156. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  157. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  158. if len(data['product']) > 0 \
  159. and data['stage'] is False:
  160. for k in range(0, len(data['product'])):
  161. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  162. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  163. if (data['date_from'] <= obj.date_planned) \
  164. and (data['date_to'] >= obj.date_planned) \
  165. and obj.product_id.id == data['product'][k]:
  166. templist1 = get_xls(obj)
  167. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  168. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  169. if len(data['product']) == 0 \
  170. and data['stage'] is False:
  171. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  172. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  173. if (data['date_from'] <= obj.date_planned) \
  174. and (data['date_to'] >= obj.date_planned):
  175. templist1 = get_xls(obj)
  176. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  177. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  178. if data['filter'] is False:
  179. if data['filter_user'] is True:
  180. if len(data['product']) > 0 \
  181. and data['stage'] is not False:
  182. for k in range(0, len(data['product'])):
  183. for l in range(0, len(data['responsible'])):
  184. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  185. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  186. if obj.state == data['stage'] \
  187. and obj.product_id.id == data['product'][k] \
  188. and obj.user_id.id == data['responsible'][l]:
  189. templist1 = get_xls(obj)
  190. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  191. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  192. elif len(data['product']) == 0 and data['stage'] is not False:
  193. for l in range(0, len(data['responsible'])):
  194. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  195. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  196. if obj.state == data['stage'] \
  197. and obj.user_id.id == data['responsible'][l]:
  198. templist1 = get_xls(obj)
  199. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  200. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  201. if len(data['product']) > 0 \
  202. and data['stage'] is False:
  203. for k in range(0, len(data['product'])):
  204. for l in range(0, len(data['responsible'])):
  205. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  206. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  207. if obj.product_id.id == data['product'][k] \
  208. and obj.user_id.id == data['responsible'][l]:
  209. templist1 = get_xls(obj)
  210. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  211. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  212. if len(data['product']) == 0 \
  213. and data['stage'] is False:
  214. for l in range(0, len(data['responsible'])):
  215. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  216. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  217. if obj.user_id.id == data['responsible'][l]:
  218. templist1 = get_xls(obj)
  219. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  220. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  221. if data['filter_user'] is False:
  222. if len(data['product']) > 0 \
  223. and data['stage'] is not False:
  224. for k in range(0, len(data['product'])):
  225. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  226. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  227. if obj.state == data['stage'] \
  228. and obj.product_id.id == data['product'][k]:
  229. templist1 = get_xls(obj)
  230. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  231. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  232. elif len(data['product']) == 0 and data['stage'] is not False:
  233. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  234. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  235. if obj.state == data['stage']:
  236. templist1 = get_xls(obj)
  237. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  238. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  239. if len(data['product']) > 0 \
  240. and data['stage'] is False:
  241. for k in range(0, len(data['product'])):
  242. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  243. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  244. if obj.product_id.id == data['product'][k]:
  245. templist1 = get_xls(obj)
  246. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  247. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  248. if len(data['product']) == 0 \
  249. and data['stage'] is False:
  250. for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
  251. obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
  252. templist1 = get_xls(obj)
  253. row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
  254. row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
  255. MrpXlsReport('report.eirumrp_reports_xls', 'mrp.production')