def setUp(self):
        super(BaseTestStockProcurementJIT, self).setUp()
        self.env.context = frozendict(dict(self.env.context, check_product_qty=False))
        self.test_product = self.browse_ref("stock_procurement_just_in_time.product_test_product")
        self.test_product2 = self.browse_ref("stock_procurement_just_in_time.product_test_product2")
        self.test_product3 = self.browse_ref("stock_procurement_just_in_time.product_test_product3")
        self.test_product4 = self.browse_ref("stock_procurement_just_in_time.product_test_product4")
        self.warehouse_orderpoint1 = self.browse_ref("stock_procurement_just_in_time.warehouse_orderpoint1")
        self.stock_location_orig = self.browse_ref("stock_procurement_just_in_time.stock_location_orig")
        self.location_a = self.browse_ref("stock_procurement_just_in_time.stock_location_a")
        self.location_b = self.browse_ref("stock_procurement_just_in_time.stock_location_b")
        self.location_inv = self.browse_ref("stock.location_inventory")
        self.product_uom_unit_id = self.ref("product.product_uom_unit")
        self.unit = self.browse_ref('product.product_uom_unit')
        self.stock = self.browse_ref('stock.stock_location_stock')
        self.customer = self.browse_ref('stock.stock_location_customers')
        self.supplier = self.browse_ref('stock.stock_location_suppliers')
        self.rule_move = self.browse_ref('stock_procurement_just_in_time.rule_move')
        # Compute parent left and right for location so that test don't fail
        self.env['stock.location']._parent_store_compute()
        # Configure cancelled moves/procs deletion
        wizard = self.env['stock.config.settings'].create({'relative_stock_delta': 10,
                                                           'absolute_stock_delta': 1,
                                                           'consider_end_contract_effect': True})
        wizard.execute()
        self.env['queue.job'].search([]).write({'state': 'done'})

        for location in self.env['stock.location'].search([]):
            self.env['stock.location.scheduler.sequence'].create({'location_id': location.id,
                                                                  'name': 0})
Exemplo n.º 2
0
 def default_get(self, fields):
     super(wiz_galaxy_sales_report_detail, self).default_get(fields)
     cr, uid, context = self.env.args
     res = dict(context)
     vals = {'name': 'Sales report.xls'}
     if context.get('report_name', False):
         vals = {'name': context['report_name']}
     res.update(vals)
     self.env.args = cr, uid, misc.frozendict(res)
     if context.get('file'):
         vals1 = {'file': context['file']}
         cr, uid, context = self.env.args
         res = dict(context)
         res.update(vals1)
         self.env.args = cr, uid, misc.frozendict(res)
     return res
Exemplo n.º 3
0
 def go_to_currency_exchange(self):
     '''
      when Money Exchange button is clicked then this method is called.
     -------------------------------------------------------------------
     @param self: object pointer
     '''
     cr, uid, context = self.env.args
     context = dict(context)
     for rec in self:
         if rec.partner_id.id and len(rec.room_lines) != 0:
             context.update({
                 'folioid': rec.id,
                 'guest': rec.partner_id.id,
                 'room_no': rec.room_lines[0].product_id.name,
                 'hotel': rec.warehouse_id.id
             })
             self.env.args = cr, uid, misc.frozendict(context)
         else:
             raise except_orm(_('Warning'), _('Please Reserve Any Room.'))
     return {
         'name': _('Currency Exchange'),
         'res_model': 'currency.exchange',
         'type': 'ir.actions.act_window',
         'view_id': False,
         'view_mode': 'form,tree',
         'view_type': 'form',
         'context': {
             'default_folio_no': context.get('folioid'),
             'default_hotel_id': context.get('hotel'),
             'default_guest_name': context.get('guest'),
             'default_room_number': context.get('room_no')
         },
     }
