Ejemplo n.º 1
0
	def renew_contract(self):
		"""
			This Button Method is used to Renew Tenancy.
		@param self: The object pointer
		@return: Dictionary of values.
		"""
		cr, uid, context = self.env.args
		context = dict(context)
		if context is None:
			context = {}
		modid = self.env['ir.model.data'].get_object_reference('realestate', 'property_analytic_view_form')
		if context.get('active_ids', []):
			for rec in self:
				start_d = datetime.strptime(rec.start_date, DEFAULT_SERVER_DATE_FORMAT).date()
				end_d = datetime.strptime(rec.end_date, DEFAULT_SERVER_DATE_FORMAT).date()
				if start_d > end_d:
					raise Warning(_('Please Insert End Date Greater Than Start Date'))
				act_prop = self.env['account.analytic.account'].browse(context['active_ids'])
				act_prop.write({
						'date_start' : rec.start_date,
						'date' : rec.end_date,
						'rent_type_id' : rec.rent_type_id and rec.rent_type_id.id or False,
						'state':'draft',
						'rent_entry_chck':False,
						})
		self.env.args = cr, uid, misc.frozendict(context)
		return {
			'view_mode': 'form',
			'view_id': modid[1],
			'view_type': 'form',
			'res_model': 'account.analytic.account',
			'type': 'ir.actions.act_window',
			'target': 'current',
			'res_id': context['active_ids'][0],
			}
Ejemplo n.º 2
0
 def go_to_currency_exchange(self):
     '''
      when Money Exchange button is clicked then this method is called.
     -------------------------------------------------------------------
     @param self: object pointer
     '''
     ctx = dict(self._context)
     for rec in self:
         if rec.partner_id.id and len(rec.room_lines) != 0:
             ctx.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 = misc.frozendict(ctx)
         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': ctx.get('folioid'),
             'default_hotel_id': ctx.get('hotel'),
             'default_guest_name': ctx.get('guest'),
             'default_room_number': ctx.get('room_no')
         },
     }
Ejemplo n.º 3
0
 def add_part_on_work_order(self):
     work_order_obj = self.env['fleet.vehicle.log.services']
     parts_used_obj = self.env["task.line"]
     for rec_main in self:
         for rec in rec_main.part_ids:
             vals = {}
             if self._context.get('active_id', False):
                 vals.update(
                     {'fleet_service_id': self._context['active_id']})
                 if rec.product_id:
                     vals.update({'product_id': rec.product_id.id})
                 if rec.name:
                     vals.update({'name': rec.name})
                 if rec.vehicle_make_id:
                     vals.update(
                         {'vehicle_make_id': rec.vehicle_make_id.id})
                 if rec.qty:
                     vals.update({'qty': rec.qty})
                 vals.update({'encoded_qty': rec.encoded_qty})
                 vals.update({'qty_hand': rec.qty_hand})
                 if rec.product_uom:
                     vals.update({'product_uom': rec.product_uom.id})
                 if rec.price_unit:
                     vals.update({'price_unit': rec.price_unit})
                 if rec.date_issued:
                     vals.update({'date_issued': rec.date_issued})
                 if rec.old_part_return:
                     vals.update({'old_part_return': rec.old_part_return})
                 parts_used_obj.create(vals)
     if self._context.get('active_id', False):
         for work_order in work_order_obj.browse(
             [self._context.get('active_id')]):
             if work_order.parts_ids:
                 work_order.write({'is_parts': True})
             if not work_order.parts_ids:
                 work_order.write({'is_parts': False})
             if not work_order.team_trip_id:
                 work_order.close_reopened_wo()
             elif work_order.team_trip_id:
                 cr, uid, context = self.env.args
                 context = dict(context)
                 context.update({
                     'team_trip': work_order.team_trip_id.id,
                     'workorder': work_order.id
                 })
                 work_order.encode_history()
                 self.env.args = cr, uid, misc.frozendict(context)
                 for part_rec in work_order.parts_ids:
                     trip_encoded_ids = \
                         self.env['trip.encoded.history'].search(
                             [('team_id', '=', work_order.team_trip_id.id),
                              ('product_id', '=', part_rec.product_id and
                               part_rec.product_id.id or False)])
                     if trip_encoded_ids:
                         encoded_qty = \
                             trip_encoded_ids[0].encoded_qty + part_rec.qty
                         trip_encoded_ids[0].write(
                             {'encoded_qty': encoded_qty})
     return True
    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', []))
        paperformat_height = self.paperformat_id.page_height or 297
        paperformat_width = self.paperformat_id.page_width or 210
        datas = {}
        for data in self.browse(self.ids):
            column = float(paperformat_width) / float(data.name.width or 1)
            total_row = math.ceil(float(total_record) / (column or 1))
            if self.single_page:
                no_row_per_page = 1
            else:
                no_row_per_page = int(paperformat_height / data.name.height)
            height = paperformat_height / (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}

        action = self.env['report'].get_action(self,
                                               'label.report_label',
                                               data=data)
        if self.paperformat_id:
            action['context']['paperformat_id'] = self.paperformat_id.id

        return action
