예제 #1
0
 def try_round(amount, expected):
     digits = max(0, -int(log10(currency.rounding)))
     result = float_repr(currency.round(amount),
                         precision_digits=digits)
     self.assertEqual(
         result, expected,
         'Rounding error: got %s, expected %s' % (result, expected))
예제 #2
0
 def try_round(amount, expected, digits=3, method='HALF-UP'):
     value = float_round(amount,
                         precision_digits=digits,
                         rounding_method=method)
     result = float_repr(value, precision_digits=digits)
     self.assertEqual(
         result, expected,
         'Rounding error: got %s, expected %s' % (result, expected))
예제 #3
0
    def infos(self, user_id=None):
        self._check_user_impersonification(user_id)
        user = request.env['res.users'].browse(
            user_id) if user_id else request.env.user

        infos = self._make_infos(user, order=False)

        lines = self._get_current_lines(user.id)
        if lines:
            lines = [
                {
                    'id':
                    line.id,
                    'product':
                    (line.product_id.id, line.product_id.name,
                     float_repr(float_round(line.product_id.price, 2), 2)),
                    'toppings': [(topping.name,
                                  float_repr(float_round(topping.price, 2), 2))
                                 for topping in line.topping_ids_1
                                 | line.topping_ids_2 | line.topping_ids_3],
                    'quantity':
                    line.quantity,
                    'price':
                    line.price,
                    'state':
                    line.state,  # Only used for _get_state
                    'note':
                    line.note
                } for line in lines
            ]
            raw_state, state = self._get_state(lines)
            infos.update({
                'total':
                float_repr(
                    float_round(sum(line['price'] for line in lines), 2), 2),
                'raw_state':
                raw_state,
                'state':
                state,
                'lines':
                lines,
            })
        return infos
예제 #4
0
    def _get_pricelist_item_name_price(self):
        for item in self:
            if item.categ_id and item.applied_on == '2_product_category':
                item.name = _("Category: %s") % (item.categ_id.display_name)
            elif item.product_tmpl_id and item.applied_on == '1_product':
                item.name = _("Product: %s") % (
                    item.product_tmpl_id.display_name)
            elif item.product_id and item.applied_on == '0_product_variant':
                item.name = _("Variant: %s") % (item.product_id.with_context(
                    display_default_code=False).display_name)
            else:
                item.name = _("All Products")

            if item.compute_price == 'fixed':
                decimal_places = self.env['decimal.precision'].precision_get(
                    'Product Price')
                if item.currency_id.position == 'after':
                    item.price = "%s %s" % (
                        float_repr(
                            item.fixed_price,
                            decimal_places,
                        ),
                        item.currency_id.symbol,
                    )
                else:
                    item.price = "%s %s" % (
                        item.currency_id.symbol,
                        float_repr(
                            item.fixed_price,
                            decimal_places,
                        ),
                    )
            elif item.compute_price == 'percentage':
                item.price = _("%s %% discount") % (item.percent_price)
            else:
                item.price = _("%s %% discount and %s surcharge") % (
                    item.price_discount, item.price_surcharge)
예제 #5
0
 def format_monetary(number, currency):
     # Format the monetary values to avoid trailing decimals (e.g. 90.85000000000001).
     return float_repr(number, currency.decimal_places)