~openbig/bigconsulting/functional_field_add_in_product_tab

« back to all changes in this revision

Viewing changes to product_price_information/product_price_info.py

  • Committer: aag(OpenERP)
  • Date: 2010-06-22 14:04:50 UTC
  • Revision ID: aagopenerp-20100622140450-p18ufnp7b3dkxr28
functional field add in product tab

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
2
##############################################################################
3
3
#
4
 
#    OpenERP, Open Source Management Solution    
 
4
#    OpenERP, Open Source Management Solution
5
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
6
#    $Id$
7
7
#
21
21
##############################################################################
22
22
from osv import fields, osv
23
23
from tools import config
24
 
    
 
24
 
25
25
class sale_order_line(osv.osv):
26
26
    _inherit = "sale.order.line"
27
27
 
28
28
    _columns = {
29
29
        'sale_price_unit_tax': fields.float('Sale price W/O taxes'),
30
30
    }
31
 
    
 
31
 
32
32
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
33
33
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
34
34
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
35
 
        
 
35
 
36
36
        tax_obj = self.pool.get('account.tax')
37
 
        
 
37
 
38
38
        result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
39
39
            uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
40
40
        if product:
43
43
            result['value']['sale_price_unit_tax'] = product_obj.product_tmpl_id.price_unit_tax
44
44
 
45
45
        return result
46
 
    
 
46
 
47
47
sale_order_line()
48
48
 
49
49
class sale_order(osv.osv):
50
50
    _name = "sale.order"
51
51
    _inherit = "sale.order"
52
 
    
 
52
 
53
53
    def onchange_shop_id(self, cr, uid, ids, shop_id):
54
54
        res = super(sale_order, self).onchange_shop_id(cr, uid, id, shop_id)
55
55
        if 'value' in res and shop_id:
56
56
            res['value']['price_type'] = self.pool.get('sale.shop').browse(cr, uid , shop_id).price_type
57
57
        return res
58
 
    
 
58
 
59
59
sale_order()
60
60
 
61
61
 
86
86
    _defaults = {
87
87
        'price_type': lambda *a: 'tax_included',
88
88
    }
89
 
    
 
89
 
90
90
    def set_default(self, cr, uid, ids, context=None):
91
91
        for o in self.browse(cr, uid, ids, context=context):
92
92
            ir_values_obj = self.pool.get('ir.values')
97
97
                'res_model': 'ir.actions.configuration.wizard',
98
98
                'type': 'ir.actions.act_window',
99
99
                'target': 'new',
100
 
         } 
101
 
        
 
100
         }
 
101
 
102
102
    def action_cancel(self,cr,uid,ids,conect=None):
103
103
        return {
104
104
                'view_type': 'form',
107
107
                'type': 'ir.actions.act_window',
108
108
                'target':'new',
109
109
        }
110
 
        
111
 
sale_shop_price_method_policy()
 
 
b'\\ No newline at end of file'
 
110
 
 
111
sale_shop_price_method_policy()
 
112
 
 
113
 
 
114
class product_product(osv.osv):
 
115
    _name = "product.product"
 
116
    _inherit = "product.product"
 
117
    _description = "Product"
 
118
 
 
119
    def _get_all_values(self, cr, uid, ids, name, arg, context={}):
 
120
        res = {}
 
121
        product = ids
 
122
        product_obj = self.pool.get('product.product')
 
123
        obj2 = self.pool.get('product.pricelist.item')
 
124
        obj = self.pool.get('product.pricelist')
 
125
        obj3 = self.pool.get('sale.order.line')
 
126
        for line in product_obj.browse(cr, uid, product, context=context):
 
127
            partner = line.pi_partner_id.id
 
128
            pricelist = line.pi_pricelist_id.id
 
129
            qty1 = line.pi_quantity1
 
130
            qty2 = line.pi_quantity2
 
131
            if pricelist != False:
 
132
                val1 = obj.price_get(cr, uid, [pricelist], line.id, qty1, partner)
 
133
                for key,values  in val1.items():
 
134
                    c_price1 = values
 
135
                val2 = obj.price_get(cr, uid, [pricelist], line.id, qty2, partner)
 
136
                for key,values  in val2.items():
 
137
                    c_price2 = values
 
138
                item_line = obj2.search(cr,uid,[])
 
139
                list = []
 
140
                for line2 in obj2.browse(cr, uid, item_line, context=context):
 
141
                    if line.id == line2.product_id.id:
 
142
                        list.append(line.min_quantity)
 
143
                    if list == []:
 
144
                        m_qty = 1.0
 
145
                    else:
 
146
                        m_qty = max(list)
 
147
                    val3 = obj.price_get(cr, uid, [pricelist], line.id, m_qty, partner)
 
148
                    for key,values  in val3.items():
 
149
                        c_price3 = values
 
150
                    list_price = product_obj.browse(cr, uid, line.id).standard_price
 
151
                    list_price1 = list_price * qty1
 
152
                    list_price2 = list_price * qty2
 
153
                    read_id = obj3.search(cr,uid,[('product_id','=',line.id)])
 
154
                    if read_id == []:
 
155
                        last_price = 0.0
 