Ejemplo n.º 5
0
 def save_part_on_work_order(self):
     work_order_obj = self.env['fleet.vehicle.log.services']
     cr, uid, context = self.env.args
     context = dict(context)
     if context.get('active_id', False):
         for work_order in work_order_obj.browse([context['active_id']]):
             if not work_order.parts_ids:
                 work_order.write({'is_parts': False})
             if work_order.parts_ids:
                 work_order.write({'is_parts': True})
             if not work_order.team_trip_id:
                 work_order.close_reopened_wo()
             elif work_order.team_trip_id:
                 trip_encoded_obj = self.env['trip.encoded.history']
                 trip_encoded_temp_obj = \
                     self.env['trip.encoded.history.temp']
                 context.update({
                     'team_trip': work_order.team_trip_id.id,
                     'workorder': work_order.id
                 })
                 work_order.encode_history()
                 self.env.args = cr, uid, misc.frozendict(context)
                 for part_rec in work_order.parts_ids:
                     trip_encoded_ids = trip_encoded_obj.search([
                         ('team_id', '=', work_order.team_trip_id.id),
                         ('product_id', '=', part_rec.product_id.id)
                     ])
                     trip_encoded_temp_ids = \
                         trip_encoded_temp_obj.search([
                             ('team_id', '=', work_order.team_trip_id.id),
                             ('product_id', '=', part_rec.product_id.id),
                             ('work_order_id', '=', work_order.id)])
                     part_used_qty = 0.0
                     if trip_encoded_temp_ids:
                         part_used_qty = trip_encoded_temp_ids[0].used_qty
                     if trip_encoded_ids:
                         encoded_qty = \
                             trip_encoded_ids[0].encoded_qty - \
                             part_used_qty + part_rec.qty
                         trip_encoded_ids[0].write(
                             {'encoded_qty': encoded_qty})
     return True
Ejemplo n.º 6
0
    def edit_status_book(self):
        """
			This method will open a wizard.
		@param self: The object pointer
		"""
        cr, uid, context = self.env.args
        context = dict(context)
        for rec in self:
            context.update({'edit_result': rec.id})
            self.env.args = cr, uid, misc.frozendict(context)
        return {
            'name': ('wizard'),
            'res_model': 'book.available',
            'type': 'ir.actions.act_window',
            'view_id': False,
            'view_mode': 'form',
            'view_type': 'form',
            'target': 'new',
            'context': {
                'default_current_ids': context.get('edit_result')
            },
        }