Exemplo n.º 4
0
 def go_to_currency_exchange(self):
     '''
      when Money Exchange button is clicked then this method is called.
     -------------------------------------------------------------------
     @param self: object pointer
     '''
     cr, uid, context = self.env.args
     context = dict(context)
     for rec in self:
         if rec.partner_id.id and len(rec.room_lines) != 0:
             context.update({'folioid': rec.id, 'guest': rec.partner_id.id,
                             'room_no': rec.room_lines[0].product_id.name,
                             'hotel': rec.warehouse_id.id})
             self.env.args = cr, uid, misc.frozendict(context)
         else:
             raise except_orm(_('Warning'), _('Please Reserve Any Room.'))
     return {'name': _('Currency Exchange'),
             'res_model': 'currency.exchange',
             'type': 'ir.actions.act_window',
             'view_id': False,
             'view_mode': 'form,tree',
             'view_type': 'form',
             'context': {'default_folio_no': context.get('folioid'),
                         'default_hotel_id': context.get('hotel'),
                         'default_guest_name': context.get('guest'),
                         'default_room_number': context.get('room_no')
                         },
             }
 def setUp(self):
     super(TestPurchaseProcurementJIT, self).setUp()
     self.env.context = frozendict(
         dict(self.env.context, check_product_qty=False))
     self.supplier1 = self.browse_ref(
         'purchase_procurement_just_in_time.supplier1')
     self.product1 = self.browse_ref(
         'purchase_procurement_just_in_time.product1')
     self.product2 = self.browse_ref(
         'purchase_procurement_just_in_time.product2')
     self.product3 = self.browse_ref(
         'purchase_procurement_just_in_time.product3')
     self.supplierinfo1 = self.browse_ref(
         'purchase_procurement_just_in_time.supplierinfo1')
     self.supplierinfo2 = self.browse_ref(
         'purchase_procurement_just_in_time.supplierinfo2')
     self.location_a = self.browse_ref(
         'purchase_procurement_just_in_time.stock_location_a')
     self.location_b = self.browse_ref(
         'purchase_procurement_just_in_time.stock_location_b')
     self.warehouse = self.browse_ref('stock.warehouse0')
     self.unit = self.browse_ref('product.product_uom_unit')
     self.uom_couple = self.browse_ref(
         'purchase_procurement_just_in_time.uom_couple')
     self.uom_four = self.browse_ref(
         'purchase_procurement_just_in_time.uom_four')
     self.cron_stock_scheduler = self.browse_ref(
         'stock_procurement_just_in_time.job_update_scheduler_controller')
     self.cron_stock_scheduler.active = False
     self.env['stock.scheduler.controller'].search([]).write({'done': True})
Exemplo n.º 6
0
    def print_report(self):
        if self._context is None:
            self._context = {}
        if (not self._context.get('label_print') or
                not self._context.get('active_ids') or
                not self.name):
            return False
        datas = {}
        column = (float(210) / float(self.name.width or 1))
        no_row_per_page = int((297-self.name.left_margin -
                               self.name.right_margin) /
                              (self.name.height or 1))

        label_print_obj = self.env['label.print']
        label_print_data = label_print_obj.browse(
            self._context.get('label_print'))

        ids = self.env.context['active_ids']
        rows_usable = int(math.ceil(float(math.ceil(
            self.number_of_labels*len(ids)) / int(column))))
        # dpi in mm
        self.mm2px = self.env.ref('label.paperformat_label').dpi / self.IN2MM
        datas = {
            'rows': int(no_row_per_page),
            'columns': int(column),
            'rows_usable': rows_usable,
            'model': self._context.get('active_model'),
            'ids': ids,
            'padding_top': label_print_data.padding_top,
            'padding_bottom': label_print_data.padding_bottom,
            'padding_left': label_print_data.padding_left,
            'padding_right': label_print_data.padding_right,
            'barcode_width': label_print_data.barcode_width,
            'barcode_height': label_print_data.barcode_height,
        }

        cr, uid, context = self.env.args
        context = dict(context)
        context.update({"label_print_id": self.env.context['label_print'],
                        'datas': datas})
        self.env.args = cr, uid, misc.frozendict(context)

        data = {
            'ids': self.ids,
            'model': 'label.config',
            'form': datas,
        }
        report_obj = self.env['report'].with_context(datas)
        return report_obj.get_action(self, 'label.report_label',
                                     data=data)
