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