156
                        qty_last = 0.0
 
157
                        last_list_price = 0.0
 
158
                    else:
 
159
                        last_id = max(read_id)
 
160
                        last_brw = obj3.browse(cr,uid,[last_id],context=context)
 
161
                        for rec in last_brw:
 
162
                            product2 = rec.product_id.id
 
163
                            if line.id == product2:
 
164
                                last_price = rec.price_unit
 
165
                                qty_last = rec.product_uom_qty
 
166
                                val_last = obj.price_get(cr, uid,[pricelist], line.id, qty_last)
 
167
                                for key,values  in val_last.items():
 
168
                                    last_list_price = values
 
169
 
 
170
                    for id in ids:
 
171
                        res[id] = {}
 
172
                        if 'pi_customer_prices1' in name:
 
173
                             res[id]['pi_customer_prices1'] = c_price1
 
174
                        if 'pi_customer_prices2' in name:
 
175
                             res[id]['pi_customer_prices2'] = c_price2
 
176
                        if 'pi_list_prices1' in name:
 
177
                             res[id]['pi_list_prices1'] = list_price1
 
178
                        if 'pi_list_prices2'in name:
 
179
                             res[id]['pi_list_prices2']= list_price2
 
180
                        if 'pi_next_better_price_qty'in name:
 
181
                             res[id]['pi_next_better_price_qty']= m_qty
 
182
                        if 'pi_best_price_on_qty'in name:
 
183
                             res[id]['pi_best_price_on_qty']= c_price3
 
184
                        if 'pi_last_customer_prices'in name:
 
185
                             res[id]['pi_last_customer_prices']= last_price
 
186
                        if 'pi_last_list_prices'in name:
 
187
                             res[id]['pi_last_list_prices']= last_list_price
 
188
                        if 'pi_qty_buyed'in name:
 
189
                             res[id]['pi_qty_buyed']= qty_last
 
190
 
 
191
            else:
 
192
                 for id in ids:
 
193
                        res[id] = {}
 
194
                        if 'pi_customer_prices1' in name:
 
195
                             res[id]['pi_customer_prices1'] = 0.0
 
196
                        if 'pi_customer_prices2' in name:
 
197
                            res[id]['pi_customer_prices2'] = 0.0
 
198
                        if 'pi_list_prices1' in name:
 
199
                            res[id]['pi_list_prices1'] = 0.0
 
200
                        if 'pi_list_prices2'in name:
 
201
                            res[id]['pi_list_prices2']= 0.0
 
202
                        if 'pi_next_better_price_qty'in name:
 
203
                            res[id]['pi_next_better_price_qty']= 0.0
 
204
                        if 'pi_best_price_on_qty'in name:
 
205
                            res[id]['pi_best_price_on_qty']= 0.0
 
206
                        if 'pi_last_customer_prices'in name:
 
207
                            res[id]['pi_last_customer_prices']= 0.0
 
208
                        if 'pi_last_list_prices'in name:
 
209
                            res[id]['pi_last_list_prices']= 0.0
 
210
                        if 'pi_qty_buyed'in name:
 
211
                            res[id]['pi_qty_buyed']= 0.0
 
212
        return res
 
213
 
 
214
    _columns = {
 
215
        'pi_quantity1': fields.float('Quantity1'),
 
216
        'pi_quantity2': fields.float('Quantity2'),
 
217
        'pi_pricelist_id': fields.many2one('product.pricelist', 'Pricelist'),
 
218
        'pi_partner_id': fields.many2one('res.partner', 'Customer'),
 
219
        'pi_customer_prices1': fields.function(_get_all_values, method=True, type='float', string='Costomer Prices',multi='pi_customer_prices1'),
 
220
        'pi_customer_prices2': fields.function(_get_all_values, method=True, type='float', string='Costomer Prices',multi='pi_customer_prices2'),
 
221
        'pi_list_prices1': fields.function(_get_all_values, method=True, type='float', string='List Prices',multi='pi_list_prices1'),
 
222
        'pi_list_prices2': fields.function(_get_all_values, method=True, type='float', string='List Prices',multi='pi_list_prices2'),
 
223
        'pi_next_better_price_qty': fields.function(_get_all_values, method=True, type='float', string='Next Better Price Qty',multi='pi_next_better_price_qty'),
 
224
        'pi_best_price_on_qty': fields.function(_get_all_values, method=True, type='float', string='Best Price On Quantity',multi='pi_best_price_on_qty'),
 
225
        'pi_last_customer_prices': fields.function(_get_all_values, method=True, type='float', string='Last Costomer Prices',multi='pi_last_customer_prices'),
 
226
        'pi_last_list_prices': fields.function(_get_all_values, method=True, type='float', string='Last List Prices',multi='pi_last_list_prices'),
 
227
        'pi_qty_buyed': fields.function(_get_all_values, method=True, type='float', string='Quantity Buyed',multi='pi_qty_buyed'),
 
228
        }
 
229
    _defaults = {
 
230
        'pi_quantity1': lambda *a: 1.0,
 
231
        'pi_quantity2': lambda *a: 5.0,
 
232
         }
 
233
product_product()
 
234