Пример #1
0
    def _compute_quantities_dict(self, lot_id, owner_id, package_id, from_date=False, to_date=False):
        domain_quant_loc, domain_move_in_loc, domain_move_out_loc = self._get_domain_locations()
        domain_quant = [('product_id', 'in', self.ids)] + domain_quant_loc
        dates_in_the_past = False
        if to_date and to_date < fields.Datetime.now(): #Only to_date as to_date will correspond to qty_available
            dates_in_the_past = True

        domain_move_in = [('product_id', 'in', self.ids)] + domain_move_in_loc
        domain_move_out = [('product_id', 'in', self.ids)] + domain_move_out_loc
        if lot_id is not None:
            domain_quant += [('lot_id', '=', lot_id)]
        if owner_id is not None:
            domain_quant += [('owner_id', '=', owner_id)]
            domain_move_in += [('restrict_partner_id', '=', owner_id)]
            domain_move_out += [('restrict_partner_id', '=', owner_id)]
        if package_id is not None:
            domain_quant += [('package_id', '=', package_id)]
        if dates_in_the_past:
            domain_move_in_done = list(domain_move_in)
            domain_move_out_done = list(domain_move_out)
        if from_date:
            domain_move_in += [('date', '>=', from_date)]
            domain_move_out += [('date', '>=', from_date)]
        if to_date:
            domain_move_in += [('date', '<=', to_date)]
            domain_move_out += [('date', '<=', to_date)]

        Move = self.env['stock.move']
        Quant = self.env['stock.quant']
        domain_move_in_todo = [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_move_in
        domain_move_out_todo = [('state', 'not in', ('done', 'cancel', 'draft'))] + domain_move_out
        moves_in_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_in_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
        moves_out_res = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_out_todo, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
        quants_res = dict((item['product_id'][0], item['quantity']) for item in Quant.read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id'))
        if dates_in_the_past:
            # Calculate the moves that were done before now to calculate back in time (as most questions will be recent ones)
            domain_move_in_done = [('state', '=', 'done'), ('date', '>', to_date)] + domain_move_in_done
            domain_move_out_done = [('state', '=', 'done'), ('date', '>', to_date)] + domain_move_out_done
            moves_in_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_in_done, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
            moves_out_res_past = dict((item['product_id'][0], item['product_qty']) for item in Move.read_group(domain_move_out_done, ['product_id', 'product_qty'], ['product_id'], orderby='id'))

        res = dict()
        for product in self.with_context(prefetch_fields=False):
            product_id = product.id
            rounding = product.uom_id.rounding
            res[product_id] = {}
            if dates_in_the_past:
                qty_available = quants_res.get(product_id, 0.0) - moves_in_res_past.get(product_id, 0.0) + moves_out_res_past.get(product_id, 0.0)
            else:
                qty_available = quants_res.get(product_id, 0.0)
            res[product_id]['qty_available'] = float_round(qty_available, precision_rounding=rounding)
            res[product_id]['incoming_qty'] = float_round(moves_in_res.get(product_id, 0.0), precision_rounding=rounding)
            res[product_id]['outgoing_qty'] = float_round(moves_out_res.get(product_id, 0.0), precision_rounding=rounding)
            res[product_id]['virtual_available'] = float_round(
                qty_available + res[product_id]['incoming_qty'] - res[product_id]['outgoing_qty'],
                precision_rounding=rounding)

        return res
Пример #2
0
 def _compute_duration_display(self):
     for allocation in self:
         allocation.duration_display = '%g %s' % (
             (float_round(allocation.number_of_hours_display,
                          precision_digits=2)
              if allocation.type_request_unit == 'hour' else float_round(
                  allocation.number_of_days_display, precision_digits=2)),
             _('hours')
             if allocation.type_request_unit == 'hour' else _('days'))
Пример #3
0
 def trans_rec_get(self):
     context = self._context or {}
     credit = debit = 0
     lines = self.env['account.move.line'].browse(context.get('active_ids', []))
     for line in lines:
         if line.amount_residual < 0.0:
             credit += abs(line.amount_residual)
         elif line.amount_residual > 0.0:
             debit += line.amount_residual
     precision = self.env.user.company_id.currency_id.decimal_places
     writeoff = float_round(debit - credit, precision_digits=precision) + 0.0 #remove -0.0 result
     credit = float_round(credit, precision_digits=precision)
     debit = float_round(debit, precision_digits=precision)
     return {'trans_nbr': len(lines), 'credit': credit, 'debit': debit, 'writeoff': writeoff}
Пример #4
0
    def get_opening_move_differences(self, opening_move_lines):
        currency = self.currency_id
        balancing_move_line = opening_move_lines.filtered(lambda x: x.account_id == self.get_unaffected_earnings_account())

        debits_sum = credits_sum = 0.0
        for line in opening_move_lines:
            if line != balancing_move_line:
                #skip the autobalancing move line
                debits_sum += line.debit
                credits_sum += line.credit

        difference = abs(debits_sum - credits_sum)
        debit_diff = (debits_sum > credits_sum) and float_round(difference, precision_rounding=currency.rounding) or 0.0
        credit_diff = (debits_sum < credits_sum) and float_round(difference, precision_rounding=currency.rounding) or 0.0
        return debit_diff, credit_diff
Пример #5
0
 def _create_stripe_charge(self,
                           acquirer_ref=None,
                           tokenid=None,
                           email=None):
     api_url_charge = 'https://%s/charges' % (
         self.acquirer_id._get_stripe_api_url())
     charge_params = {
         'amount':
         int(self.amount if self.currency_id.name in
             INT_CURRENCIES else float_round(self.amount * 100, 2)),
         'currency':
         self.currency_id.name,
         'metadata[reference]':
         self.reference,
         'description':
         self.reference,
     }
     if acquirer_ref:
         charge_params['customer'] = acquirer_ref
     if tokenid:
         charge_params['card'] = str(tokenid)
     if email:
         charge_params['receipt_email'] = email.strip()
     r = requests.post(api_url_charge,
                       auth=(self.acquirer_id.stripe_secret_key, ''),
                       params=charge_params,
                       headers=STRIPE_HEADERS)
     return r.json()
Пример #6
0
 def _get_price_unit(self):
     """ Returns the unit price for the move"""
     self.ensure_one()
     if self.purchase_line_id and self.product_id.id == self.purchase_line_id.product_id.id:
         price_unit_prec = self.env['decimal.precision'].precision_get(
             'Product Price')
         line = self.purchase_line_id
         order = line.order_id
         price_unit = line.price_unit
         if line.taxes_id:
             qty = line.product_qty or 1
             price_unit = line.taxes_id.with_context(
                 round=False).compute_all(
                     price_unit,
                     currency=line.order_id.currency_id,
                     quantity=qty)['total_void']
             price_unit = float_round(price_unit / qty,
                                      precision_digits=price_unit_prec)
         if line.product_uom.id != line.product_id.uom_id.id:
             price_unit *= line.product_uom.factor / line.product_id.uom_id.factor
         if order.currency_id != order.company_id.currency_id:
             # The date must be today, and not the date of the move since the move move is still
             # in assigned state. However, the move date is the scheduled date until move is
             # done, then date of actual move processing. See:
             # https://github.com/flectra/flectra/blob/2f789b6863407e63f90b3a2d4cc3be09815f7002/addons/stock/models/stock_move.py#L36
             price_unit = order.currency_id._convert(
                 price_unit,
                 order.company_id.currency_id,
                 order.company_id,
                 fields.Date.context_today(self),
                 round=False)
         return price_unit
     return super(StockMove, self)._get_price_unit()
Пример #7
0
 def _set_inventory_quantity(self):
     """ Inverse method to create stock move when `inventory_quantity` is set
     (`inventory_quantity` is only accessible in inventory mode).
     """
     if not self._is_inventory_mode():
         return
     for quant in self:
         # Get the quantity to create a move for.
         rounding = quant.product_id.uom_id.rounding
         diff = float_round(quant.inventory_quantity - quant.quantity,
                            precision_rounding=rounding)
         diff_float_compared = float_compare(diff,
                                             0,
                                             precision_rounding=rounding)
         # Create and vaidate a move so that the quant matches its `inventory_quantity`.
         if diff_float_compared == 0:
             continue
         elif diff_float_compared > 0:
             move_vals = quant._get_inventory_move_values(
                 diff,
                 quant.product_id.with_company(
                     quant.company_id).property_stock_inventory,
                 quant.location_id)
         else:
             move_vals = quant._get_inventory_move_values(
                 -diff,
                 quant.location_id,
                 quant.product_id.with_company(
                     quant.company_id).property_stock_inventory,
                 out=True)
         move = quant.env['stock.move'].with_context(
             inventory_mode=False).create(move_vals)
         move._action_done()
Пример #8
0
    def stripe_form_generate_values(self, tx_values):
        self.ensure_one()
        base_url = self.get_base_url()
        stripe_session_data = {
            "payment_method_types[]":
            "card",
            "line_items[][amount]":
            int(tx_values["amount"] if tx_values["currency"].name in
                INT_CURRENCIES else float_round(tx_values["amount"] * 100, 2)),
            "line_items[][currency]":
            tx_values["currency"].name,
            "line_items[][quantity]":
            1,
            "line_items[][name]":
            tx_values["reference"],
            "client_reference_id":
            tx_values["reference"],
            "payment_intent_data[description]":
            tx_values["reference"],
            "success_url":
            urls.url_join(base_url, StripeController._success_url) +
            "?reference=%s&return_url=%s" %
            (tx_values["reference"], tx_values.get('return_url')),
            "cancel_url":
            urls.url_join(base_url, StripeController._cancel_url) +
            "?reference=%s&return_url=%s" %
            (tx_values["reference"], tx_values.get('return_url')),
            "customer_email":
            tx_values["partner_email"] or tx_values["billing_partner_email"],
        }
        tx_values["session_id"] = self._create_stripe_session(
            stripe_session_data)

        return tx_values
Пример #9
0
 def _compute_mrp_product_qty(self):
     for template in self:
         template.mrp_product_qty = float_round(
             sum(
                 template.mapped('product_variant_ids').mapped(
                     'mrp_product_qty')),
             precision_rounding=template.uom_id.rounding)
Пример #10
0
    def _put_in_pack(self):
        package = False
        for pick in self:
            operations = pick.move_line_ids.filtered(lambda o: o.qty_done > 0 and not o.result_package_id)
            operation_ids = self.env['stock.move.line']
            if operations:
                package = self.env['stock.quant.package'].create({})
                for operation in operations:
                    if float_compare(operation.qty_done, operation.product_uom_qty, precision_rounding=operation.product_uom_id.rounding) >= 0:
                        operation_ids |= operation
                    else:
                        quantity_left_todo = float_round(
                            operation.product_uom_qty - operation.qty_done,
                            precision_rounding=operation.product_uom_id.rounding,
                            rounding_method='UP')
                        done_to_keep = operation.qty_done
                        new_operation = operation.copy(
                            default={'product_uom_qty': 0, 'qty_done': operation.qty_done})
                        operation.write({'product_uom_qty': quantity_left_todo, 'qty_done': 0.0})
                        new_operation.write({'product_uom_qty': done_to_keep})
                        operation_ids |= new_operation

                operation_ids.write({'result_package_id': package.id})
            else:
                raise UserError(_('Please process some quantities to put in the pack first!'))
        return package
Пример #11
0
 def _prepare_mrp_move_data_from_forecast(self, estimate, product_mrp_area,
                                          date):
     mrp_type = 'd'
     origin = 'fc'
     daily_qty = float_round(
         estimate.daily_qty,
         precision_rounding=product_mrp_area.product_id.uom_id.rounding,
         rounding_method='HALF-UP')
     return {
         'mrp_area_id': product_mrp_area.mrp_area_id.id,
         'product_id': product_mrp_area.product_id.id,
         'product_mrp_area_id': product_mrp_area.id,
         'production_id': None,
         'purchase_order_id': None,
         'purchase_line_id': None,
         'stock_move_id': None,
         'mrp_qty': -daily_qty * product_mrp_area.group_estimate_days,
         'current_qty': -daily_qty,
         'mrp_date': date,
         'current_date': date,
         'mrp_type': mrp_type,
         'mrp_origin': origin,
         'mrp_order_number': None,
         'parent_product_id': None,
         'name': 'Forecast',
         'state': 'confirmed',
     }
Пример #12
0
 def _get_stock_move_price_unit(self):
     self.ensure_one()
     line = self[0]
     order = line.order_id
     price_unit = line.price_unit
     price_unit_prec = self.env['decimal.precision'].precision_get(
         'Product Price')
     if line.taxes_id:
         qty = line.product_qty or 1
         price_unit = line.taxes_id.with_context(round=False).compute_all(
             price_unit,
             currency=line.order_id.currency_id,
             quantity=qty,
             product=line.product_id,
             partner=line.order_id.partner_id)['total_void']
         price_unit = float_round(price_unit / qty,
                                  precision_digits=price_unit_prec)
     if line.product_uom.id != line.product_id.uom_id.id:
         price_unit *= line.product_uom.factor / line.product_id.uom_id.factor
     if order.currency_id != order.company_id.currency_id:
         price_unit = order.currency_id._convert(
             price_unit,
             order.company_id.currency_id,
             self.company_id,
             self.date_order or fields.Date.today(),
             round=False)
     return price_unit
Пример #13
0
    def value_to_html(self, value, options):
        if 'decimal_precision' in options:
            precision = self.env['decimal.precision'].search([
                ('name', '=', options['decimal_precision'])
            ]).digits
        else:
            precision = options['precision']

        if precision is None:
            fmt = '%f'
        else:
            value = float_utils.float_round(value, precision_digits=precision)
            fmt = '%.{precision}f'.format(precision=precision)

        formatted = self.user_lang().format(fmt, value, grouping=True).replace(
            r'-', u'-\N{ZERO WIDTH NO-BREAK SPACE}')

        # %f does not strip trailing zeroes. %g does but its precision causes
        # it to switch to scientific notation starting at a million *and* to
        # strip decimals. So use %f and if no precision was specified manually
        # strip trailing 0.
        if precision is None:
            formatted = re.sub(r'(?:(0|\d+?)0+)$', r'\1', formatted)

        return pycompat.to_text(formatted)
Пример #14
0
    def _compute_sales_count(self):
        r = {}
        self.sales_count = 0
        if not self.user_has_groups('sales_team.group_sale_salesman'):
            return r
        date_from = fields.Datetime.to_string(
            fields.datetime.combine(
                fields.datetime.now() - timedelta(days=365), time.min))

        done_states = self.env['sale.report']._get_done_states()

        domain = [
            ('state', 'in', done_states),
            ('product_id', 'in', self.ids),
            ('date', '>=', date_from),
        ]
        for group in self.env['sale.report'].read_group(
                domain, ['product_id', 'product_uom_qty'], ['product_id']):
            r[group['product_id'][0]] = group['product_uom_qty']
        for product in self:
            if not product.id:
                product.sales_count = 0.0
                continue
            product.sales_count = float_round(
                r.get(product.id, 0),
                precision_rounding=product.uom_id.rounding)
        return r
Пример #15
0
 def _compute_sales_count(self):
     for product in self:
         product.sales_count = float_round(
             sum([
                 p.sales_count for p in product.with_context(
                     active_test=False).product_variant_ids
             ]),
             precision_rounding=product.uom_id.rounding)
Пример #16
0
 def _compute_purchased_product_qty(self):
     for template in self:
         template.purchased_product_qty = float_round(
             sum([
                 p.purchased_product_qty
                 for p in template.product_variant_ids
             ]),
             precision_rounding=template.uom_id.rounding)
Пример #17
0
 def name_get(self):
     if not self._context.get('employee_id'):
         # leave counts is based on employee_id, would be inaccurate if not based on correct employee
         return super(HolidaysType, self).name_get()
     res = []
     for record in self:
         name = record.name
         if record.allocation_type != 'no':
             name = "%(name)s (%(count)s)" % {
                 'name': name,
                 'count': _('%g remaining out of %g') % (
                     float_round(record.virtual_remaining_leaves, precision_digits=2) or 0.0,
                     float_round(record.max_leaves, precision_digits=2) or 0.0,
                 ) + (_(' hours') if record.request_unit == 'hour' else _(' days'))
             }
         res.append((record.id, name))
     return res
Пример #18
0
 def _get_margin_value(self, value, previous_value=0.0):
     margin = 0.0
     if (value != previous_value) and (value != 0.0
                                       and previous_value != 0.0):
         margin = float_round(
             (float(value - previous_value) / previous_value or 1) * 100,
             precision_digits=2)
     return margin
Пример #19
0
    def default_get(self, fields):
        if len(self.env.context.get('active_ids', list())) > 1:
            raise UserError("You may only return one picking at a time!")
        res = super(ReturnPicking, self).default_get(fields)

        move_dest_exists = False
        product_return_moves = []
        picking = self.env['stock.picking'].browse(
            self.env.context.get('active_id'))
        if picking:
            res.update({'picking_id': picking.id})
            if picking.state != 'done':
                raise UserError(_("You may only return Done pickings"))
            for move in picking.move_lines:
                if move.state == 'cancel':
                    continue
                if move.scrapped:
                    continue
                if move.move_dest_ids:
                    move_dest_exists = True
                quantity = move.product_qty - sum(move.move_dest_ids.filtered(lambda m: m.state in ['partially_available', 'assigned', 'done']).\
                                                  mapped('move_line_ids').mapped('product_qty'))
                quantity = float_round(
                    quantity, precision_rounding=move.product_uom.rounding)
                product_return_moves.append((0, 0, {
                    'product_id':
                    move.product_id.id,
                    'quantity':
                    quantity,
                    'move_id':
                    move.id,
                    'uom_id':
                    move.product_id.uom_id.id
                }))

            if not product_return_moves:
                raise UserError(
                    _("No products to return (only lines in Done state and not fully returned yet can be returned)!"
                      ))
            if 'product_return_moves' in fields:
                res.update({'product_return_moves': product_return_moves})
            if 'move_dest_exists' in fields:
                res.update({'move_dest_exists': move_dest_exists})
            if 'parent_location_id' in fields and picking.location_id.usage == 'internal':
                res.update({
                    'parent_location_id':
                    picking.picking_type_id.warehouse_id and
                    picking.picking_type_id.warehouse_id.view_location_id.id
                    or picking.location_id.location_id.id
                })
            if 'original_location_id' in fields:
                res.update({'original_location_id': picking.location_id.id})
            if 'location_id' in fields:
                location_id = picking.location_id.id
                if picking.picking_type_id.return_picking_type_id.default_location_dest_id.return_location:
                    location_id = picking.picking_type_id.return_picking_type_id.default_location_dest_id.id
                res['location_id'] = location_id
        return res
Пример #20
0
    def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, ml_to_ignore=None):
        """ When editing a done move line or validating one with some forced quantities, it is
        possible to impact quants that were not reserved. It is therefore necessary to edit or
        unlink the move lines that reserved a quantity now unavailable.

        :param ml_to_ignore: recordset of `stock.move.line` that should NOT be unreserved
        """
        self.ensure_one()

        if ml_to_ignore is None:
            ml_to_ignore = self.env['stock.move.line']
        ml_to_ignore |= self

        # Check the available quantity, with the `strict` kw set to `True`. If the available
        # quantity is greather than the quantity now unavailable, there is nothing to do.
        available_quantity = self.env['stock.quant']._get_available_quantity(
            product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True
        )
        if quantity > available_quantity:
            # We now have to find the move lines that reserved our now unavailable quantity. We
            # take care to exclude ourselves and the move lines were work had already been done.
            oudated_move_lines_domain = [
                ('move_id.state', 'not in', ['done', 'cancel']),
                ('product_id', '=', product_id.id),
                ('lot_id', '=', lot_id.id if lot_id else False),
                ('location_id', '=', location_id.id),
                ('owner_id', '=', owner_id.id if owner_id else False),
                ('package_id', '=', package_id.id if package_id else False),
                ('product_qty', '>', 0.0),
                ('id', 'not in', ml_to_ignore.ids),
            ]
            oudated_candidates = self.env['stock.move.line'].search(oudated_move_lines_domain)

            # As the move's state is not computed over the move lines, we'll have to manually
            # recompute the moves which we adapted their lines.
            move_to_recompute_state = self.env['stock.move']

            rounding = self.product_uom_id.rounding
            for candidate in oudated_candidates:
                if float_compare(candidate.product_qty, quantity, precision_rounding=rounding) <= 0:
                    quantity -= candidate.product_qty
                    move_to_recompute_state |= candidate.move_id
                    if candidate.qty_done:
                        candidate.product_uom_qty = 0.0
                    else:
                        candidate.unlink()
                else:
                    # split this move line and assign the new part to our extra move
                    quantity_split = float_round(
                        candidate.product_qty - quantity,
                        precision_rounding=self.product_uom_id.rounding,
                        rounding_method='UP')
                    candidate.product_uom_qty = self.product_id.uom_id._compute_quantity(quantity_split, candidate.product_uom_id, rounding_method='HALF-UP')
                    quantity -= quantity_split
                    move_to_recompute_state |= candidate.move_id
                if quantity == 0.0:
                    break
            move_to_recompute_state._recompute_state()
Пример #21
0
 def _compute_remaining_leaves(self):
     remaining = {}
     if self.ids:
         remaining = self._get_remaining_leaves()
     for employee in self:
         value = float_round(remaining.get(employee.id, 0.0),
                             precision_digits=2)
         employee.leaves_count = value
         employee.remaining_leaves = value
Пример #22
0
 def trans_rec_get(self):
     context = self._context or {}
     credit = debit = 0
     lines = self.env['account.move.line'].browse(
         context.get('active_ids', []))
     for line in lines:
         if not line.full_reconcile_id:
             credit += line.credit
             debit += line.debit
     precision = self.env.user.company_id.currency_id.decimal_places
     writeoff = float_round(debit - credit, precision_digits=precision)
     credit = float_round(credit, precision_digits=precision)
     debit = float_round(debit, precision_digits=precision)
     return {
         'trans_nbr': len(lines),
         'credit': credit,
         'debit': debit,
         'writeoff': writeoff
     }
Пример #23
0
 def _compute_mrp_product_qty(self):
     date_from = fields.Datetime.to_string(fields.datetime.now() - timedelta(days=365))
     #TODO: state = done?
     domain = [('state', '=', 'done'), ('product_id', 'in', self.ids), ('date_planned_start', '>', date_from)]
     read_group_res = self.env['mrp.production'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id'])
     mapped_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in read_group_res])
     for product in self:
         if not product.id:
             product.mrp_product_qty = 0.0
             continue
         product.mrp_product_qty = float_round(mapped_data.get(product.id, 0), precision_rounding=product.uom_id.rounding)
