示例#1
0
 def _get_move_display_name(self, show_ref=False):
     """Add amount_untaxed in name_get of invoices"""
     name = super()._get_move_display_name(show_ref=show_ref)
     if self.env.context.get("invoice_show_amount"):
         name += _(" Amount w/o tax: %s") % format_amount(
             self.env, self.amount_untaxed, self.currency_id)
     return name
示例#2
0
    def _qweb_render_context(self, record):
        """Compute variables to render Qweb templates.

        Some vars are added to ease porting of Jinja templates.
        """
        res = {
            "object": record,
            "email_template": self,
        }
        ctx = dict(self.env.context)
        if record._name == "mail.message":
            partner_model = self.env["res.partner"]  # pragma: no cover
            # These variables are usually loaded when the notification is sent.
            # It normally happens on `partner._notify` call,
            # hence - due to the call here - is going to happen twice.
            # Nevertheless there are some important values
            # that can be mandatory for your templates
            # especially if you load them
            # from the mail composer. In this case
            # the template will be rendered but it will miss many params.
            # NOTE: some keys related to partner-specific permissions
            # such as `actions` or `button_follow` won't be available
            # until the final rendering happens.
            # Check the variable `recipient_template_values`
            # that comes from `_message_notification_recipients`
            # in `partner._notify`.
            ctx.update(partner_model._notify_prepare_template_context(
                record))  # pragma: no cover
        res.update({
            # Same as for Jinja rendering,
            # taken from `mail_template.render_template`.
            # These ease porting of old Jinja templates to qweb ones.
            # fmt: off
            "format_date":
            lambda date, format=False, context=self._context: format_date(
                self.env, date, format),
            "format_tz":
            lambda dt, tz=False, format=False, context=self._context:
            format_datetime(self.env, dt, tz, format),
            "format_amount":
            lambda amount, currency, context=self._context: format_amount(
                self.env, amount, currency),
            # fmt: on
            "user":
            self.env.user,
            # keep it for Jinja template compatibility
            "ctx":
            ctx,
        })
        # Alias `record` to be always the main record needed by the template.
        # Imagine a template for sale.order: when you load it in the composer
        # the current `object` is the SO you are looking at,
        # BUT when you send the message, the `object` is the message
        # and not the SO anymore.
        # Hence, stick the main record to `record` to make templates robust.
        res["record"] = ctx.get("record", record)
        res["record_name"] = ctx.get("record_name", record.display_name)
        return res
示例#3
0
 def check_existing_invoice(self):
     assert self.invoice_id
     # should not happen because domain blocks that
     if self.invoice_id.currency_id != self.company_currency_id:
         raise UserError(
             _("For the moment, we don't support linking to an invoice "
               "in another currency than the company currency."))
     # should not happen because domain blocks that
     if self.invoice_id.payment_state != 'not_paid':
         raise UserError(
             _("The transaction %s is linked to invoice %s "
               "which is not in unpaid state.") %
             (self.name, self.invoice_id.number))
     # should not happen because domain blocks that
     if self.invoice_id.move_type not in ('in_invoice', 'in_refund'):
         raise UserError(
             _("The transaction %s is linked to invoice %s "
               "which is not a supplier invoice/refund!") %
             (self.name, self.invoice_id.name))
     # handled by onchange
     if self.partner_id != self.invoice_id.commercial_partner_id:
         raise UserError(
             _("The transaction %s is linked to partner '%s' "
               "whereas the related invoice %s is linked to "
               "partner '%s'.") %
             (self.name, self.partner_id.display_name,
              self.invoice_id.display_name,
              self.invoice_id.commercial_partner_id.display_name))
     # TODO handle partial payments ?
     if float_compare(self.invoice_id.amount_total_signed,
                      self.total_company_currency,
                      precision_rounding=self.company_currency_id.rounding):
         raise UserError(
             _("The transaction %s is linked to the "
               "invoice/refund %s whose total amount is %s, "
               "but the amount of the transaction is %s.") % (
                   self.name,
                   self.invoice_id.name,
                   format_amount(self.env,
                                 self.invoice_id.amount_total_signed * -1,
                                 self.invoice_id.currency_id),
                   format_amount(self.env, self.total_company_currency,
                                 self.company_currency_id),
               ))