Exemplo n.º 7
0
    def print_report(self):
        if self._context is None:
            self._context = {}
        if not self._context.get('label_print') or not self._context.get(
                'active_ids'):
            return False
        total_record = len(self._context.get('active_ids', []))
        datas = {}
        for data in self.browse(self.ids):
            column = float(210) / float(data.name.width or 1)
            total_row = math.ceil(float(total_record) / (column or 1))
            no_row_per_page = int(297 / data.name.height)
            height = 297 / (no_row_per_page or 1)
            datas = {
                'rows': int(total_row),
                'columns': int(column) == 0 and 1 or int(column),
                'model': self._context.get('active_model'),
                'height': str(height * 3.693602694) + "mm",
                'no_row_per_page': no_row_per_page,
                'width': str(float(data.name.width) * 3.693602694) + "mm",
                'image_width': str(data.image_width),
                'image_height': str(data.image_height),
                'barcode_width': data.barcode_width,
                'barcode_height': data.barcode_height,
                'font_size': 10,
                'number_of_copy': data.number_of_copy,
                'top_margin': str(data.name.top_margin) + "mm",
                'bottom_margin': str(data.name.bottom_margin) + "mm",
                'left_margin': str(data.name.left_margin) + "mm",
                'right_margin': str(data.name.right_margin) + "mm",
                'cell_spacing': str(data.name.cell_spacing) + "px",
                'ids': self._context.get('active_ids', [])
            }
        cr, uid, context = self.env.args
        context = dict(context)
        context.update({
            'label_print_id': self._context.get('label_print'),
            'datas': datas
        })
        self.env.args = cr, uid, misc.frozendict(context)

        data = {'ids': self.ids, 'model': 'label.config', 'form': datas}
        return self.env['report'].get_action(self,
                                             'label.report_label',
                                             data=data)
Exemplo n.º 8
0
 def write(self, values):
     cr, uid, context = self.env.args
     context = dict(context)
     for p in self:
         if values.get('state') and (
             not values.get('stage_id') and not
             context.get('stage_updated')
         ):
             if not context.get('change_project_stage_from_status'):
                 context.update(
                     {'change_project_stage_from_status': True}
                 )
                 self.env.args = cr, uid, misc.frozendict(context)
                 # Change the stage corresponding to the new status
                 if p.parent_id and p.parent_id.child_stage_ids:
                     for stage in p.parent_id.child_stage_ids:
                         if stage.project_state == values.get('state'):
                             values.update({'stage_id': stage.id})
     return super(Project, self).write(values)
    def setUp(self):
        super(TestPurchaseScheduler, self).setUp()
        self.env.context = frozendict(
            dict(self.env.context, check_product_qty=False))
        self.company = self.browse_ref('base.main_company')
        self.company.write({'po_lead': 5})
        self.supplier = self.browse_ref(
            'purchase_procurement_just_in_time.supplier1')
        self.supplier2 = self.browse_ref(
            'purchase_procurement_just_in_time.supplier2')
        self.product1 = self.browse_ref(
            'purchase_procurement_just_in_time.product1')
        self.product2 = self.browse_ref(
            'purchase_procurement_just_in_time.product2')
        self.supplierinfo2 = self.browse_ref(
            'purchase_procurement_just_in_time.supplierinfo2')
        self.product_uom = self.browse_ref('product.product_uom_unit')
        self.location_a = self.browse_ref(
            'purchase_procurement_just_in_time.stock_location_a')
        self.location_b = self.browse_ref(
            'purchase_procurement_just_in_time.stock_location_b')
        self.warehouse = self.browse_ref('stock.warehouse0')
        self.frame_week = self.browse_ref(
            'purchase_procurement_just_in_time.week')
        self.loc_supplier = self.browse_ref('stock.stock_location_suppliers')
        self.picking_type_in = self.browse_ref('stock.picking_type_in')
        self.unit = self.browse_ref('product.product_uom_unit')
        self.uom_couple = self.browse_ref(
            'purchase_procurement_just_in_time.uom_couple')
        self.uom_four = self.browse_ref(
            'purchase_procurement_just_in_time.uom_four')
        self.cron_stock_scheduler = self.browse_ref(
            'stock_procurement_just_in_time.job_update_scheduler_controller')
        self.cron_stock_scheduler.active = False
        self.env['stock.scheduler.controller'].search([]).write({'done': True})

        self.prepare_procurements()

        configuration_wizard = self.env['purchase.config.settings']. \
            create({'delta_begin_grouping_period': False, 'ignore_past_procurements': False})
        configuration_wizard.execute()
