~openbig/bigconsulting/product_price_information_patch

« back to all changes in this revision

Viewing changes to product_price_information/product_price_info.py

  • Committer: gpa
  • Date: 2010-07-19 15:08:55 UTC
  • Revision ID: gpa@tinyerp.com-20100719150855-hrwiq647sw16aodw
apply the changes of the patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#
21
21
##############################################################################
22
22
from osv import fields, osv
23
 
from tools import config
24
23
 
25
24
class sale_order_line(osv.osv):
26
25
    _inherit = "sale.order.line"
28
27
        'sale_price_unit_tax': fields.float('Sale price W/O taxes'),
29
28
    }
30
29
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
31
 
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
32
 
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
33
 
        tax_obj = self.pool.get('account.tax')
 
30
                          uom=False, qty_uos=0, uos=False, name='', partner_id=False,
 
31
                          lang=False, update_tax=True, date_order=False, packaging=False,
 
32
                          fiscal_position=False, flag=False):
 
33
 
34
34
        result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
35
 
            uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
 
35
                                                                uom, qty_uos, uos, name, partner_id, lang,
 
36
                                                                update_tax, date_order, packaging, fiscal_position, flag)
36
37
        if product:
37
38
            context = {'lang': lang, 'partner_id': partner_id, 'qty': qty}
38
39
            product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context)
82
83
    }
83
84
 
84
85
    def set_default(self, cr, uid, ids, context=None):
85
 
        for o in self.browse(cr, uid, ids, context=context):
86
 
            ir_values_obj = self.pool.get('ir.values')
87
 
            ir_values_obj.set(cr, uid, 'default', False, 'price_type', ['sale.shop'], o.price_type)
 
86
        ir_values_obj = self.pool.get('ir.values')
 
87
        for obj in self.browse(cr, uid, ids, context=context):
 
88
            ir_values_obj.set(cr, uid, 'default', False, 'price_type', ['sale.shop'], obj.price_type)
 
89
 
88
90
        return {
89
 
                'view_type': 'form',
90
 
                "view_mode": 'form',
91
 
                'res_model': 'ir.actions.configuration.wizard',
92
 
                'type': 'ir.actions.act_window',
93
 
                'target': 'new',
94
 
         }
 
91
            'view_type': 'form',
 
92
            "view_mode": 'form',
 
93
            'res_model': 'ir.actions.configuration.wizard',
 
94
            'type': 'ir.actions.act_window',
 
95
            'target': 'new',
 
96
        }
95
97
 
96
98
    def action_cancel(self,cr,uid,ids,conect=None):
97
99
        return {
98
 
                'view_type': 'form',
99
 
                "view_mode": 'form',
100
 
                'res_model': 'ir.actions.configuration.wizard',
101
 
                'type': 'ir.actions.act_window',
102
 
                'target':'new',
 
100
            'view_type': 'form',
 
101
            "view_mode": 'form',
 
102
            'res_model': 'ir.actions.configuration.wizard',
 
103
            'type': 'ir.actions.act_window',
 
104
            'target':'new',
103
105
        }
104
106
 
105
107
sale_shop_price_method_policy()
110
112
    _inherit = "product.product"
111
113
    _description = "Product"
112
114
 
113
 
    def _get_all_values(self, cr, uid, ids, name, arg, context={}):
 
115
    def _get_all_values(self, cr, uid, ids, name, arg, context=None):
114
116
        res = {}
115
 
        product = ids
116
117
        product_obj = self.pool.get('product.product')
117
 
        obj2 = self.pool.get('product.pricelist.item')
118
 
        obj = self.pool.get('product.pricelist')
119
 
        obj3 = self.pool.get('sale.order.line')
 
118
        pricelist_proxy = self.pool.get('product.pricelist')
 
119
        sol_proxy = self.pool.get('sale.order.line')
120
120
        res_partner_obj = self.pool.get("res.partner")
121
 
        for line in product_obj.browse(cr, uid, product, context=context):
 
121
        for line in product_obj.browse(cr, uid, ids, context=context):
 
122
            c_price1, c_price2, list_price1, last_price, qty_last = 0.0, 0.0, 0.0, 0.0, 0.0
 