示例#4
0
 def _get_value_label(self, value):
     self.ensure_one()
     symbol_position = self.currency_id.position
     symbol = self.currency_id.symbol
     int_value = int(round(value))
     # if value is an integer
     if self.currency_id.compare_amounts(value, int_value) == 0:
         amount_label = str(int_value)
         if symbol_position == "before":
             value_label = "%s %s" % (symbol, amount_label)
         else:
             value_label = "%s %s" % (amount_label, symbol)
     else:
         value_label = format_amount(self.env, value, self.currency_id)
     return value_label
 def _vat_on_payment(self, in_or_out, vat_account_ids, speedy):
     account2logs = super()._vat_on_payment(in_or_out, vat_account_ids,
                                            speedy)
     if in_or_out == 'in' and self.company_id.vat_prorata:
         # make sure VAT prorata already exists for that period
         prorata = self.env['account.vat.prorata'].search(
             [('company_id', '=', speedy['company_id']),
              ('date_to', '=', self.end_date)],
             limit=1)
         if not prorata:
             raise UserError(
                 _("There is no VAT prorata in company '{company}' "
                   "for the period that ends on {end_date}.").format(
                       company=self.company_id.display_name,
                       end_date=format_date(self.env, self.end_date)))
         if prorata and prorata.state != 'done':
             raise UserError(
                 _("You must finish the VAT prorata process in company "
                   "'{company}' for the period that ends on {end_date} "
                   "before doing the VAT return for the same period.").
                 format(company=self.company_id.display_name,
                        end_date=format_date(self.env, self.end_date)))
         perct_prec = self.env['decimal.precision'].precision_get(
             'VAT Pro Rata Ratio')
         ratio = float_round(prorata.used_perct,
                             precision_digits=perct_prec)
         assert float_compare(ratio, 100, precision_digits=perct_prec) <= 0
         assert float_compare(ratio, 0, precision_digits=perct_prec) >= 0
         if float_compare(ratio, 100, precision_digits=perct_prec) < 0:
             for account, logs in account2logs.items():
                 for log in logs:
                     log['amount'] *= ratio / 100
                     log['note'] += _(" => VAT prorata ratio {ratio} % "
                                      "VAT amount: {vat_amount}").format(
                                          ratio=ratio,
                                          vat_amount=format_amount(
                                              self.env, log['amount'],
                                              speedy["currency"]))
     return account2logs
示例#6
0
       agreement.sale_count = mapped_data.get(agreement.id, 0)

from odoo.tools.misc import formatLang
# CAUTION: it is not the same method as in the report ! It is only for numbers, not dates.
Proto: formatLang(env, value, digits=None, grouping=True, monetary=False, dp=False, currency_obj=False)
price_unit_formatted = formatLang(
    self.with_context(lang=lang).env, self.price_unit, currency_obj=self.company_id.currency_id)
qty_formatted = formatLang(
    self.with_context(lang=lang).env, self.qty_done, dp='Product Unit of Measure')

Proto: format_date(env, value, lang_code=False, date_format=False)
'%s' % format_date(self.env, self.date)
# format_datetime is v13+ only
format_datetime(env, value, tz=False, dt_format='medium', lang_code=False)
'%s' % format_datetime(self.env, self.datetime_field)
format_amount(env, amount, currency, lang_code=False)
'%s' % format_amount(self.env, 12.42, invoice.currency_id)


self.env['ir.config_parameter'].sudo().get_param('webkit_path', default='default_path')
# WARNING: It the value of the param is True or False, get_param() will return
# 'True' or 'False' as strings !

account_recordset = self.env['ir.property'].get('property_account_payable_id', 'res.partner')


# v14+ test intrastat country :
if country in self.env.ref('base.europe').country_ids

# v15 translation
raise UserError(_("partner {partner_name} in company {company_name}").format(partner_name=partner_name, company_name=company_name))