Advertisement
lukio

problem-on_change_with-sale_id

Jun 19th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. class Cantidades(ModelSQL, ModelView):
  2.     'Imprenta. Otras Cantidades'
  3.     _name = 'sale_imprenta.cantidad'
  4.     _description = 'Otras Cantidades'
  5.  
  6.     cantidad = fields.Integer('Cantidad', required=True)
  7.     utilidad = fields.Integer('Porcentaje de Utilidad', required=True)
  8.     sale_id = fields.Many2One('sale.sale','Venta')
  9.  
  10.     total = fields.Function(fields.Numeric('Total', digits=(16, 2), depends=['cantidad'], on_change_with=['cantidad', 'utilidad', 'sale_id']), 'get_total_amount')
  11.  
  12.     def default_utilidad(self):
  13.         return 0
  14.  
  15.     def on_change_with_total(self, vals):
  16.         'On change With Campo Total'
  17.    
  18.         if vals.get('sale_id'):
  19.             ## I would like to call get_total_amount()
  20.  
  21.     def get_total_amount(self, ids, name):
  22.         'Total para Otras Cantidades'
  23.  
  24.         currency_obj = Pool().get('currency.currency')
  25.         amounts = {}
  26.  
  27.         for cantidades in self.browse(ids):
  28.             sale = cantidades.sale_id
  29.             amount_fijo = sum((l.amount for l in sale.lines if l.type == 'line' and l.fijo),
  30.                     Decimal(0))
  31.             factor = Decimal(float(cantidades.cantidad) / sale.cantidad)
  32.             amount_variable = sum((l.amount * factor for l in sale.lines if l.type == 'line' and not l.fijo),
  33.                     Decimal(0))
  34.             amounts[cantidades.id] = currency_obj.round(sale.currency, (amount_fijo + amount_variable)*(100+cantidades.utilidad)/100)
  35.  
  36.         return amounts
  37.  
  38.  
  39. Cantidades()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement