~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to sale_commission/sale_commission.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
 
from osv import osv
3
 
from osv import fields
4
 
from tools.translate import _
 
2
from openerp.osv import fields, osv
 
3
from openerp.tools.translate import _
 
4
 
5
5
import decimal_precision as dp
6
6
 
7
 
class sale_commission(osv.osv):
8
 
 
9
 
    def _get_commission(self, cr, uid,ids,name,args,context=None):
10
 
        res={}
11
 
      
12
 
        for so_brw in self.browse(cr,uid,ids):
13
 
            res[so_brw.id]=0.0
 
7
 
 
8
class sale_commission(osv.Model):
 
9
 
 
10
    def _get_commission(self, cr, uid, ids, name, args, context=None):
 
11
        res = {}
 
12
 
 
13
        for so_brw in self.browse(cr, uid, ids):
 
14
            res[so_brw.id] = 0.0
14
15
            for sol_brw in so_brw.order_line:
15
 
                res[so_brw.id]+=sol_brw.commission
 
16
                res[so_brw.id] += sol_brw.commission
16
17
        return res
17
 
    
 
18
 
18
19
    def _get_order_line(self, cr, uid, ids, context=None):
19
20
        res = {}
20
21
        for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
21
22
            res[line.order_id.id] = True
22
23
        return res.keys()
23
 
    
24
 
    _inherit ='sale.order'
25
 
    _columns ={
26
 
        'commission': fields.function(_get_commission, method=True, type='float', string='Commission',digits_compute= dp.get_precision('Commission'),
27
 
            store={
28
 
                'sale.order': (lambda  self, cr, uid, ids, c={}: ids,['order_line','state'], 25),
29
 
                'sale.order.line': (_get_order_line, ['gain', 'commission'], 15),})
 
24
 
 
25
    _inherit = 'sale.order'
 
26
    _columns = {
 
27
        'commission': fields.function(_get_commission, method=True, type='float', string='Commission', digits_compute=dp.get_precision('Commission'),
 
28
                                      store={
 
29
                                      'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line', 'state'], 25),
 
30
                                      'sale.order.line': (_get_order_line, ['gain', 'commission'], 15), })
30
31
    }
31
 
sale_commission()
32
 
 
33
 
class sale_commission_line(osv.osv):
34
 
    
35
 
    
36
 
    def get_abs_commission(self, cr, uid,ids,name,args,context=None):
37
 
        
 
32
 
 
33
 
 
34
class sale_commission_line(osv.Model):
 
35
 
 
36
    def get_abs_commission(self, cr, uid, ids, name, args, context=None):
 
37
 
38
38
        bar_obj = self.pool.get('baremo.book')
39
 
        res={}
40
 
        for sol_brw in self.browse(cr,uid,ids):
 
39
        res = {}
 
40
        for sol_brw in self.browse(cr, uid, ids):
41
41
            bar_id = sol_brw.company_id.bar_id and sol_brw.company_id.bar_id.id or False
42
 
            print '--------------- bar_id -------------',bar_id
 
42
            print '--------------- bar_id -------------', bar_id
43
43
            if not bar_id:
44
44
                # TODO: raise exception, levantar excepcion.
45
45
                # de momento esta asi como se muestra, enviando
46
46
                # un calculo igual a cero para cuando no haya
47
47
                # establecido en la company un tipo de baremo
48
48
                print 'NO HAY BAREMO EN LA COMPANY'
49
 
                res[sol_brw.id]=0.0
 
49
                res[sol_brw.id] = 0.0
50
50
                continue
51
51
            rate = sol_brw.gain
52
 
            rate_comm=bar_obj._calc_comm(cr,uid,ids,bar_id,rate,0.0,context=None)['rate_comm']
53
 
            res[sol_brw.id]=sol_brw.price_subtotal * rate_comm / 100
54
 
            print 'res[%s] = subtotal(%s) * tasa(%s) => %s'%(sol_brw.id, sol_brw.price_subtotal,rate_comm,res[sol_brw.id])
 
52
            rate_comm = bar_obj._calc_comm(
 
53
                cr, uid, ids, bar_id, rate, 0.0, context=None)['rate_comm']
 
54
            res[sol_brw.id] = sol_brw.price_subtotal * rate_comm / 100
 
55
            print 'res[%s] = subtotal(%s) * tasa(%s) => %s' % (sol_brw.id, sol_brw.price_subtotal, rate_comm, res[sol_brw.id])
55
56
        return res
56
 
            
57
 
    def get_gain(self, cr, uid,ids,name,args,context=None):
58
 
        res={}
59
 
        product_price = 0 
60
 
        product_pu = 0 
61
 
        gain = 0 
62
 
        for sol_brw in self.browse(cr,uid,ids):
 
57
 
 
58
    def get_gain(self, cr, uid, ids, name, args, context=None):
 
59
        res = {}
 
60
        product_price = 0
 
61
        product_pu = 0
 
62
        gain = 0
 
63
        for sol_brw in self.browse(cr, uid, ids):
63
64
            if sol_brw.product_id:
64
65
                product_cost = sol_brw.product_id.standard_price
65
66
                if product_cost != 0.0:
66
67
                    product_pu = sol_brw.price_unit
67
 
                    res[sol_brw.id]=((product_pu-product_cost)/product_cost)*100
 
68
                    res[sol_brw.id] = ((
 
69
                        product_pu-product_cost)/product_cost)*100
68
70
                else:
69
 
                    raise osv.except_osv(_("User Error"), _("The product standard price can't be 0.0!"))
 
71
                    raise osv.except_osv(_("User Error"), _(
 
72
                        "The product standard price can't be 0.0!"))
70
73
            else:
71
 
                res[sol_brw.id]=0.0
 
74
                res[sol_brw.id] = 0.0
72
75
        print 'get_gain'
73
76
        return res
74
77
 
75
78
    _inherit = 'sale.order.line'
76
79
    _columns = {
77
 
        'gain':fields.function(get_gain,method=True, type='float',string='Gain',digits_compute= dp.get_precision('Commission'),
78
 
            store={
79
 
                'sale.order.line':(lambda self, cr, uid, ids, c={}: ids, ['price_unit','price_subtotal','product_uom_qty'], 15),
80
 
            }),
81
 
        'commission': fields.function(get_abs_commission,method=True, type='float',string='Commission',digits_compute= dp.get_precision('Commission'),
82
 
            store={
83
 
                'sale.order.line':(lambda self, cr, uid, ids, c={}: ids, None, 25),
84
 
            }),
 
80
        'gain': fields.function(get_gain, method=True, type='float', string='Gain', digits_compute=dp.get_precision('Commission'),
 
81
                                store={
 
82
                                'sale.order.line': (lambda self, cr, uid, ids, c={}: ids, ['price_unit', 'price_subtotal', 'product_uom_qty'], 15),
 
83
                                }),
 
84
        'commission': fields.function(get_abs_commission, method=True, type='float', string='Commission', digits_compute=dp.get_precision('Commission'),
 
85
                                      store={
 
86
                                      'sale.order.line': (lambda self, cr, uid, ids, c={}: ids, None, 25),
 
87
                                      }),
85
88
    }
86
 
    
87
 
sale_commission_line()
88
89