123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
- #
- # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
- # GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
- # If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- import xlwt
- import datetime
- from openerp.addons.report_xls.report_xls import report_xls
- def get_xls(obj):
- getvals = {
- 'name': obj.name,
- 'product': obj.product_id.name,
- 'product_qty': obj.product_qty,
- 'product_uom': obj.product_uom.name,
- 'prod_price_unit': obj.prod_price_unit,
- 'product_price': obj.product_price,
- 'user_id': obj.user_id.name,
- 'date_planned': obj.date_planned,
- 'state': obj.state,
- }
- templist1 = [(1, 3, 0, 'text', getvals['name']),
- (2, 3, 0, 'text', getvals['product']),
- (3, 2, 0, 'text', getvals['product_qty']),
- (4, 2, 0, 'text', getvals['product_uom']),
- (5, 2, 0, 'text', getvals['prod_price_unit']),
- (6, 2, 0, 'text', getvals['product_price']),
- (7, 2, 0, 'text', getvals['user_id']),
- (8, 1, 0, 'text', getvals['date_planned']),
- (9, 1, 0, 'text', getvals['state']),
- ]
- return templist1
- class MrpXlsReport(report_xls):
- def generate_xls_report(self, _p, _xs, data, objects, wb):
- report_name = "Ordenes de producción"
- ws = wb.add_sheet(report_name[:31])
- ws.panes_frozen = True
- ws.remove_splits = True
- ws.portrait = 1
- ws.fit_width_to_pages = 1
- row_pos = 0
- ws.set_horz_split_pos(row_pos)
- ws.header_str = self.xls_headers['standard']
- ws.footer_str = self.xls_footers['standard']
- _xs.update({
- 'xls_title': 'font: bold true, height 350;'
- })
- _xs.update({
- 'xls_sub_title': 'font: bold false, height 250;'
- })
- cell_style = xlwt.easyxf(_xs['xls_title'] + _xs['center'])
- cell_center = xlwt.easyxf(_xs['center'])
- cell_center_bold_no = xlwt.easyxf(_xs['center'] + _xs['bold'])
- cell_left_b = xlwt.easyxf(_xs['left'] + _xs['bold'])
- c_specs = [('report_name', 8, 0, 'text', report_name)]
- row_pos += 1
- row_data = self.xls_row_template(c_specs, ['report_name'])
- row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
- ws.row(row_pos - 1).height_mismatch = True
- ws.row(row_pos - 1).height = 220 * 2
- row_pos += 1
- date_report = "Fecha del informe :" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M %p"))
- top2 = [('entry1', 3, 0, 'text', date_report)]
- row_data = self.xls_row_template(top2, [x[0] for x in top2])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_left_b)
- row_pos += 1
- templist = [(1, 3, 0, 'text', 'Referencia'),
- (2, 3, 0, 'text', 'Producto'),
- (3, 2, 0, 'text', 'Cantidad'),
- (4, 2, 0, 'text', 'Unidad'),
- (5, 2, 0, 'text', 'Costo unit.'),
- (6, 2, 0, 'text', 'Costo Prod.'),
- (7, 2, 0, 'text', 'Responsable'),
- (8, 1, 0, 'text', 'Fecha inicio'),
- (9, 1, 0, 'text', 'Estado'), ]
- row_pos += 1
- row_data = self.xls_row_template(templist, [x[0] for x in templist])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center_bold_no)
- if data['filter'] is True:
- if data['filter_user'] is True:
- if len(data['product']) > 0 \
- and data['stage'] is not False:
- for k in range(0, len(data['product'])):
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.state == data['stage'] \
- and obj.product_id.id == data['product'][k] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- elif len(data['product']) == 0 and data['stage'] is not False:
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.state == data['stage'] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) > 0 \
- and data['stage'] is False:
- for k in range(0, len(data['product'])):
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.product_id.id == data['product'][k] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) == 0 \
- and data['stage'] is False:
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if data['filter_user'] is False:
- if len(data['product']) > 0 \
- and data['stage'] is not False:
- for k in range(0, len(data['product'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.state == data['stage'] \
- and obj.product_id.id == data['product'][k]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- elif len(data['product']) == 0 and data['stage'] is not False:
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.state == data['stage']:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) > 0 \
- and data['stage'] is False:
- for k in range(0, len(data['product'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned) \
- and obj.product_id.id == data['product'][k]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) == 0 \
- and data['stage'] is False:
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if (data['date_from'] <= obj.date_planned) \
- and (data['date_to'] >= obj.date_planned):
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if data['filter'] is False:
- if data['filter_user'] is True:
- if len(data['product']) > 0 \
- and data['stage'] is not False:
- for k in range(0, len(data['product'])):
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.state == data['stage'] \
- and obj.product_id.id == data['product'][k] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- elif len(data['product']) == 0 and data['stage'] is not False:
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.state == data['stage'] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) > 0 \
- and data['stage'] is False:
- for k in range(0, len(data['product'])):
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.product_id.id == data['product'][k] \
- and obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) == 0 \
- and data['stage'] is False:
- for l in range(0, len(data['responsible'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.user_id.id == data['responsible'][l]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if data['filter_user'] is False:
- if len(data['product']) > 0 \
- and data['stage'] is not False:
- for k in range(0, len(data['product'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.state == data['stage'] \
- and obj.product_id.id == data['product'][k]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- elif len(data['product']) == 0 and data['stage'] is not False:
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.state == data['stage']:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) > 0 \
- and data['stage'] is False:
- for k in range(0, len(data['product'])):
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- if obj.product_id.id == data['product'][k]:
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- if len(data['product']) == 0 \
- and data['stage'] is False:
- for i in self.pool.get('mrp.production').search(self.cr, self.uid, []):
- obj = self.pool.get('mrp.production').browse(self.cr, self.uid, i)
- templist1 = get_xls(obj)
- row_data = self.xls_row_template(templist1, [x[0] for x in templist1])
- row_pos = self.xls_write_row(ws, row_pos, row_data, cell_center)
- MrpXlsReport('report.eirumrp_reports_xls', 'mrp.production')
|