[Python] Info built-in types Python

Cristian Esposito cristian.esposito a hotmail.com
Ven 1 Lug 2016 11:33:14 CEST


Buongiorno,

 

mi trovo in questa situazione in cui dovrei calcolare la percentuale dello
sconto/montante ('sale_sale' e 'sale_montante') sull'ammontare non tassato
('amount_untaxed').

Queste sono le mie righe di codice:

 

def _sumqty_all(self, cr, uid, ids, field_name, arg, context=None):

        cur_obj = self.pool.get('res.currency')

        res = {}

        for order in self.browse(cr, uid, ids, context=context):

            res[order.id] = {

                'amount_untaxed': 0.0,

                'amount_tax': 0.0,

                'amount_total': 0.0,

                'sale_sale': sale_order.sale_sale,

                'sale_montante': sale_order.sale_montante,

                'sale_override': sale_order.sale_override,

                'percentage_for_sale': 0.01,

            }

            val = val1 = 0.0

            cur = order.pricelist_id.currency_id

            for line in order.order_line:

                res[order.id]['amount_untaxed'] += line.price_subtotal

                val += self._amount_line_tax(cr, uid, line, context=context)

        

            if res[order.id]['sale_sale']:

                val1 = res[order.id]['amount_untaxed'] -
(res[order.id]['amount_untaxed'] * (res[order.id]['sale_sale'] *
res[order.id]['percentage_for_sale']))    

            elif res[order.id]['sale_montante']:

                val1 = res[order.id]['amount_untaxed'] +
(res[order.id]['amount_untaxed'] * (res[order.id]['sale_montante'] *
res[order.id]['percentage_for_sale']))

            elif res[order.id]['sale_override']:

                val1 = res[order.id]['sale_override']

                

            res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)

            res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur,
val1)

            res[order.id]['amount_total'] = res[order.id]['amount_untaxed']
+ res[order.id]['amount_tax']

        

        print(val1)

        #print("stasmp")        

        return res

 

 

Nella compilazione mi torna il seguente problema:

 

Traceback (most recent call last):

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 530, in
_handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 567, in dispatch

    result = self._call_function(**self.params)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 303, in
_call_function

    return checked_call(self.db, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\service\model.py", line 113, in
wrapper

    return f(dbname, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 300, in
checked_call

    return self.endpoint(*a, **kw)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 796, in __call__

    return self.method(*args, **kw)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 396, in
response_wrap

    response = f(*args, **kw)

  File "C:\nexapp\source\Svil\odoo\openerp\addons\web\controllers\main.py",
line 949, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\addons\web\controllers\main.py",
line 932, in _call_kw

    records = getattr(request.session.model(model), method)(*args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\http.py", line 900, in proxy

    result = meth(cr, request.uid, *args, **kw)

  File "C:\nexapp\source\Svil\odoo\openerp\api.py", line 241, in wrapper

    return old_api(self, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\models.py", line 5130, in
search_read

    result = self.read(cr, uid, record_ids, fields, context=read_ctx)

  File "C:\nexapp\source\Svil\odoo\openerp\api.py", line 241, in wrapper

    return old_api(self, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\models.py", line 3128, in read

    result = BaseModel.read(records, fields, load=load)

  File "C:\nexapp\source\Svil\odoo\openerp\api.py", line 239, in wrapper

    return new_api(self, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\models.py", line 3163, in read

    self._read_from_database(stored, inherited)

  File "C:\nexapp\source\Svil\odoo\openerp\api.py", line 239, in wrapper

    return new_api(self, *args, **kwargs)

  File "C:\nexapp\source\Svil\odoo\openerp\models.py", line 3328, in
_read_from_database

    res2 = self._columns[fs[0]].get(cr, self._model, ids, fs, user,
context=context, values=result)

  File "C:\nexapp\source\Svil\odoo\openerp\osv\fields.py", line 1365, in get

    result = self._fnct(obj, cr, uid, ids, name, self._arg, context)

  File
"C:\nexapp\source\Svil\aurema_HEAD\odoo\openerp\addons\na_aurema_project\mod
els\sale.py", line 44, in _sumqty_all_wrapper

    return self._sumqty_all(cr, uid, ids, field_name, arg, context=context)

  File "C:\nexapp\source\Svil\odoo\openerp\api.py", line 241, in wrapper

    return old_api(self, *args, **kwargs)

  File
"C:\nexapp\source\Svil\aurema_HEAD\odoo\openerp\addons\na_aurema_project\mod
els\sale.py", line 66, in _sumqty_all

    val1 = res[order.id]['amount_untaxed'] -
(res[order.id]['amount_untaxed'] * (res[order.id]['sale_sale'] *
res[order.id]['percentage_for_sale']))

TypeError: unsupported operand type(s) for *: 'Float' and 'float'

 

Presumo che il primo tipo di variabile sia una variabile built-in float,
mentre la seconda una float normale.

Come posso eseguire operazioni tra una variabile built-in Float e una
variabile primitiva float?

 

Grazie in anticipo, buon lavoro.

 

 

Cristian

-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20160701/afb3a7f5/attachment-0001.html>


Maggiori informazioni sulla lista Python