Exemplo n.º 10
0
    def print_report(self):
        cr, uid, context = self.env.args
        sales_obj = self.env['sale.order']
        sales_ord_line_obj = self.env['sale.order.line']
        partner_obj = self.env['res.partner']
        for wiz in self:
            fl = StringIO()
            wbk = xlwt.Workbook(encoding='utf-8')
            font = xlwt.Font()
            font.bold = True
            header_left = xlwt.easyxf('align: horiz left')
            bold_header_left = xlwt.easyxf("font: bold 1, height 200,"
                                           " color black; align: horiz left")
            header8 = xlwt.easyxf('align: horiz left')
            header_left = xlwt.easyxf('align: horiz left')
            main_header = xlwt.easyxf(
                'font: bold 1, height 360; align: horiz center,vert center')
            header2 = xlwt.easyxf(
                'font: bold 1, height 230; align: horiz center,vert center ;borders :top hair, bottom hair,left hair, right hair, bottom_color black,top_color black'
            )
            header2_left = xlwt.easyxf(
                'font: bold 1, height 230; align: horiz left ;borders :top hair, bottom hair,left hair, right hair, bottom_color black,top_color black'
            )
            rep_name = ''

            st_dt = datetime.strptime(wiz.date_from,
                                      DEFAULT_SERVER_DATE_FORMAT)
            start_dt = datetime.strftime(st_dt, "%Y/%m/%d")
            en_dt = datetime.strptime(wiz.date_to, DEFAULT_SERVER_DATE_FORMAT)
            end_dt = datetime.strftime(en_dt, "%Y/%m/%d")

            if wiz.report_name == 'sales_reg_rep':
                worksheet = wbk.add_sheet('Sales Register Report')
                rep_name = 'Sales Register Report.xls'
                sales_ords = sales_obj.search([('state', '!=', 'draft'),
                                               ('date_order', '>=', start_dt),
                                               ('date_order', '<=', end_dt)])
                invoices = []
                if sales_ords:
                    for sale_ord in sales_ords:
                        if sale_ord.invoice_ids:
                            invoices = [
                                inv for inv in sale_ord.invoice_ids
                                if inv.state != 'draft'
                            ]
                    worksheet.row(0).height = 600
                    worksheet.write_merge(
                        0, 0, 0, 8, 'Sales Register Report ' + ' ( ' +
                        start_dt + ' to ' + end_dt + ' ) ', main_header)
                    col = 0
                    row = 1
                    worksheet.col(col).width = 3000
                    worksheet.write(row, col, 'Sr. No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Date', header2)
                    col += 1
                    worksheet.col(col).width = 6000
                    worksheet.write(row, col, 'Sales Invoice No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Customer PO No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Customer Name', header2)
                    col += 1
                    worksheet.col(col).width = 7000
                    worksheet.write(row, col, 'Amount in Actual Currency',
                                    header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Tax amt', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Amt in SGD', header2)
                    col += 1
                    worksheet.col(col).width = 7000
                    worksheet.write(row, col, 'Tax Amt in SGD', header2)

                    col = 0
                    row += 1
                    seq_no = 1
                    for invoice in invoices:
                        worksheet.write(row, col, seq_no or '', header8)
                        col += 1
                        worksheet.write(row, col, invoice.date_invoice or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, invoice.origin or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, invoice.origin or '',
                                        header8)
                        col += 1
                        worksheet.write(
                            row, col,
                            invoice.partner_id and invoice.partner_id.name
                            or '', header8)
                        col += 1
                        worksheet.write(row, col, invoice.amount_total or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, invoice.amount_tax or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, '', header8)
                        col += 1
                        worksheet.write(row, col, '', header8)
                        col = 0
                        row += 1
                        seq_no += 1
            elif wiz.report_name == 'sales_order_reg_rep':
                worksheet = wbk.add_sheet('Sales Order Register Report')
                rep_name = 'Sales Order Register Report.xls'
                sales_ords = sales_obj.search([('state', '!=', 'draft'),
                                               ('date_order', '>=', start_dt),
                                               ('date_order', '<=', end_dt)])
                if sales_ords:
                    worksheet.row(0).height = 600
                    worksheet.write_merge(
                        0, 0, 0, 8, 'Sales Order Register Report ' + ' ( ' +
                        start_dt + ' to ' + end_dt + ' ) ', main_header)
                    col = 0
                    row = 1
                    worksheet.col(col).width = 3000
                    worksheet.write(row, col, 'Sr. No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Date', header2)
                    col += 1
                    worksheet.col(col).width = 6000
                    worksheet.write(row, col, 'Sales Order No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Customer PO No.', header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Customer Name', header2)
                    col += 1
                    worksheet.col(col).width = 7000
                    worksheet.write(row, col, 'Order Amt in Actual Currency',
                                    header2)
                    col += 1
                    worksheet.col(col).width = 5000
                    worksheet.write(row, col, 'Tax amt', header2)

                    col = 0
                    row += 1
                    seq_no = 1
                    for sale_ord in sales_ords:
                        worksheet.write(row, col, seq_no or '', header8)
                        col += 1
                        worksheet.write(row, col, sale_ord.date_order or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, sale_ord.name or '', header8)
                        col += 1
                        worksheet.write(row, col, '', header8)
                        col += 1
                        worksheet.write(
                            row, col,
                            sale_ord.partner_id and sale_ord.partner_id.name
                            or '', header8)
                        col += 1
                        worksheet.write(row, col, sale_ord.amount_total or '',
                                        header8)
                        col += 1
                        worksheet.write(row, col, sale_ord.amount_tax or '',
                                        header8)
                        col = 0
                        row += 1
                        seq_no += 1

            elif wiz.report_name == 'prod_wise_sales_rep_summary':
                worksheet = wbk.add_sheet('Product-wise Sales Summary')
                rep_name = 'Product-wise Sales Report in Summary.xls'
                partner_ids = wiz.partner_ids
                worksheet.row(0).height = 600
                worksheet.col(0).width = 7000
                worksheet.col(1).width = 7000
                worksheet.col(2).width = 7000
                worksheet.col(3).width = 5000
                worksheet.col(4).width = 7000
                worksheet.write_merge(
                    0, 0, 0, 4, 'Product-wise Sales Report in Summary' +
                    ' ( ' + start_dt + ' to ' + end_dt + ' ) ', main_header)
                if not wiz.partner_ids:
                    partner_ids = partner_obj.search([('customer', '=', True)])
                row = 1
                for partner in partner_ids:
                    sales_ords = sales_obj.search([
                        ('partner_id', '=', partner.id),
                        ('state', '!=', 'draft'),
                        ('date_order', '>=', start_dt),
                        ('date_order', '<=', end_dt)
                    ])
                    if sales_ords:
                        col = 0
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Customer Name',
                                        header2_left)
                        col += 1
                        worksheet.write(row, col, partner.name or '',
                                        header_left)

                        col = 0
                        row += 1
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Product Name', header2_left)
                        col += 1
                        worksheet.col(col).width = 5000
                        worksheet.write(row, col, 'Qty', header2)
                        col += 1
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Amt in Actual Currency',
                                        header2)
                        col += 1
                        worksheet.col(col).width = 5000
                        worksheet.write(row, col, 'Amt in SGD', header2)

                        col = 0
                        row += 1
                        for sale_ord in sales_ords:
                            for sale_ord_l in sale_ord.order_line:
                                worksheet.write(
                                    row, col, sale_ord_l.product_id
                                    and sale_ord_l.product_id.name or '',
                                    header_left)
                                col += 1
                                worksheet.write(
                                    row, col, sale_ord_l.product_uom_qty or '',
                                    header8)
                                col += 1
                                worksheet.write(
                                    row, col, sale_ord_l.price_subtotal or '',
                                    header8)
                                col += 1
                                worksheet.write(row, col, '', header8)
                                col = 0
                                row += 1
                        row += 1
            elif wiz.report_name == 'prod_wise_sales_rep_detail':
                worksheet = wbk.add_sheet('Product-wise Sales Detail')
                rep_name = 'Product-wise Sales Report in Detail.xls'
                partner_ids = wiz.partner_ids
                worksheet.row(0).height = 600
                worksheet.col(0).width = 7000
                worksheet.col(1).width = 7000
                worksheet.col(2).width = 7000
                worksheet.col(3).width = 5000
                worksheet.col(4).width = 7000
                worksheet.write_merge(
                    0, 0, 0, 5, 'Product-wise Sales Report in Detail' + ' ( ' +
                    start_dt + ' to ' + end_dt + ' ) ', main_header)
                if not wiz.partner_ids:
                    partner_ids = partner_obj.search([('customer', '=', True)])
                row = 1
                for partner in partner_ids:
                    sales_ords = sales_obj.search([
                        ('partner_id', '=', partner.id),
                        ('state', '!=', 'draft'),
                        ('date_order', '>=', start_dt),
                        ('date_order', '<=', end_dt)
                    ])
                    if sales_ords:
                        col = 0
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Customer Name',
                                        header2_left)
                        col += 1
                        worksheet.write(row, col, partner.name or '',
                                        header_left)
                        col += 1
                        worksheet.write(row, col, 'Customer Code',
                                        header2_left)
                        col += 1
                        worksheet.write(row, col, '', header_left)

                        col = 0
                        row += 1
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Product Name', header2_left)
                        col += 1
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Date', header2)
                        col += 1
                        worksheet.col(col).width = 5000
                        worksheet.write(row, col, 'Quantity', header2)
                        col += 1
                        worksheet.col(col).width = 7000
                        worksheet.write(row, col, 'Amt in Actual Currency',
                                        header2)
                        col += 1
                        worksheet.col(col).width = 5000
                        worksheet.write(row, col, 'Amt in SGD', header2)
                        col += 1
                        worksheet.col(col).width = 5000
                        worksheet.write(row, col, 'Tax Amt in SGD', header2)

                        col = 0
                        row += 1
                        for sale_ord in sales_ords:
                            for sale_ord_l in sale_ord.order_line:
                                worksheet.write(
                                    row, col, sale_ord_l.product_id
                                    and sale_ord_l.product_id.name or '',
                                    header_left)
                                col += 1
                                worksheet.write(row, col, sale_ord.date_order
                                                or '', header8)
                                col += 1
                                worksheet.write(
                                    row, col, sale_ord_l.product_uom_qty or '',
                                    header8)
                                col += 1
                                worksheet.write(
                                    row, col, sale_ord_l.price_subtotal or '',
                                    header8)
                                col += 1
                                worksheet.write(row, col, '', header8)
                                col += 1
                                worksheet.write(row, col, '', header8)
                                col = 0
                                row += 1
                        row += 1
            wbk.save(fl)
            fl.seek(0)
            buf = base64.encodestring(fl.read())
            vals = {'file': buf, 'report_name': rep_name}
            cr, uid, context = self.env.args
            ctx = dict(context)
            ctx.update(vals)
            self.env.args = cr, uid, misc.frozendict(ctx)
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'wiz.galaxy.sales.report.detail',
            'target': 'new',
            'context': ctx
        }