Ejemplo n.º 7
0
def MockRequest(
    env,
    *,
    path='/mockrequest',
    routing=True,
    multilang=True,
    context=frozendict(),
    cookies=frozendict(),
    country_code=None,
    website=None,
    remote_addr=HOST,
    environ_base=None,
    # website_sale
    sale_order_id=None,
    website_sale_current_pl=None,
):

    lang_code = context.get('lang', env.context.get('lang', 'en_US'))
    env = env(context=dict(context, lang=lang_code))
    request = Mock(
        # request
        httprequest=Mock(
            host='localhost',
            path=path,
            app=odoo.http.root,
            environ=dict(
                EnvironBuilder(
                    path=path,
                    base_url=HttpCase.base_url(),
                    environ_base=environ_base,
                ).get_environ(),
                REMOTE_ADDR=remote_addr,
            ),
            cookies=cookies,
            referrer='',
            remote_addr=remote_addr,
        ),
        type='http',
        future_response=odoo.http.FutureResponse(),
        params={},
        redirect=env['ir.http']._redirect,
        session=DotDict(
            odoo.http.DEFAULT_SESSION,
            geoip={'country_code': country_code},
            sale_order_id=sale_order_id,
            website_sale_current_pl=website_sale_current_pl,
        ),
        geoip={},
        db=None,
        env=env,
        registry=env.registry,
        cr=env.cr,
        uid=env.uid,
        context=env.context,
        lang=env['res.lang']._lang_get(lang_code),
        website=website,
    )
    if website:
        request.website_routing = website.id

    # The following code mocks match() to return a fake rule with a fake
    # 'routing' attribute (routing=True) or to raise a NotFound
    # exception (routing=False).
    #
    #   router = odoo.http.root.get_db_router()
    #   rule, args = router.bind(...).match(path)
    #   # arg routing is True => rule.endpoint.routing == {...}
    #   # arg routing is False => NotFound exception
    router = MagicMock()
    match = router.return_value.bind.return_value.match
    if routing:
        match.return_value[0].routing = {
            'type': 'http',
            'website': True,
            'multilang': multilang
        }
    else:
        match.side_effect = NotFound

    with contextlib.ExitStack() as s:
        odoo.http._request_stack.push(request)
        s.callback(odoo.http._request_stack.pop)
        s.enter_context(patch('odoo.http.root.get_db_router', router))

        yield request
