[FIX] website_event_sale: display the discounted price in website.

Add price_reduce compute method on ticket and sale order line
This commit is contained in:
Christophe Matthieu 2014-10-24 14:16:16 +02:00 committed by Denis Ledoux
parent 1a5bfdc055
commit 23f9736372
7 changed files with 52 additions and 20 deletions

View File

@ -23,6 +23,7 @@ from openerp import api
from openerp.fields import Integer, One2many, Html
from openerp.osv import fields, osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
class product_template(osv.osv):
_inherit = 'product.template'
@ -180,7 +181,14 @@ class event_ticket(osv.osv):
current_date = fields.date.context_today(self, cr, uid, context=context)
return {ticket.id: ticket.deadline and ticket.deadline < current_date
for ticket in self.browse(cr, uid, ids, context=context)}
def _get_price_reduce(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, 0.0)
for ticket in self.browse(cr, uid, ids, context=context):
product = ticket.product_id
discount = product.lst_price and (product.lst_price - product.price) / product.lst_price or 0.0
res[ticket.id] = (1.0-discount) * ticket.price
return res
_columns = {
'name': fields.char('Name', required=True, translate=True),
@ -189,7 +197,8 @@ class event_ticket(osv.osv):
'registration_ids': fields.one2many('event.registration', 'event_ticket_id', 'Registrations'),
'deadline': fields.date("Sales End"),
'is_expired': fields.function(_is_expired, type='boolean', string='Is Expired'),
'price': fields.float('Price'),
'price': fields.float('Price', digits_compute=dp.get_precision('Product Price')),
'price_reduce': fields.function(_get_price_reduce, type='float', string='Price Reduce', digits_compute=dp.get_precision('Product Price')),
'seats_max': fields.integer('Maximum Available Seats', oldname='register_max', help="You can for each event define a maximum registration level. If you have too much registrations you are not able to confirm your event. (put 0 to ignore this rule )"),
'seats_reserved': fields.function(_get_seats, string='Reserved Seats', type='integer', multi='seats_reserved'),
'seats_available': fields.function(_get_seats, string='Available Seats', type='integer', multi='seats_reserved'),

View File

@ -843,6 +843,11 @@ class sale_order_line(osv.osv):
WHERE rel.invoice_id = ANY(%s)""", (list(ids),))
return [i[0] for i in cr.fetchall()]
def _get_price_reduce(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, 0.0)
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.price_subtotal / line.product_uom_qty
return res
_name = 'sale.order.line'
_description = 'Sales Order Line'
@ -859,6 +864,7 @@ class sale_order_line(osv.osv):
}),
'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]}),
'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')),
'price_reduce': fields.function(_get_price_reduce, type='float', string='Price Reduce', digits_compute=dp.get_precision('Product Price')),
'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}),
'address_allotment_id': fields.many2one('res.partner', 'Allotment Partner',help="A partner to whom the particular product needs to be allotted."),
'product_uom_qty': fields.float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]}),

View File

@ -23,11 +23,22 @@ from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website_event.controllers.main import website_event
from openerp.addons.website_sale.controllers.main import get_pricelist
from openerp.tools.translate import _
class website_event(website_event):
@http.route(['/event/<model("event.event"):event>/register'], type='http', auth="public", website=True)
def event_register(self, event, **post):
pricelist_id = int(get_pricelist())
values = {
'event': event.with_context(pricelist=pricelist_id),
'main_object': event.with_context(pricelist=pricelist_id),
'range': range,
}
return request.website.render("website_event.event_description_full", values)
@http.route(['/event/cart/update'], type='http', auth="public", methods=['POST'], website=True)
def cart_update(self, event_id, **post):
cr, uid, context = request.cr, request.uid, request.context

View File

@ -2,6 +2,7 @@
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
# defined for access rules
class sale_order(osv.Model):

View File

@ -19,12 +19,6 @@
</xpath>
</template>
<template id="cart" inherit_id="website_sale.cart" name="My Cart Event's Price">
<xpath expr="//td[@name='price']/t" position="attributes">
<attribute name="t-if">abs(line.product_id.lst_price - line.price_unit) &gt; 0.2 and not line.product_id.event_ok</attribute>
</xpath>
</template>
<template id="event_description_full" inherit_id="website_event.event_description_full" customize_show="True" name="Event's Ticket form">
<xpath expr="//div[@t-field='event.description']" position="before">
<form t-attf-action="/event/cart/update?event_id=#{ event.id }" method="post" t-if="event.event_ticket_ids">
@ -47,7 +41,15 @@
</td>
<td><span itemprop="priceValidUntil" t-field="ticket.deadline"/></td>
<td>
<t t-if="ticket.price or editable"><span t-field="ticket.price" t-field-options='{
<t t-if="ticket.price or editable">
<t t-if="(ticket.price-ticket.price_reduce) &gt; 1">
<del class="text-danger" style="white-space: nowrap;" t-field="ticket.price" t-field-options='{
"widget": "monetary",
"from_currency": "website.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
</t>
<span t-field="ticket.price_reduce" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>

View File

@ -102,17 +102,20 @@ class QueryURL(object):
return path
def get_pricelist():
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
sale_order = context.get('sale_order')
if sale_order:
pricelist = sale_order.pricelist_id
else:
partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
pricelist = partner.property_product_pricelist
return pricelist
class website_sale(http.Controller):
def get_pricelist(self):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
sale_order = context.get('sale_order')
if sale_order:
pricelist = sale_order.pricelist_id
else:
partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
pricelist = partner.property_product_pricelist
return pricelist
return get_pricelist()
def get_attribute_value_ids(self, product):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry

View File

@ -683,15 +683,15 @@
<div class="text-muted" t-field="line.name"/>
</td>
<td class="text-center" name="price">
<t t-if="(compute_currency(line.product_id.lst_price) - line.price_unit) &gt; 0.01">
<t t-if="(line.price_unit - line.price_reduce) &gt; 1">
<del class="text-danger" style="white-space: nowrap;"
t-field="line.product_id.lst_price" t-field-options='{
t-field="line.price_unit" t-field-options='{
"widget": "monetary",
"from_currency": "website.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>&amp;nbsp;
</t>
<span t-field="line.price_unit" style="white-space: nowrap;" t-field-options='{
<span t-field="line.price_reduce" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
}'/>