You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Order Pricelist Change for Odoo
  5. # Copyright (C) 2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.osv.orm import Model
  23. from openerp.tools.translate import _
  24. class pos_order(Model):
  25. _inherit = 'pos.order'
  26. def action_recompute_pricelist(self, cr, uid, ids, context=None):
  27. pol_obj = self.pool.get('pos.order.line')
  28. for po in self.browse(cr, uid, ids, context=context):
  29. for pol in po.lines:
  30. res = pol_obj.onchange_product_id(
  31. cr, uid, [pol.id], po.pricelist_id.id, pol.product_id.id,
  32. pol.qty, po.partner_id.id)
  33. if res['value']['price_unit'] != pol.price_unit:
  34. pol_obj.write(
  35. cr, uid, [pol.id], res['value'], context=context)
  36. def onchange_pricelist_id(
  37. self, cr, uid, ids, pricelist_id, lines, context=None):
  38. if not pricelist_id or not lines:
  39. return {}
  40. warning = {
  41. 'title': _('Pricelist Warning!'),
  42. 'message': _(
  43. """If you change the pricelist of this order,"""
  44. """ prices of existing order lines will not be updated."""
  45. """ Please click on the 'Recompute With Pricelist'.""")
  46. }
  47. return {'warning': warning}