Ejemplo n.º 8
0
    def download_template(self, row_values=None, error_reason=None, error_value=None):
        fl = BytesIO()
        workbook = xlwt.Workbook()
        worksheet = workbook.add_sheet(self.ir_model.name)
        bold = xlwt.easyxf('font: bold 1;')
        main_header = xlwt.easyxf(
            'font: bold 1, height 270; align: horiz center,vert center ,wrap 1;borders :top hair, bottom hair,left hair, right hair, bottom_color black,top_color black')
        label_header = xlwt.easyxf(
            'font: bold 1, height 230; align: horiz center,vert center ,wrap 1;borders :top hair, bottom hair,left hair, right hair, bottom_color black,top_color black')

        if self.ir_model:
            col = 1
            count = -1
            row_12 = 12
            row_13 = 13
            row_14 = 14
            row_15 = 15
            row_16 = 16
            row_17 = 17

            worksheet.row(0).height = 500
            worksheet.col(0).width = 6200
            worksheet.col(1).width = 9500
            worksheet.col(2).width = 9500
            worksheet.col(3).width = 9500
            worksheet.col(4).width = 9500
            worksheet.write_merge(0, 0, 0, 4, 'Data Import Template', main_header)
            worksheet.write_merge(1, 1, 0, 4, '')
            worksheet.write_merge(2, 2, 0, 4, '')
            worksheet.write_merge(3, 3, 0, 2, 'Notes:', bold)
            worksheet.write_merge(
                4, 4, 0, 2, 'Please do not change the template headings.')
            worksheet.write_merge(
                5, 5, 0, 2, 'First data column must be blank.')
            worksheet.write_merge(
                6, 6, 0, 2, 'If you are uploading new records, "Naming Series" becomes mandatory, if present.')
            worksheet.write_merge(
                7, 7, 0, 2, 'Only mandatory fields are necessary for new records. You can keep non-mandatory columns blank if you wish.')
            worksheet.write_merge(
                8, 8, 0, 2, 'For updating, you can update only selective columns.')
            worksheet.write_merge(
                9, 9, 0, 2, 'You can only upload upto 5000 records in one go. (may be less in some cases)')

            worksheet.write_merge(3, 3, 3, 4, 'Data Import Notes:', bold)
            worksheet.write_merge(4, 4, 3, 4, '')
            worksheet.write_merge(
                5, 5, 3, 4, 'Many2one: You can enter "NAME" of the relational model!')
            worksheet.write_merge(
                6, 6, 3, 4, 'Many2many: You can enter "NAME" of the relational model Seprate by ";"')
            worksheet.write_merge(7, 7, 3, 4, 'One2many: Let this blank! & Download Blank Template for displayed comodel to Import!')
            worksheet.write_merge(8, 8, 3, 4, '')
            worksheet.write_merge(9, 9, 3, 4, '')
            worksheet.write_merge(10, 10, 3, 4, '')

            worksheet.write(row_12, 0, 'DocType:', bold)
            worksheet.write(row_12, 1, self.ir_model.name)
            worksheet.write(row_13, 0, 'Column Name:', bold)
            worksheet.write(row_14, 0, 'Type:', bold)
            worksheet.write(row_15, 0, 'Mandatory:', bold)
            worksheet.write(row_16, 0, 'Column Labels:', bold)
            worksheet.write(row_17, 0, 'Start entering data this line', bold)

            if not self.fields_list_ids and not error_value:
                raise UserError(
                    _("Fields should not be blank!"))

            if self.fields_list_ids:
                for line in self.fields_list_ids:
                    count += 1
                    worksheet.col(count + 1).width = 9900
                    worksheet.write(row_13, col, line.name)
                    worksheet.write(row_14, col, line.ttype + ' ' +
                                    'Relation: ' + str(line.relation) + '')
                    # Check for delegated field!
                    delegated = False
                    data = 'No'
                    if line.ttype == 'many2one' and line.relation in [
                            x.model for x in self.ir_model.inherited_model_ids]\
                            and not line.related or line.ttype == 'one2many':
                        delegated = True
                    # Check for all fields and its required attribute!
                    if line.required and not delegated:
                        data = 'Yes'
                    worksheet.write(row_15, col, str(data))
                    worksheet.write(row_16, col, line.field_description, label_header)
                    col += 1

            elif row_values and error_value:
                for line in row_values:
                    count += 1
                    worksheet.col(count + 1).width = 9900
                    if count == 13:
                        i = line.index("Column Name:")
                        del line[i]
                        for data in line:
                            worksheet.write(row_13, col, data)
                            col += 1
                        col = 1
                    elif count == 14:
                        i = line.index("Type:")
                        del line[i]
                        for data in line:
                            worksheet.write(row_14, col, data)
                            col += 1
                        col = 1

                    elif count == 15:
                        i = line.index("Mandatory:")
                        del line[i]
                        for data in line:
                            worksheet.write(row_15, col, str(data))
                            col += 1
                        col = 1

                    elif count == 16:
                        i = line.index("Column Labels:")
                        del line[i]
                        for data in line:
                            worksheet.write(row_16, col, data, label_header)
                            col += 1
                        worksheet.write(row_16, col, "REASONS: (NOT CREATED RECORD)", label_header)
                        col += 1
                        col = 1

                    elif count == 17:
                        for each_error in error_value:
                            del each_error[0]
                            reason = set(each_error) & set(error_reason)
                            for value in each_error:
                                worksheet.write(row_17, col, str(value))
                                col += 1
                            worksheet.write(row_17, col, (str(reason) + ': Value not found in Database! Please create it first. once create value in database. remove (REASON) column for IMPORT!'))
                            col += 1
                            row_17 += 1
                            col = 1

        workbook.save(fl)
        fl.seek(0)
        buf = base64.encodestring(fl.read())
        ctx = dict(self._context)
        vals = {'file': buf}
        ctx.update(vals)
        self.env.args = self._cr, self._uid, misc.frozendict(ctx)
        file_id = self.env['wiz.template.file'].create({
            'file': buf,
            'name': self.ir_model.name + '.xls'
        })

        return {
            'res_id': file_id.id,
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'wiz.template.file',
            'context': ctx,
            'target': 'new'
        }
