1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# -*- encoding: utf-8 -*-
from openerp.osv import fields, osv
from openerp.tools.translate import _
class sale_order(osv.Model):
"""
sale_order
"""
def _get_commision(self, price, cost):
return (price and cost) and ((price - cost/price)*100) or 0
def _check_commision(self, cr, uid, ids, field_name, arg, context):
result = {}
for i in ids:
print i
result[i] = 10
return result
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='',
partner_id=False, lang=False, update_tax=True,
date_order=False, packaging=False,
fiscal_position=False, flag=False):
res = super(sale_order_line, self).product_id_change(cr, uid, ids,
pricelist,
product, qty=qty,
uom=uom,
qty_uos=qty_uos,
uos=uos,
name=name,
partner_id=
partner_id,
lang=lang,
update_tax=
update_tax,
date_order=
date_order,
packaging=
packaging,
fiscal_position=
fiscal_position,
flag=flag)
frm_cur = self.pool.get('res.users').browse(
cr, uid, uid).company_id.currency_id.id
to_cur = self.pool.get('res.partner').browse(
cr, uid, partner_id).property_product_pricelist.currency_id.id
if product:
purchase_price = self.pool.get('product.product').browse(
cr, uid, product).standard_price
price = self.pool.get('res.currency').compute(
cr, uid, frm_cur, to_cur, purchase_price, round=False)
res['value'].update({'purchase_price': price})
return res
def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = 0
if line.product_id:
if line.purchase_price:
res[line.id] = round((line.price_unit *
line.product_uos_qty *
(100.0-line.discount) / 100.0) -
(line.purchase_price *
line.product_uos_qty), 2)
else:
res[line.id] = round((line.price_unit*line.product_uos_qty
* (100.0-line.discount)/100.0) -
(line.product_id.standard_price *
line.product_uos_qty), 2)
return res
_inherit = 'sale.order'
_columns = {
'commision': fields.function(_check_commision, method=True,
type='float', string='Commision Rate',
store=True,
help="""It is the commision calculate
based on baremos"""),
'margin': fields.function(_check_commision, method=True,
type='float', string='Margin', store=True,
help="""It gives profitability by
calculating the difference between
the Unit Price and Cost Price."""),
}
|