Пример #24
0
 def _onchange_secondary_uom(self):
     if not self.secondary_uom_id:
         return
     factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor
     qty = float_round(self.secondary_uom_qty * factor,
                       precision_rounding=self.product_id.uom_id.rounding)
     if float_compare(
             self.units_included,
             qty,
             precision_rounding=self.product_id.uom_id.rounding) != 0:
         self.units_included = qty
Пример #25
0
 def _onchange_units_included_purchase_order_secondary_unit(self):
     if not self.secondary_uom_id:
         return
     factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor
     qty = float_round(
         self.units_included / (factor or 1.0),
         precision_rounding=self.secondary_uom_id.uom_id.rounding)
     if float_compare(
             self.secondary_uom_qty,
             qty,
             precision_rounding=self.secondary_uom_id.uom_id.rounding) != 0:
         self.secondary_uom_qty = qty
Пример #26
0
 def ogone_form_generate_values(self, values):
     base_url = self.env['ir.config_parameter'].sudo().get_param(
         'web.base.url')
     ogone_tx_values = dict(values)
     param_plus = {'return_url': ogone_tx_values.pop('return_url', False)}
     temp_ogone_tx_values = {
         'PSPID':
         self.ogone_pspid,
         'ORDERID':
         values['reference'],
         'AMOUNT':
         float_repr(float_round(values['amount'], 2) * 100, 0),
         'CURRENCY':
         values['currency'] and values['currency'].name or '',
         'LANGUAGE':
         values.get('partner_lang'),
         'CN':
         values.get('partner_name'),
         'EMAIL':
         values.get('partner_email'),
         'OWNERZIP':
         values.get('partner_zip'),
         'OWNERADDRESS':
         values.get('partner_address'),
         'OWNERTOWN':
         values.get('partner_city'),
         'OWNERCTY':
         values.get('partner_country')
         and values.get('partner_country').code or '',
         'OWNERTELNO':
         values.get('partner_phone'),
         'ACCEPTURL':
         urls.url_join(base_url, OgoneController._accept_url),
         'DECLINEURL':
         urls.url_join(base_url, OgoneController._decline_url),
         'EXCEPTIONURL':
         urls.url_join(base_url, OgoneController._exception_url),
         'CANCELURL':
         urls.url_join(base_url, OgoneController._cancel_url),
         'PARAMPLUS':
         url_encode(param_plus),
     }
     if self.save_token in ['ask', 'always']:
         temp_ogone_tx_values.update({
             'ALIAS':
             'FLECTRA-NEW-ALIAS-%s' % time.time(),  # something unique,
             'ALIASUSAGE':
             values.get('alias_usage') or self.ogone_alias_usage,
         })
     shasign = self._ogone_generate_shasign('in', temp_ogone_tx_values)
     temp_ogone_tx_values['SHASIGN'] = shasign
     ogone_tx_values.update(temp_ogone_tx_values)
     return ogone_tx_values