Exemplo n.º 11
0
    def print_report(self):
        emp_obj = self.env['hr.employee']
        bed_obj = self.env['beds.beds']
        emps = emp_obj.search(
            [('accommodated', '=', True),
             ('last_date', '>=', self.start_month.date_start),
             ('last_date', '<=', self.end_month.date_stop)],
            order='last_date')
        month_list = []
        check_months = []
        for emp in emps:
            ctr = 1
            emp_last_date = datetime.strptime(emp.last_date,
                                              DEFAULT_SERVER_DATE_FORMAT)
            month = emp_last_date.strftime('%B-%Y')
            bed = bed_obj.search([('employee_id', '=', emp.id)])
            if bed:
                emp_dict = {
                    'sr':
                    ctr or '',
                    'emp_id':
                    emp.identification_id or '',
                    'name':
                    emp.name or '',
                    'wp_number':
                    emp.wp_number or '',
                    'company':
                    emp.company_id and emp.company_id.code or '',
                    'dialect':
                    emp.dialect or '',
                    'site':
                    emp.worker_location_id and emp.worker_location_id.name
                    or '',
                    'app_date':
                    emp.app_date or '',
                    'last_date':
                    emp.last_date or '',
                    'accommodation':
                    bed.room_id and bed.room_id.accommodation_id
                    and bed.room_id.accommodation_id.name or '',
                    'print_emp':
                    True,
                }
                ctr += 1

                if month_list:
                    check_months = [m for m, dict2 in month_list]
                    month_index_dict = dict([(m2, month_list.index(
                        (m2, dict2))) for m2, dict2 in month_list])
                if month.upper() in check_months:
                    month_list[month_index_dict[month.upper()]][1].append(
                        emp_dict)
                else:
                    month_list.append((month.upper(), [emp_dict]))

        fl = StringIO()
        workbook = xlwt.Workbook()
        worksheet = workbook.add_sheet('Sheet 1')
        font = xlwt.Font()
        font.bold = True
        for_left = xlwt.easyxf("font: color black; align: horiz left")
        for_center_bold = xlwt.easyxf(
            "font: bold 1, color black; align: horiz center")
        #         for_center = xlwt.easyxf("font: bold 1, color black; align: horiz center; pattern: fore_colour red;")

        GREEN_TABLE_HEADER = xlwt.easyxf(
            'font: bold 1, name Tahoma, height 250;'
            'align: vertical center, horizontal center, wrap on;'
            #                  'borders: left thin, right thin, top thin, bottom thin;'
            'borders: top double, bottom double, left double, right double;'
            'pattern: pattern solid, pattern_fore_colour white, pattern_back_colour white'
        )

        BLACK_MONTH_HEADER = xlwt.easyxf(
            'font: bold 1, color white, name Tahoma, height 160;'
            'align: vertical center, horizontal center, wrap on;'
            'borders: left thin, right thin, top thin, bottom thin;'
            'pattern: pattern solid, pattern_fore_colour black, pattern_back_colour black'
        )

        alignment = xlwt.Alignment()  # Create Alignment
        alignment.horz = xlwt.Alignment.HORZ_RIGHT
        style = xlwt.easyxf('align: wrap yes')
        style.num_format_str = '0.00'

        worksheet.row(0).height = 320
        worksheet.col(0).width = 4000
        worksheet.col(1).width = 4000
        worksheet.col(2).width = 4000
        worksheet.col(3).width = 4000
        worksheet.col(4).width = 4000
        worksheet.col(5).width = 4000
        worksheet.col(6).width = 6000
        worksheet.col(7).width = 4000
        worksheet.col(8).width = 4000
        borders = xlwt.Borders()
        borders.bottom = xlwt.Borders.MEDIUM
        border_style = xlwt.XFStyle()  # Create Style
        border_style.borders = borders

        worksheet.write_merge(0, 0, 0, 8, 'RESIGNED WORKERS',
                              GREEN_TABLE_HEADER)
        worksheet.write(1, 0, 'CODE NO', for_center_bold)
        worksheet.write(1, 1, 'NAME', for_center_bold)
        worksheet.write(1, 2, 'W/P NUMBER', for_center_bold)
        worksheet.write(1, 3, 'COM', for_center_bold)
        worksheet.write(1, 4, 'DIALECT', for_center_bold)
        worksheet.write(1, 5, 'SITE', for_center_bold)
        worksheet.write(1, 6, 'DATE OF APPLICATION', for_center_bold)
        worksheet.write(1, 7, 'DEPARTURE DT', for_center_bold)
        worksheet.write(1, 8, 'ACCOM', for_center_bold)
        if month_list:
            row = 2
            col1 = 0
            col = 8
            for month, month_data in month_list:
                worksheet.write_merge(row, row, col1, col, month,
                                      BLACK_MONTH_HEADER)
                if month_data:
                    row = row + 1
                    for month_dict in month_data:
                        worksheet.write(row, 0, month_dict.get('emp_id'),
                                        for_left)
                        worksheet.write(row, 1, month_dict.get('name'),
                                        for_left)
                        worksheet.write(row, 2, month_dict.get('wp_number'),
                                        for_left)
                        worksheet.write(row, 3, month_dict.get('company'),
                                        for_left)
                        worksheet.write(row, 4, month_dict.get('dialect'),
                                        for_left)
                        worksheet.write(row, 5, month_dict.get('site'),
                                        for_left)
                        worksheet.write(row, 6, month_dict.get('app_date'),
                                        for_left)
                        worksheet.write(row, 7, month_dict.get('last_date'),
                                        for_left)
                        worksheet.write(row, 8,
                                        month_dict.get('accommodation'),
                                        for_left)
                        #                         worksheet.write(row, 9, month_dict.get('print_emp',''), for_left)
                        row = row + 1

        workbook.save(fl)
        fl.seek(0)

        buf = base64.encodestring(fl.read())
        cr, uid, context = self.env.args
        ctx = dict(context)
        ctx.update({'file': buf})
        self.env.args = cr, uid, misc.frozendict(context)

        #         datas = {
        #             'ids' : [],
        #             'model' : 'acc.report.resigned.emp',
        #             'form': month_list,
        #             }
        #         return {'type': 'ir.actions.report.xml',
        #                 'report_name': 'acc.report.resigned.emp.doc',
        #                 'datas': datas
        #                 }
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'acc.report.resigned.emp.standard.export',
            'target': 'new',
            'context': ctx,
        }
