~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to sale_pricelist_recalculation/wizard/wizard_sale_pricelist_recalculation.py

  • Committer: DHS(OpenERP)
  • Date: 2011-01-06 07:11:49 UTC
  • mto: This revision was merged to the branch mainline in revision 5146.
  • Revision ID: dhs@tinyerp.com-20110106071149-izff0vluqz0tovd5
[ADD] Added a module called sale_pricelist_recalculation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
from osv import osv, fields
 
22
from tools.translate import _
 
23
 
 
24
class sale_extended_wizard(osv.osv_memory):
 
25
    _name = "sale.extended.wizard"
 
26
    _description = "Sale Extended wizard"
 
27
    _columns = {
 
28
        'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True)
 
29
    }
 
30
 
 
31
    def change_pricelist_products(self, cr, uid, ids, context):
 
32
        obj_curr = self.browse(cr, uid, ids, context)[0]
 
33
        order_line_obj = self.pool.get('sale.order.line')
 
34
        sale_oder_pool = self.pool.get('sale.order')
 
35
        pricelist_id = obj_curr['pricelist_id']
 
36
        sale_obj = sale_oder_pool.browse(cr, uid, context['active_id'], context)
 
37
        partner_id = sale_obj.partner_id.id
 
38
        date_order = sale_obj.date_order
 
39
 
 
40
        if sale_obj.pricelist_id.id == pricelist_id.id:
 
41
            raise osv.except_osv(_('Warning'),_('The Pricelist is already applied to the sale order!'))
 
42
 
 
43
        if sale_obj['state'] == 'draft':
 
44
            sale_oder_pool.write(cr, uid, context['active_id'], {'pricelist_id': pricelist_id.id})
 
45
            for line in sale_obj.order_line:
 
46
                vals = order_line_obj.product_id_change(cr, uid, line.id, pricelist_id.id, line.product_id.id ,qty=line.product_uom_qty,uom=line.product_uom.id,uos=line.product_uos.id, partner_id=partner_id, date_order=date_order)
 
47
                if vals.get('value',False):
 
48
                    if 'price_unit' in vals['value'].keys():
 
49
                        order_line_obj.write(cr, uid, line.id, {'price_unit': vals['value']['price_unit']},context=context)
 
50
        else:
 
51
            raise osv.except_osv(_('Warning'),_('PriceList cannot be changed! Make sure the Sale Order is in "Quotation" state!'))
 
52
        return {}
 
53
 
 
54
sale_extended_wizard()
 
55
 
 
56
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'