b94111ac868e068f28023adaff85e4c11c157e88
[odoo/odoo.git] / addons / website_event_sale / models / sale_order.py
1 # -*- coding: utf-8 -*-
2 from openerp.osv import osv
3 from openerp import SUPERUSER_ID
4 from openerp.addons.web.http import request
5
6
7 class sale_order_line(osv.osv):
8     _inherit = "sale.order.line"
9
10     def _recalculate_product_values(self, cr, uid, ids, product_id=0, context=None):
11         if not ids:
12             return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, context=context)
13
14         order_line = self.browse(cr, SUPERUSER_ID, ids[0], context=context)
15         assert order_line.order_id.website_session_id == request.httprequest.session['website_session_id']
16
17         product = product_id and self.pool.get('product.product').browse(cr, uid, product_id, context=context) or order_line.product_id
18         res = super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product.id, context=context)
19         if product.event_type_id and order_line.event_ticket_id and order_line.event_ticket_id.price != product.lst_price:
20             res.update({'price_unit': order_line.event_ticket_id.price})
21
22         return res