Ejemplo n.º 9
0
    def print_report(self):
        if self._context is None:
            self._context = {}
        label_print_id = self._context.get('label_print')
        if not label_print_id or not self._context.get('active_ids'):
            return False
        records = self.line_ids or self.browse(self.ids)
        if not records:
            return False
        label_print = self.env['label.print'].browse(
            self._context.get('label_print'))
        mode = label_print.mode
        record = records[0]
        if self.use_line:
            total_record = len(self.line_ids)
        else:
            total_record = len(self._context.get('active_ids', []))
        if self.use_line:
            wizard = record.wizard_id
            model = self.line_model
            ids = self.line_selected_ids.mapped('src_line_id_int')
        else:
            wizard = record
            model = self._context.get('active_model')
            ids = self._context.get('active_ids', [])
        landscape = wizard.config_id.landscape
        if landscape:
            page_width = 297.0
            page_height = 210.0
        else:
            page_width = 210.0
            page_height = 297.0
        column = page_width / float(wizard.config_id.width or 1)
        total_row = math.ceil(float(total_record) / (column or 1))
        no_row_per_page = int(page_height / wizard.config_id.height)
        height = int(page_height) / (no_row_per_page or 1)
        ratio = 4.555

        datas = {
            'rows': int(total_row),
            'columns': int(column) == 0 and 1 or int(column),
            'model': model,
            'height': str(int(height * ratio)) + "px",
            #'height': str(height * ratio) + "mm",
            'height_internal': str(int(height * ratio - 2)) + "px",
            #'height': str(int(height * 100.0 / 297)) + "%",
            'no_row_per_page': no_row_per_page,
            #'width': str(int(wizard.config_id.width * 100.0 / 210)) + "%",
            #'width': str(wizard.config_id.width * ratio) + "mm",
            'width': str(int(wizard.config_id.width * ratio)) + "px",
            'width_internal':
            str(int(wizard.config_id.width * ratio - 2)) + "px",
            'image_width': str(wizard.image_width),
            'image_height': str(wizard.image_height),
            'barcode_width': wizard.barcode_width,
            'barcode_height': wizard.barcode_height,
            'font_size': 10,
            'number_of_copy': wizard.number_of_copy,
            'top_margin': str(wizard.config_id.top_margin) + "mm",
            'bottom_margin': str(wizard.config_id.bottom_margin) + "mm",
            'left_margin': str(wizard.config_id.left_margin) + "mm",
            'right_margin': str(wizard.config_id.right_margin) + "mm",
            'cell_spacing': str(wizard.config_id.cell_spacing) + "px",
            'landscape': landscape,
            'ids': ids,
            'mode': mode,
            'template_css': label_print.template_css_id.xml_id or '',
        }
        if mode == 'template':
            datas['template_name'] = label_print.template_id.xml_id

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

        if self.use_line:
            ids = self.line_selected_ids and self.line_selected_ids.ids or []
            if not ids:
                raise Warning(
                    u"Vous devez sélectionner au moins une ligne pour imprimer des étiquettes"
                )
        else:
            ids = self.ids
        data = {
            'ids': ids,
            'model': 'label.config',
            'form': datas,
            'landscape': landscape,
        }
        report_name = datas[
            'landscape'] and 'of_label.report_label_landscape' or 'of_label.report_label'
        action = self.env['report'].get_action(self, report_name, data=data)
        return action