1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20
##############################################################################
21
from osv import osv, fields
22
from tools.translate import _
24
class sale_extended_wizard(osv.osv_memory):
25
_name = "sale.extended.wizard"
26
_description = "Sale Extended wizard"
28
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True)
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
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!'))
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)
51
raise osv.except_osv(_('Warning'),_('PriceList cannot be changed! Make sure the Sale Order is in "Quotation" state!'))
54
sale_extended_wizard()
56
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'