[FIX] event_sale: workaround for broken view.
Non-stored fields created with the new API are not converted to old fields and added in `_columns` (and thus `_all_columns`). This forbid them to be used in qweb views. A fix will be commited in 8.0 to address this issue.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from openerp import models, fields, api, _
|
||||
import openerp.addons.decimal_precision as dp
|
||||
from openerp.exceptions import Warning
|
||||
from openerp.osv import fields as old_fields
|
||||
|
||||
|
||||
class event_event(models.Model):
|
||||
@@ -51,8 +52,6 @@ class event_ticket(models.Model):
|
||||
default=lambda self: self._default_product_id())
|
||||
registration_ids = fields.One2many('event.registration', 'event_ticket_id', 'Registrations')
|
||||
price = fields.Float('Price', digits=dp.get_precision('Product Price'))
|
||||
price_reduce = fields.Float("Price Reduce", compute="_get_price_compute", store=False,
|
||||
digits=dp.get_precision('Product Price'))
|
||||
deadline = fields.Date("Sales End")
|
||||
is_expired = fields.Boolean('Is Expired', compute='_is_expired', store=True)
|
||||
|
||||
@@ -74,13 +73,32 @@ class event_ticket(models.Model):
|
||||
current_date = fields.Date.context_today(self.with_context({'tz': self.event_id.date_tz}))
|
||||
self.is_expired = self.deadline < current_date
|
||||
|
||||
# FIXME non-stored fields wont ends up in _columns (and thus _all_columns), which forbid them
|
||||
# to be used in qweb views. Waiting a fix, we create an old function field directly.
|
||||
"""
|
||||
price_reduce = fields.Float("Price Reduce", compute="_get_price_reduce", store=False,
|
||||
digits=dp.get_precision('Product Price'))
|
||||
@api.one
|
||||
@api.depends('price', 'product_id.lst_price', 'product_id.price')
|
||||
def _get_price_compute(self):
|
||||
def _get_price_reduce(self):
|
||||
product = self.product_id
|
||||
discount = product.lst_price and (product.lst_price - product.price) / product.lst_price or 0.0
|
||||
self.price_reduce = (1.0 - discount) * self.price
|
||||
"""
|
||||
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 = {
|
||||
'price_reduce': old_fields.function(_get_price_reduce, type='float', string='Price Reduce',
|
||||
digits_compute=dp.get_precision('Product Price')),
|
||||
}
|
||||
|
||||
# seats fields
|
||||
seats_max = fields.Integer('Maximum Available Seats', 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.Integer(string='Reserved Seats', compute='_compute_seats', store=True)
|
||||
seats_available = fields.Integer(string='Available Seats', compute='_compute_seats', store=True)
|
||||
|
||||
Reference in New Issue
Block a user