wizard_sale_pricelist_recalculation.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 openerp.osv import osv, fields
  22. from openerp.tools import translate
  23. class sale_extended_wizard(osv.osv_memory):
  24. _name = "sale.extended.wizard"
  25. _description = "Sale Extended wizard"
  26. _columns = {
  27. 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, domain=[('type','=','sale')])
  28. }
  29. def change_pricelist_products(self, cr, uid, ids, context):
  30. obj_curr = self.browse(cr, uid, ids, context)[0]
  31. order_line_obj = self.pool.get('sale.order.line')
  32. sale_order_pool = self.pool.get('sale.order')
  33. pricelist_id = obj_curr['pricelist_id']
  34. sale_obj = sale_order_pool.browse(cr, uid, context['active_id'], context)
  35. partner_id = sale_obj.partner_id.id
  36. date_order = sale_obj.date_order
  37. if sale_obj.pricelist_id.id == pricelist_id.id:
  38. raise osv.except_osv(_('Warning'),_('The Pricelist is already applied to the sales order!'))
  39. if sale_obj['state'] == 'draft':
  40. sale_order_pool.write(cr, uid, context['active_id'], {'pricelist_id': pricelist_id.id})
  41. for line in sale_obj.order_line:
  42. 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)
  43. if vals.get('value',False):
  44. if 'price_unit' in vals['value'].keys():
  45. order_line_obj.write(cr, uid, line.id, {'price_unit': vals['value']['price_unit']},context=context)
  46. else:
  47. raise osv.except_osv(_('Warning'),_('PriceList cannot be changed! Make sure the Sales Order is in "Quotation" state!'))
  48. return {}
  49. sale_extended_wizard()