# Part of Odoo. See LICENSE file for full copyright and licensing details. import re from markupsafe import Markup import werkzeug from odoo import api, fields, Command, models, _ from odoo.exceptions import UserError, ValidationError from odoo.tools import email_split, float_repr, float_round, is_html_empty class HrExpense(models.Model): _name = "hr.expense" _inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'analytic.mixin'] _description = "Expense" _order = "date desc, id desc" _check_company_auto = True @api.model def _default_employee_id(self): employee = self.env.user.employee_id if not employee and not self.env.user.has_group('hr_expense.group_hr_expense_team_approver'): raise ValidationError(_('The current user has no related employee. Please, create one.')) return employee name = fields.Char( string="Description", compute='_compute_name', precompute=True, store=True, readonly=False, required=True, copy=True, ) date = fields.Date(string="Expense Date", default=fields.Date.context_today) employee_id = fields.Many2one( comodel_name='hr.employee', string="Employee", compute='_compute_employee_id', precompute=True, store=True, readonly=False, required=True, default=_default_employee_id, check_company=True, domain=[('filter_for_expense', '=', True)], tracking=True, ) company_id = fields.Many2one( comodel_name='res.company', string="Company", required=True, readonly=True, default=lambda self: self.env.company, ) # product_id is not required to allow to create an expense without product via mail alias, but should be required on the view. product_id = fields.Many2one( comodel_name='product.product', string="Category", tracking=True, check_company=True, domain=[('can_be_expensed', '=', True)], ondelete='restrict', ) product_description = fields.Html(compute='_compute_product_description') product_uom_id = fields.Many2one( comodel_name='uom.uom', string="Unit of Measure", compute='_compute_uom_id', precompute=True, store=True, domain="[('category_id', '=', product_uom_category_id)]", copy=True, ) product_uom_category_id = fields.Many2one( comodel_name='uom.category', string="UoM Category", related='product_id.uom_id.category_id', readonly=True, ) product_has_cost = fields.Boolean(compute='_compute_from_product') # Whether the product has a cost (standard_price) or not product_has_tax = fields.Boolean(string="Whether tax is defined on a selected product", compute='_compute_from_product') quantity = fields.Float(required=True, digits='Product Unit of Measure', default=1) description = fields.Text(string="Internal Notes") message_main_attachment_checksum = fields.Char(related='message_main_attachment_id.checksum') nb_attachment = fields.Integer(string="Number of Attachments", compute='_compute_nb_attachment') attachment_ids = fields.One2many( comodel_name='ir.attachment', inverse_name='res_id', domain=[('res_model', '=', 'hr.expense')], string="Attachments", ) state = fields.Selection( selection=[ ('draft', 'To Report'), ('reported', 'To Submit'), ('submitted', 'Submitted'), ('approved', 'Approved'), ('done', 'Done'), ('refused', 'Refused') ], string="Status", compute='_compute_state', store=True, readonly=True, index=True, copy=False, default='draft', ) sheet_id = fields.Many2one( comodel_name='hr.expense.sheet', string="Expense Report", domain="[('employee_id', '=', employee_id), ('company_id', '=', company_id)]", readonly=True, copy=False, index=True, ) approved_by = fields.Many2one(comodel_name='res.users', string="Approved By", related='sheet_id.user_id', tracking=False) approved_on = fields.Datetime(string="Approved On", related='sheet_id.approval_date') duplicate_expense_ids = fields.Many2many(comodel_name='hr.expense', compute='_compute_duplicate_expense_ids') # Used to trigger warnings same_receipt_expense_ids = fields.Many2many(comodel_name='hr.expense', compute='_compute_same_receipt_expense_ids') # Used to trigger warnings # Amount fields tax_amount_currency = fields.Monetary( string="Tax amount in Currency", currency_field='currency_id', compute='_compute_tax_amount_currency', precompute=True, store=True, help="Tax amount in currency", ) tax_amount = fields.Monetary( string="Tax amount", currency_field='company_currency_id', compute='_compute_tax_amount', precompute=True, store=True, help="Tax amount in company currency", ) total_amount_currency = fields.Monetary( string="Total In Currency", currency_field='currency_id', compute='_compute_total_amount_currency', precompute=True, store=True, readonly=False, tracking=True, ) untaxed_amount_currency = fields.Monetary( string="Total Untaxed Amount In Currency", currency_field='currency_id', compute='_compute_tax_amount_currency', precompute=True, store=True, ) total_amount = fields.Monetary( string="Total", currency_field='company_currency_id', compute='_compute_total_amount', inverse='_inverse_total_amount', precompute=True, store=True, readonly=False, tracking=True, ) price_unit = fields.Float( string="Unit Price", compute='_compute_price_unit', precompute=True, store=True, required=True, readonly=True, copy=True, digits='Product Price', ) currency_id = fields.Many2one( comodel_name='res.currency', string="Currency", compute='_compute_currency_id', precompute=True, store=True, readonly=False, required=True, default=lambda self: self.env.company.currency_id, ) company_currency_id = fields.Many2one( comodel_name='res.currency', related='company_id.currency_id', string="Report Company Currency", readonly=True, ) is_multiple_currency = fields.Boolean( string="Is currency_id different from the company_currency_id", compute='_compute_is_multiple_currency', ) currency_rate = fields.Float(compute='_compute_currency_rate', digits=(16, 9), readonly=True, tracking=True) label_currency_rate = fields.Char(compute='_compute_currency_rate', readonly=True) # Account fields payment_mode = fields.Selection( selection=[ ('own_account', "Employee (to reimburse)"), ('company_account', "Company") ], string="Paid By", default='own_account', required=True, tracking=True, ) vendor_id = fields.Many2one(comodel_name='res.partner', string="Vendor") account_id = fields.Many2one( comodel_name='account.account', string="Account", compute='_compute_account_id', precompute=True, store=True, readonly=False, check_company=True, domain="[('account_type', 'not in', ('asset_receivable', 'liability_payable', 'asset_cash', 'liability_credit_card'))]", help="An expense account is expected", ) tax_ids = fields.Many2many( comodel_name='account.tax', relation='expense_tax', column1='expense_id', column2='tax_id', string="Included taxes", compute='_compute_tax_ids', precompute=True, store=True, readonly=False, domain="[('type_tax_use', '=', 'purchase')]", check_company=True, help="Both price-included and price-excluded taxes will behave as price-included taxes for expenses.", ) accounting_date = fields.Date( # The date used for the accounting entries or the one we'd like to use if not yet posted related='sheet_id.accounting_date', string="Accounting Date", store=True, groups='account.group_account_invoice,account.group_account_readonly', ) # Security fields is_editable = fields.Boolean(string="Is Editable By Current User", compute='_compute_is_editable') @api.depends('product_has_cost') def _compute_currency_id(self): for expense in self: if expense.product_has_cost and expense.state in {'draft', 'reported'}: expense.currency_id = expense.company_currency_id @api.depends('sheet_id.is_editable') def _compute_is_editable(self): for expense in self: if expense.sheet_id: expense.is_editable = expense.sheet_id.is_editable else: expense.is_editable = True @api.onchange('product_has_cost') def _onchange_product_has_cost(self): """ Reset quantity to 1, in case of 0-cost product. To make sure switching non-0-cost to 0-cost doesn't keep the quantity.""" if not self.product_has_cost and self.state in {'draft', 'reported'}: self.quantity = 1 @api.depends_context('lang') @api.depends('product_id') def _compute_product_description(self): for expense in self: expense.product_description = not is_html_empty(expense.product_id.description) and expense.product_id.description @api.depends('product_id') def _compute_name(self): for expense in self: expense.name = expense.name or expense.product_id.display_name def _set_expense_currency_rate(self, date_today): for expense in self: expense.currency_rate = expense.env['res.currency']._get_conversion_rate( from_currency=expense.currency_id, to_currency=expense.company_currency_id, company=expense.company_id, date=expense.date or date_today, ) @api.depends('currency_id', 'total_amount_currency', 'date') def _compute_currency_rate(self): """ We want the default odoo rate when the following change: - the currency of the expense - the total amount in foreign currency - the date of the expense this will cause the rate to be recomputed twice with possible changes but we don't have the required fields to store the override state in stable """ date_today = fields.Date.context_today(self) for expense in self: if expense.is_multiple_currency: if ( expense.currency_id != expense._origin.currency_id or expense.total_amount_currency != expense._origin.total_amount_currency or expense.date != expense._origin.date ): expense._set_expense_currency_rate(date_today=date_today) else: expense.currency_rate = expense.total_amount / expense.total_amount_currency if expense.total_amount_currency else 1.0 else: # Mono-currency case computation shortcut, no need for the label if there is no conversion expense.currency_rate = 1.0 expense.label_currency_rate = False continue expense.label_currency_rate = _( '1 %(exp_cur)s = %(rate)s %(comp_cur)s', exp_cur=expense.currency_id.name, rate=float_repr(expense.currency_rate, 6), comp_cur=expense.company_currency_id.name, ) @api.depends('currency_id', 'company_currency_id') def _compute_is_multiple_currency(self): for expense in self: expense.is_multiple_currency = expense.currency_id != expense.company_currency_id @api.depends('product_id') def _compute_from_product(self): for expense in self: expense.product_has_cost = expense.product_id and not expense.company_currency_id.is_zero(expense.product_id.standard_price) expense.product_has_tax = bool(expense.product_id.supplier_taxes_id.filtered_domain(self.env['account.tax']._check_company_domain(expense.company_id))) @api.depends('product_id.uom_id') def _compute_uom_id(self): for expense in self: expense.product_uom_id = expense.product_id.uom_id @api.depends('sheet_id', 'sheet_id.account_move_ids', 'sheet_id.state') def _compute_state(self): for expense in self: if not expense.sheet_id: expense.state = 'draft' elif expense.sheet_id.state == 'draft': expense.state = 'reported' elif expense.sheet_id.state == 'cancel': expense.state = 'refused' elif expense.sheet_id.state in {'approve', 'post'}: expense.state = 'approved' elif not expense.sheet_id.account_move_ids: expense.state = 'submitted' else: expense.state = 'done' @api.depends('quantity', 'price_unit', 'tax_ids') def _compute_total_amount_currency(self): AccountTax = self.env['account.tax'] for expense in self.filtered('product_has_cost'): base_line = expense._prepare_base_line_for_taxes_computation(price_unit=expense.price_unit, quantity=expense.quantity) AccountTax._add_tax_details_in_base_line(base_line, expense.company_id) AccountTax._round_base_lines_tax_details([base_line], expense.company_id) expense.total_amount_currency = base_line['tax_details']['total_included_currency'] @api.onchange('total_amount_currency') def _inverse_total_amount_currency(self): for expense in self: if not expense.is_editable: raise UserError(_('You are not authorized to edit this expense.')) expense.price_unit = (expense.total_amount / expense.quantity) if expense.quantity != 0 else 0. @api.depends( 'date', 'company_id', 'currency_id', 'company_currency_id', 'is_multiple_currency', 'total_amount_currency', 'product_id', 'employee_id.user_id.partner_id', 'quantity', ) def _compute_total_amount(self): AccountTax = self.env['account.tax'] for expense in self: if expense.is_multiple_currency: base_line = expense._prepare_base_line_for_taxes_computation( price_unit=expense.total_amount_currency * expense.currency_rate, quantity=1.0, currency_id=expense.company_currency_id, rate=1.0, ) AccountTax._add_tax_details_in_base_line(base_line, expense.company_id) AccountTax._round_base_lines_tax_details([base_line], expense.company_id) expense.total_amount = base_line['tax_details']['total_included_currency'] else: # Mono-currency case computation shortcut expense.total_amount = expense.total_amount_currency def _inverse_total_amount(self): """ Allows to set a custom rate on the expense, and avoid the override when it makes no sense """ AccountTax = self.env['account.tax'] for expense in self: if expense.is_multiple_currency: base_line = expense._prepare_base_line_for_taxes_computation( price_unit=expense.total_amount, quantity=1.0, currency=expense.company_currency_id, ) AccountTax._add_tax_details_in_base_line(base_line, expense.company_id) AccountTax._round_base_lines_tax_details([base_line], expense.company_id) tax_details = base_line['tax_details'] expense.tax_amount = tax_details['total_included_currency'] - tax_details['total_excluded_currency'] else: expense.total_amount_currency = expense.total_amount expense.tax_amount = expense.tax_amount_currency expense.currency_rate = expense.total_amount / expense.total_amount_currency if expense.total_amount_currency else 1.0 expense.price_unit = expense.total_amount / expense.quantity if expense.quantity else expense.total_amount @api.depends('product_id', 'company_id') def _compute_tax_ids(self): for _expense in self: expense = _expense.with_company(_expense.company_id) # taxes only from the same company expense.tax_ids = expense.product_id.supplier_taxes_id.filtered_domain(self.env['account.tax']._check_company_domain(expense.company_id)) @api.depends('total_amount_currency', 'tax_ids') def _compute_tax_amount_currency(self): """ Note: as total_amount_currency can be set directly by the user (for product without cost) or needs to be computed (for product with cost), `untaxed_amount_currency` can't be computed in the same method as `total_amount_currency`. """ AccountTax = self.env['account.tax'] for expense in self: base_line = expense._prepare_base_line_for_taxes_computation( price_unit=expense.total_amount_currency, quantity=1.0, ) AccountTax._add_tax_details_in_base_line(base_line, expense.company_id) AccountTax._round_base_lines_tax_details([base_line], expense.company_id) tax_details = base_line['tax_details'] expense.tax_amount_currency = tax_details['total_included_currency'] - tax_details['total_excluded_currency'] expense.untaxed_amount_currency = tax_details['total_excluded_currency'] @api.depends('total_amount', 'currency_rate', 'tax_ids', 'is_multiple_currency') def _compute_tax_amount(self): """ Note: as total_amount can be set directly by the user when the currency_rate is overriden, the tax must be computed after the total_amount. """ AccountTax = self.env['account.tax'] for expense in self: if expense.is_multiple_currency: base_line = expense._prepare_base_line_for_taxes_computation( price_unit=expense.total_amount, quantity=1.0, currency=expense.company_currency_id, ) AccountTax._add_tax_details_in_base_line(base_line, expense.company_id) AccountTax._round_base_lines_tax_details([base_line], expense.company_id) tax_details = base_line['tax_details'] expense.tax_amount = tax_details['total_included_currency'] - tax_details['total_excluded_currency'] else: # Mono-currency case computation shortcut expense.tax_amount = expense.tax_amount_currency @api.depends('total_amount', 'total_amount_currency') def _compute_price_unit(self): """ The price_unit is the unit price of the product if no product is set and no attachment overrides it. Otherwise it is always computed from the total_amount and the quantity else it would break the vendor bill when edited after creation. """ for expense in self: if expense.state not in {'draft', 'reported'}: continue product_id = expense.product_id if expense._needs_product_price_computation(): expense.price_unit = product_id._price_compute( 'standard_price', uom=expense.product_uom_id, company=expense.company_id, )[product_id.id] else: expense.price_unit = expense.company_currency_id.round(expense.total_amount / expense.quantity) if expense.quantity else 0. def _needs_product_price_computation(self): # Hook to be overridden. self.ensure_one() return self.product_has_cost @api.depends('product_id', 'company_id') def _compute_account_id(self): property_field = self.env['product.category']._fields['property_account_expense_categ_id'] for _expense in self: expense = _expense.with_company(_expense.company_id) if not expense.product_id: expense.account_id = property_field.get_company_dependent_fallback(self.env['product.category']) continue account = expense.product_id.product_tmpl_id._get_product_accounts()['expense'] if account: expense.account_id = account @api.depends('company_id') def _compute_employee_id(self): if not self.env.context.get('default_employee_id'): for expense in self: expense.employee_id = self.env.user.with_company(expense.company_id).employee_id @api.depends('attachment_ids') def _compute_same_receipt_expense_ids(self): self.same_receipt_expense_ids = [Command.clear()] expenses_with_attachments = self.filtered(lambda expense: expense.attachment_ids) if not expenses_with_attachments: return expenses_groupby_checksum = dict(self.env['ir.attachment']._read_group(domain=[ ('res_model', '=', 'hr.expense'), ('checksum', 'in', expenses_with_attachments.attachment_ids.mapped('checksum'))], groupby=['checksum'], aggregates=['res_id:array_agg'], )) for expense in expenses_with_attachments: same_receipt_ids = set() for attachment in expense.attachment_ids: same_receipt_ids.update(expenses_groupby_checksum[attachment.checksum]) same_receipt_ids.remove(expense.id) expense.same_receipt_expense_ids = [Command.set(list(same_receipt_ids))] @api.depends('employee_id', 'product_id', 'total_amount_currency') def _compute_duplicate_expense_ids(self): self.duplicate_expense_ids = [Command.clear()] expenses = self.filtered(lambda expense: expense.employee_id and expense.product_id and expense.total_amount_currency) if expenses.ids: duplicates_query = """ SELECT ARRAY_AGG(DISTINCT he.id) FROM hr_expense AS he JOIN hr_expense AS ex ON he.employee_id = ex.employee_id AND he.product_id = ex.product_id AND he.date = ex.date AND he.total_amount_currency = ex.total_amount_currency AND he.company_id = ex.company_id AND he.currency_id = ex.currency_id WHERE ex.id in %(expense_ids)s GROUP BY he.employee_id, he.product_id, he.date, he.total_amount_currency, he.company_id, he.currency_id HAVING COUNT(he.id) > 1 """ self.env.cr.execute(duplicates_query, {'expense_ids': tuple(expenses.ids)}) for duplicates_ids in (x[0] for x in self.env.cr.fetchall()): expenses_duplicates = expenses.filtered(lambda expense: expense.id in duplicates_ids) expenses_duplicates.duplicate_expense_ids = [Command.set(duplicates_ids)] expenses = expenses - expenses_duplicates @api.depends('product_id', 'account_id', 'employee_id') def _compute_analytic_distribution(self): for expense in self: distribution = self.env['account.analytic.distribution.model']._get_distribution({ 'product_id': expense.product_id.id, 'product_categ_id': expense.product_id.categ_id.id, 'partner_id': expense.employee_id.work_contact_id.id, 'partner_category_id': expense.employee_id.work_contact_id.category_id.ids, 'account_prefix': expense.account_id.code, 'company_id': expense.company_id.id, }) expense.analytic_distribution = distribution or expense.analytic_distribution def _compute_nb_attachment(self): attachment_data = self.env['ir.attachment']._read_group( [('res_model', '=', 'hr.expense'), ('res_id', 'in', self.ids)], ['res_id'], ['__count'], ) attachment = dict(attachment_data) for expense in self: expense.nb_attachment = attachment.get(expense._origin.id, 0) @api.constrains('payment_mode') def _check_payment_mode(self): self.sheet_id._check_payment_mode() def _prepare_base_line_for_taxes_computation(self, **kwargs): self.ensure_one() return self.env['account.tax']._prepare_base_line_for_taxes_computation( self, **{ 'partner_id': self.vendor_id, 'special_mode': 'total_included', 'rate': self.currency_rate, **kwargs, }, ) def attach_document(self, **kwargs): """When an attachment is uploaded as a receipt, set it as the main attachment.""" self._message_set_main_attachment_id(self.env["ir.attachment"].browse(kwargs['attachment_ids'][-1:]), force=True) @api.model def create_expense_from_attachments(self, attachment_ids=None, view_type='list'): """ Create the expenses from files. :return: An action redirecting to hr.expense list view. """ if not attachment_ids: raise UserError(_("No attachment was provided")) attachments = self.env['ir.attachment'].browse(attachment_ids) expenses = self.env['hr.expense'] if any(attachment.res_id or attachment.res_model != 'hr.expense' for attachment in attachments): raise UserError(_("Invalid attachments!")) product = self.env['product.product'].search([('can_be_expensed', '=', True)]) if product: product = product.filtered(lambda p: p.default_code == "EXP_GEN")[:1] or product[0] else: raise UserError(_("You need to have at least one category that can be expensed in your database to proceed!")) for attachment in attachments: attachment_name = '.'.join(attachment.name.split('.')[:-1]) vals = { 'name': attachment_name, 'price_unit': 0, 'product_id': product.id, } if product.property_account_expense_id: vals['account_id'] = product.property_account_expense_id.id expense = self.env['hr.expense'].create(vals) attachment.write({'res_model': 'hr.expense', 'res_id': expense.id}) expense._message_set_main_attachment_id(attachment, force=True) expenses += expense return { 'name': _('Generate Expenses'), 'res_model': 'hr.expense', 'type': 'ir.actions.act_window', 'views': [[False, view_type], [False, "form"]], 'domain': [('id', 'in', expenses.ids)], 'context': self.env.context, } # ---------------------------------------- # ORM Overrides # ---------------------------------------- @api.ondelete(at_uninstall=False) def _unlink_except_posted_or_approved(self): for expense in self: if expense.state in {'done', 'approved'}: raise UserError(_('You cannot delete a posted or approved expense.')) def write(self, vals): expense_to_previous_sheet = {} if 'sheet_id' in vals: # Check access rights on the sheet self.env['hr.expense.sheet'].browse(vals['sheet_id']).check_access('write') # Store the previous sheet of the expenses to unlink the attachments later if needed for expense in self: expense_to_previous_sheet[expense] = expense.sheet_id # If the sheet_id is modified, we need to check that the expenses are not set to 0, # unless it's to unlink the sheet enforced_non_zero_expenses = self.env['hr.expense'] if vals.get('sheet_id'): # If sheet is linked, we need to check all the newly linked expenses in self enforced_non_zero_expenses = self else: # If sheet_id is not modified, we need to check all the expenses in self linked to a sheet enforced_non_zero_expenses = self.filtered('sheet_id') if 'tax_ids' in vals or 'analytic_distribution' in vals or 'account_id' in vals: if any(not expense.is_editable for expense in self): raise UserError(_('You are not authorized to edit this expense report.')) if enforced_non_zero_expenses: enforced_non_zero_expenses.check_amount_not_zero(vals) res = super().write(vals) if 'currency_id' in vals: self._set_expense_currency_rate(date_today=fields.Date.context_today(self)) for expense in self: expense.total_amount = expense.total_amount_currency * expense.currency_rate if 'employee_id' in vals: # In case expense has sheet which has only one expense_line_ids, # then changing the expense.employee_id triggers changing the sheet.employee_id too. # Otherwise we unlink the expense line from sheet, (so that the user can create a new report). if self.sheet_id: employees = self.sheet_id.expense_line_ids.mapped('employee_id') if len(employees) == 1: self.sheet_id.write({'employee_id': vals['employee_id']}) elif len(employees) > 1: self.sheet_id = False if 'sheet_id' in vals: # The sheet_id has been modified, either by an explicit write on sheet_id of the expense, # or by processing a command on the sheet's expense_line_ids. # We need to delete the attachments on the previous sheet coming from the expenses that were modified, # and copy the attachments of the expenses to the new sheet, # if it's a no-op (writing same sheet_id as the current sheet_id of the expense), # nothing should be done (no unlink then copy of the same attachments) attachments_to_unlink = self.env['ir.attachment'] for expense in self: previous_sheet = expense_to_previous_sheet[expense] checksums = set((expense.attachment_ids - previous_sheet.expense_line_ids.attachment_ids).mapped('checksum')) attachments_to_unlink += previous_sheet.attachment_ids.filtered(lambda att: att.checksum in checksums) if vals['sheet_id'] and expense.sheet_id != previous_sheet: for attachment in expense.attachment_ids.with_context(sync_attachment=False): attachment.copy({ 'res_model': 'hr.expense.sheet', 'res_id': vals['sheet_id'], }) attachments_to_unlink.with_context(sync_attachment=False).unlink() return res @api.model_create_multi def create(self, vals_list): expenses = super().create(vals_list) if self.env.context.get('check_total_amount_not_zero'): for expense, vals in zip(expenses, vals_list): expense.check_amount_not_zero(vals) return expenses def unlink(self): attachments_to_unlink = self.env['ir.attachment'] for sheet in self.sheet_id: checksums = set((sheet.expense_line_ids.attachment_ids & self.attachment_ids).mapped('checksum')) attachments_to_unlink += sheet.attachment_ids.filtered(lambda att: att.checksum in checksums) attachments_to_unlink.with_context(sync_attachment=False).unlink() return super().unlink() @api.model def get_empty_list_help(self, help_message): return super().get_empty_list_help((help_message or '') + self._get_empty_list_mail_alias()) @api.model def _get_empty_list_mail_alias(self): use_mailgateway = self.env['ir.config_parameter'].sudo().get_param('hr_expense.use_mailgateway') expense_alias = self.env.ref('hr_expense.mail_alias_expense') if use_mailgateway else False if expense_alias and expense_alias.alias_domain and expense_alias.alias_name: # encode, but force %20 encoding for space instead of a + (URL / mailto difference) params = werkzeug.urls.url_encode({'subject': _("Lunch with customer $12.32")}).replace('+', '%20') return Markup( """