Пример #27
0
 def _compute_allocation_count(self):
     data = self.env['hr.leave.allocation'].read_group([
         ('employee_id', 'in', self.ids),
         ('holiday_status_id.active', '=', True),
         ('state', '=', 'validate'),
     ], ['number_of_days:sum', 'employee_id'], ['employee_id'])
     rg_results = dict(
         (d['employee_id'][0], d['number_of_days']) for d in data)
     for employee in self:
         employee.allocation_count = float_round(rg_results.get(
             employee.id, 0.0),
                                                 precision_digits=2)
         employee.allocation_display = "%g" % employee.allocation_count
Пример #28
0
    def _create_stripe_refund(self):

        refund_params = {
            'charge': self.acquirer_reference,
            'amount': int(float_round(self.amount * 100, 2)), # by default, stripe refund the full amount (we don't really need to specify the value)
            'metadata[reference]': self.reference,
        }

        _logger.info('_create_stripe_refund: Sending values to stripe URL, values:\n%s', pprint.pformat(refund_params))
        res = self.acquirer_id._stripe_request('refunds', refund_params)
        _logger.info('_create_stripe_refund: Values received:\n%s', pprint.pformat(res))

        return res
Пример #29
0
 def create(self, vals):
     move = self.env['stock.move'].browse(vals.get('move_id', False))
     if move.secondary_uom_id:
         uom = self.env['product.uom'].browse(vals['product_uom_id'])
         factor = move.secondary_uom_id.factor * uom.factor
         move_line_qty = vals.get('product_uom_qty',
                                  vals.get('qty_done', 0.0))
         qty = float_round(
             move_line_qty / (factor or 1.0),
             precision_rounding=move.secondary_uom_id.uom_id.factor)
         vals.update({
             'secondary_uom_qty': qty,
             'secondary_uom_id': move.secondary_uom_id.id,
         })
     return super().create(vals)
Пример #30
0
 def _stripe_form_get_invalid_parameters(self, data):
     invalid_parameters = []
     if data.get("amount") != int(
             self.amount if self.currency_id.name in
             INT_CURRENCIES else float_round(self.amount * 100, 2)):
         invalid_parameters.append(
             ("Amount", data.get("amount"), self.amount * 100))
     if data.get("currency").upper() != self.currency_id.name:
         invalid_parameters.append(
             ("Currency", data.get("currency"), self.currency_id.name))
     if data.get("payment_intent") and data.get(
             "payment_intent") != self.stripe_payment_intent:
         invalid_parameters.append(
             ("Payment Intent", data.get("payment_intent"),
              self.stripe_payment_intent))
     return invalid_parameters