Exemplo n.º 12
0
 def setUp(self):
     super(TestPurchaseGroupByPeriod, self).setUp()
     self.env.context = frozendict(
         dict(self.env.context, check_product_qty=False))
Exemplo n.º 13
0
    def print_report(self):
        cr, uid, context = self.env.args
        if context is None:
            context = {}
        context = dict(context)
        fl = StringIO()
        wbk = xlwt.Workbook(encoding='utf-8')
        sheet = wbk.add_sheet('Accommodation Report', cell_overwrite_ok=True)
        count_style = xlwt.easyxf(
            'font: bold 1,height 200; borders: top double, bottom double, right double,left double, bottom_color black;align: wrap off , horiz center;'
        )
        font_style_bold = xlwt.easyxf(
            'font: bold 1,height 200;align: wrap off , horiz left;')
        font_style_center_only = xlwt.easyxf(
            'font: height 200;align: wrap off , horiz center;')
        border_style = xlwt.easyxf(
            'font: height 200; borders: right double,left double, bottom_color black;align: wrap off , horiz center;'
        )
        color_style_title = xlwt.easyxf(
            'font: bold 1,height 300, bold on, name Arial, colour_index black;borders : top double, bottom double, right double,left double, bottom_color black; pattern: pattern solid, fore_colour coral; align: wrap on,vert centre, horiz left;align: wrap off , horiz center;'
        )
        color_style2 = xlwt.easyxf(
            'font: bold 1,height 200, bold on, name Arial, colour_index black;borders : top double, bottom double, right double,left double, bottom_color black; pattern: pattern solid, fore_colour ice_blue; align: wrap on,vert centre, horiz left;align: wrap off , horiz center;'
        )
        color_style_total = xlwt.easyxf(
            'font: bold 1,height 220, bold on, name Arial, colour_index black;borders : top double, bottom double, right double,left double, bottom_color black; pattern: pattern solid, fore_colour coral; align: wrap on,vert centre, horiz left;align: wrap off , horiz center;'
        )
        sheet.row(0).height = 800
        sheet.col(0).width = 10000
        sheet.col(1).width = 5000
        sheet.col(2).width = 6000
        sheet.col(3).width = 11000
        today_date = datetime.today().strftime('%d %B %Y')
        today = " VACANCIES OF ACCOMMODATION (AS OF " + today_date + ")"
        sheet.write_merge(0, 0, 0, 3, today, color_style_title)
        sheet.write(1, 0, 'LOCATION', color_style2)
        sheet.write(1, 1, 'ROOM NO.', color_style2)
        sheet.write(1, 2, 'NO.OF VACANCY', color_style2)
        sheet.write(1, 3, 'NATIONALITY', color_style2)
        #        context.update({'report': 'Accommodation Report'})

        hist_obj = self.env['accommodation.history']
        acc_obj = self.env['accommodation.accommodation']

        for wiz_rec in self:
            date = wiz_rec.date
            accom_ids = acc_obj.search([])
            total_vacancy = 0.0
            row = 2
            for accom in acc_obj.browse(
                [accom_id.id for accom_id in accom_ids]):
                sheet.write(row, 0, accom.name, font_style_bold)
                for room in accom.room_ids:
                    sheet.write(row, 1, room.name, border_style)
                    for vis in room.visa_quota_ids:
                        his_args = [
                            ('country_id', '=', vis.nationality_id.id),
                            ('room_id', '=', room.id),
                            ('date', '<=', date + " 23:59:59"),
                        ]
                        his_args_occupied = his_args + [('type', '=', 'occupy')
                                                        ]
                        hist_ids_occupied = hist_obj.search(his_args_occupied)
                        his_args_vacant = his_args + [('type', '=', 'vacant')]
                        hist_ids_vacant = hist_obj.search(his_args_vacant)
                        no_of_vac = vis.number_of_quota - len(
                            hist_ids_occupied) + len(hist_ids_vacant)
                        sheet.write(row, 2, no_of_vac, border_style)
                        total_vacancy += no_of_vac
                        sheet.write(row, 3, vis.nationality_id.name,
                                    border_style)
                        row += 1
        sheet.write(row, 0, "TOTAL", color_style_total)
        sheet.write(row, 1, "", color_style_total)
        sheet.write(row, 2, total_vacancy, color_style_total)
        sheet.write(row, 3, " ", color_style_total)
        wbk.save(fl)
        fl.seek(0)
        buf = base64.encodestring(fl.read())
        ctx = dict(context)
        ctx.update({'file': buf})
        self.env.args = cr, uid, misc.frozendict(context)
        try:
            form_id = self.env['ir.model.data'].get_object_reference(
                'accommodation', 'wiz_dwnld_acc_report_form_dt')[1]
        except ValueError:
            form_id = False
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'accom.dwnld.datewise.report',
            'views': [(form_id, 'form')],
            'view_id': form_id,
            'target': 'new',
            'context': ctx,
        }