123
 
122
124
            partner = line.pi_partner_id.id
123
125
            pricelist = line.pi_pricelist_id.id
124
126
            qty1 = line.pi_quantity1
125
127
            qty2 = line.pi_quantity2
126
128
            if pricelist != False:
127
 
                val1 = obj.price_get(cr, uid, [pricelist], line.id, qty1, partner)
128
 
                for key,values  in val1.items():
129
 
                    c_price1 = values
130
 
                val2 = obj.price_get(cr, uid, [pricelist], line.id, qty2, partner)
131
 
                for key,values  in val2.items():
132
 
                    c_price2 = values
133
 
#                item_line = obj2.search(cr,uid,[])
134
 
#                list = []
135
 
#                for line2 in obj2.browse(cr, uid, item_line, context=context):
136
 
#                    if line.id == line2.product_id.id:
137
 
#                        list.append(line.min_quantity)
138
 
#                    if list == []:
139
 
#                        m_qty = 1.0
140
 
#                    else:
141
 
#                        m_qty = max(list)
142
 
#                    val3 = obj.price_get(cr, uid, [pricelist], line.id, m_qty, partner)
143
 
#                    for key,values  in val3.items():
144
 
#                        c_price3 = values
145
 
                    sale_price_list = res_partner_obj.browse(cr, uid, partner).property_product_pricelist.id
146
 
                    val_sale = obj.price_get(cr, uid, [sale_price_list], line.id, qty1, partner)
147
 
                    for key,values  in val_sale.items():
148
 
                        list_price1 = values
149
 
                    read_id = obj3.search(cr,uid,[('product_id','=',line.id)])
150
 
                    if read_id == []:
151
 
                        last_price = 0.0
152
 
                        qty_last = 0.0
153
 
                        last_list_price = 0.0
154
 
                    else:
155
 
                        last_id = max(read_id)
156
 
                        last_brw = obj3.browse(cr,uid,[last_id],context=context)
157
 
                        for rec in last_brw:
158
 
                            product2 = rec.product_id.id
159
 
                            if line.id == product2:
160
 
                                last_price = rec.price_unit
161
 
                                qty_last = rec.product_uom_qty
162
 
#                                val_last = obj.price_get(cr, uid,[pricelist], line.id, qty_last)
163
 
#                                for key,values  in val_last.items():
164
 
#                                    last_list_price = values
165
 
 
166
 
                    for id in ids:
167
 
                        res[id] = {}
168
 
                        if 'pi_customer_prices1' in name:
169
 
                             res[id]['pi_customer_prices1'] = c_price1
170
 
                        if 'pi_customer_prices2' in name:
171
 
                             res[id]['pi_customer_prices2'] = c_price2
172
 
                        if 'pi_list_prices1' in name:
173
 
                             res[id]['pi_list_prices1'] = list_price1
174
 
#                        if 'pi_next_better_price_qty'in name:
175
 
#                             res[id]['pi_next_better_price_qty']= m_qty
176
 
#                        if 'pi_best_price_on_qty'in name:
177
 
#                             res[id]['pi_best_price_on_qty']= c_price3
178
 
                        if 'pi_last_customer_prices'in name:
179
 
                             res[id]['pi_last_customer_prices']= last_price
180
 
#                        if 'pi_last_list_prices'in name:
181
 
#                             res[id]['pi_last_list_prices']= last_list_price
182
 
                        if 'pi_qty_buyed'in name:
183
 
                             res[id]['pi_qty_buyed']= qty_last
184
 
 
185
 
            else:
186
 
                 for id in ids:
187
 
                        res[id] = {}
188
 
                        if 'pi_customer_prices1' in name:
189
 
                             res[id]['pi_customer_prices1'] = 0.0
190
 
                        if 'pi_customer_prices2' in name:
191
 
                            res[id]['pi_customer_prices2'] = 0.0
192
 
                        if 'pi_list_prices1' in name:
193
 
                            res[id]['pi_list_prices1'] = 0.0
194
 
#                        if 'pi_next_better_price_qty'in name:
195
 
