[IMP]GOLEM Activity : new fields, enhancements in namings, default name...

This commit is contained in:
Fabien Bourgeois 2016-06-27 17:53:10 +02:00
parent af825ab8ba
commit 03ed5e1719
2 changed files with 54 additions and 36 deletions

View File

@ -22,11 +22,7 @@ class ProductTemplate(models.Model):
_inherit = 'product.template'
# Make default service for type
type = fields.Selection([('consu', 'Consumable'), ('service', 'Service')],
'Product Type', default='service', required=True,
help="Consumable are product where you don't "
"manage stock, a service is a non-material "
"product provided by a company or an individual.")
type = fields.Selection(default='service')
class GolemActivity(models.Model):
@ -34,33 +30,34 @@ class GolemActivity(models.Model):
_description = 'GOLEM Activity'
_inherit = 'mail.thread'
_inherits = {'product.template': 'product_id'}
_rec_name = 'activity_name'
season_id = fields.Many2one('golem.season', string='Seasons',
required=True)
animator = fields.Many2one('res.partner', string="Animator",
domain=[('is_company', '=', False)])
animator_id = fields.Many2one('res.partner', string="Animator",
domain=[('is_company', '=', False)])
places = fields.Integer('Places', default=0)
is_surcharged = fields.Boolean('Allow surcharge?', default=False)
places_surcharged = fields.Integer('Places with surcharge', default=0)
is_overbooked = fields.Boolean('Allow overbook?', default=False)
places_overbooked = fields.Integer('Places with overbook', default=0)
@api.onchange('is_surcharged', 'places')
def onchange_is_surcharged(self):
@api.onchange('is_overbooked', 'places')
def onchange_is_overbooked(self):
for a in self:
if a.places and a.is_surcharged:
if not a.places_surcharged or (a.places_surcharged < a.places):
a.places_surcharged = a.places
if a.places and a.is_overbooked:
if not a.places_overbooked or (a.places_overbooked < a.places):
a.places_overbooked = a.places + 1
@api.constrains('places', 'places_surcharged')
@api.constrains('places', 'places_overbooked')
def _check_places(self):
""" Check integers are signed and surcharged to be superior than
""" Check integers are signed and overbooked to be superior than
normal places """
for v in self:
for f in ['places', 'places_surcharged']:
for f in ['places', 'places_overbooked']:
if v[f] < 0:
emsg = _('Number of places cannot be negative.')
raise models.ValidationError(emsg)
if v.places < v.places_surcharged:
emsg = _('Surcharged places cannot be inferieur than places')
if v.is_overbooked and (v.places_overbooked <= v.places):
emsg = _('Overbooked places cannot be inferior than places')
raise models.ValidationError(emsg)
date_start = fields.Date('Start date')
@ -100,3 +97,16 @@ class GolemActivity(models.Model):
default_season = self.env['golem.season'].search(domain)
for a in self:
a.is_current = (default_season == a.season_id)
activity_name = fields.Char('Name', compute='_compute_name', store=True,
index=True)
@api.depends('name', 'default_code')
def _compute_name(self):
""" Provide a better displayed name """
for a in self:
activity_name = unicode(a.name)
if a.default_code:
activity_name = u'[{}] {}'.format(a.default_code,
activity_name)
a.activity_name = activity_name

View File

@ -25,7 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="arch" type="xml">
<form>
<sheet>
<group>
<div class="oe_right oe_button_box" style="width: 300px;"
name="buttons"></div>
<div class="oe_left" style="width: 500px;">
<field name="image_medium" widget="image"
class="oe_avatar oe_left"/>
@ -37,29 +38,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group>
<field name="season_id" />
</group>
</group>
<group string="Details" col="4">
<group colspan="2">
<field name="default_code" />
<field name="animator" />
<field name="categ_id" />
<field name="animator_id" />
<field name="list_price" />
</group>
<group colspan="2">
<field name="places" />
<field name="is_surcharged" />
<field name="places_surcharged"
attrs="{'invisible': [('is_surcharged', '=', False)]}" />
<field name="is_overbooked" />
<field name="places_overbooked"
attrs="{'invisible': [('is_overbooked', '=', False)]}" />
<field name="date_start" />
<field name="date_end" />
</group>
</group>
<notebook>
<page name="activity_info" string="Information">
<group colspan="4">
<group>
<field name="active"/>
</group>
</group>
<group colspan="4">
<field name="description" placeholder="describe the activity characteristics..."/>
</group>
@ -88,7 +84,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="model">golem.activity</field>
<field name="arch" type="xml">
<search>
<field name="name" />
<field name="activity_name" />
<field name="season_id" widget="many2one" />
<filter name="season_default" string="Default season"
domain="[('is_current', '=', True)]" />
@ -98,16 +94,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Actions -->
<act_window id="action"
name="GOLEM Activities"
res_model="golem.activity"
view_mode="kanban,tree,form"
context="{'search_default_season_default': True}" />
<record id="action" model="ir.actions.act_window">
<field name="name">GOLEM Activities</field>
<field name="res_model">golem.activity</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain" eval="[('categ_id', 'child_of', ref('golem_activity.golem_product_category_all_activities'))]" />
<field name="context"
eval="{'search_default_season_default': True, 'default_categ_id': ref('golem_activity.golem_product_category_all_activities')}" />
</record>
<record model="ir.actions.act_window.view" id="act_view_kanban">
<field name="view_mode">kanban</field>
<field name="view_id" ref="product.product_template_kanban_view"/>
<field name="act_window_id" ref="action"/>
</record>
<record id="category_action" model="ir.actions.act_window">
<field name="name">Activities Categories</field>
<field name="res_model">product.category</field>
<field name="view_type">form</field>
<field name="view_id" ref="product.product_category_list_view" />
</record>
<!-- Menus -->
<menuitem id="activity_menu" name="Activities"
@ -115,6 +120,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<menuitem id="activity_list" name="List"
parent="activity_menu" sequence="0"
action="action" />
<menuitem id="activity_categ" name="Activities categories"
parent="activity_menu" sequence="10"
action="category_action" />
</data>
</openerp>