#                            res[id]['pi_next_better_price_qty']= 0.0
196
 
#                        if 'pi_best_price_on_qty'in name:
197
 
#                            res[id]['pi_best_price_on_qty']= 0.0
198
 
                        if 'pi_last_customer_prices'in name:
199
 
                            res[id]['pi_last_customer_prices']= 0.0
200
 
#                        if 'pi_last_list_prices'in name:
201
 
#                            res[id]['pi_last_list_prices']= 0.0
202
 
                        if 'pi_qty_buyed'in name:
203
 
                            res[id]['pi_qty_buyed']= 0.0
 
129
                values = pricelist_proxy.price_get(cr, uid, [pricelist], line.id, qty1, partner)
 
130
                c_price1 = values[pricelist]
 
131
 
 
132
                values = pricelist_proxy.price_get(cr, uid, [pricelist], line.id, qty2, partner)
 
133
                c_price2 = values[pricelist]
 
134
 
 
135
                sale_price_list = res_partner_obj.browse(cr, uid, partner).property_product_pricelist.id
 
136
                values = pricelist_proxy.price_get(cr, uid, [sale_price_list], line.id, qty1, partner)
 
137
                list_price1 = values[sale_price_list]
 
138
 
 
139
                read_ids = sol_proxy.search(cr,uid,[('product_id','=',line.id)])
 
140
                last_price, qty_last = 0.0, 0.0
 
141
                if read_ids:
 
142
                    last_id = max(read_ids)
 
143
                    last_brw = sol_proxy.browse(cr,uid,[last_id],context=context)
 
144
                    if line.id == last_brw[0].product_id.id:
 
145
                        last_price = last_brw[0].price_unit
 
146
                        qty_last = last_brw[0].product_uom_qty
 
147
            res[line.id] = {}
 
148
 
 
149
            if 'pi_customer_prices1' in name:
 
150
                 res[line.id]['pi_customer_prices1'] = c_price1 or 0.0
 
151
            if 'pi_customer_prices2' in name:
 
152
                 res[line.id]['pi_customer_prices2'] = c_price2 or 0.0
 
153
            if 'pi_list_prices1' in name:
 
154
                 res[line.id]['pi_list_prices1'] = list_price1 or 0.0
 
155
            if 'pi_last_customer_prices'in name:
 
156
                 res[line.id]['pi_last_customer_prices']= last_price or 0.0
 
157
            if 'pi_qty_buyed'in name:
 
158
                 res[line.id]['pi_qty_buyed']= qty_last or 0.0
 
159
 
204
160
        return res
205
161
 
206
 
    def button_dummy(self, cr, uid, ids, context={}):
 
162
    def button_dummy(self, cr, uid, ids, context=None):
207
163
        return True
208
164
 
209
165
    _columns = {
214
170
        'pi_customer_prices1': fields.function(_get_all_values, method=True, type='float', string='Costomer Prices',multi='pi_customer_prices1',help='Costomer Price For Quantity1 & Quantity2'),
215
171
        'pi_customer_prices2': fields.function(_get_all_values, method=True, type='float', string='Costomer Prices',multi='pi_customer_prices2'),
216
172
        'pi_list_prices1': fields.function(_get_all_values, method=True, type='float', string='List Prices',multi='pi_list_prices1',help= 'Price Of Public Pricelist'),
217
 
#        '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'),
218
 
#        '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'),
219
173
        'pi_last_customer_prices': fields.function(_get_all_values, method=True, type='float', string='Last Costomer Prices',multi='pi_last_customer_prices'),
220
 
#        'pi_last_list_prices': fields.function(_get_all_values, method=True, type='float', string='Last List Prices',multi='pi_last_list_prices'),
221
174
        'pi_qty_buyed': fields.function(_get_all_values, method=True, type='float', string='Quantity Buyed',multi='pi_qty_buyed',help='Last Costomer Buyed Quantity'),
222
 
        }
 
175
    }
223
176
    _defaults = {
224
177
        'pi_quantity1': lambda *a: 1.0,
225
178
        'pi_quantity2': lambda *a: 5.0,
226
 
         }
 
179
    }
227
180
product_product()
228
181