diff --git a/models/calendar.py b/models/calendar.py index fda0c8e7b1c45337c8b467e5e6de9e0a33ec3fb8..80a5d4dd98ab6ee48bb006d17998e52b2f0bca1c 100644 --- a/models/calendar.py +++ b/models/calendar.py @@ -42,6 +42,9 @@ class CGScopCalendar(models.Model): ur_financial_system_id = fields.Many2one( comodel_name='ur.financial.system', string='Dispositif Financier') + ur_regional_convention_id = fields.Many2one( + comodel_name='ur.regional.convention', + string='Convention Régionale') ur_id = fields.Many2one( 'union.regionale', string='Union Régionale', @@ -50,18 +53,27 @@ class CGScopCalendar(models.Model): default=_default_ur) ur_financial_system_nb = fields.Integer( string="Nb Dispositifs Financiers", - compute="_compute_ur_financial_system_nb") + compute="_compute_ur_system_nb") + ur_regional_convention_nb = fields.Integer( + string="Nb conventions régionales", + compute="_compute_ur_system_nb") # ------------------------------------------------------ # Compute # ------------------------------------------------------ @api.depends('ur_id') - def _compute_ur_financial_system_nb(self): + def _compute_ur_system_nb(self): for event in self: + # Calcul nombre de dispositifs financiers financial_system = event.env['ur.financial.system'].search([ ('ur_id', '=', event.ur_id.id)]) event.ur_financial_system_nb = len( financial_system) + # Calcul nombre de conventions + regional_convention = event.env['ur.regional.convention'].search([ + ('ur_id', '=', event.ur_id.id)]) + event.ur_regional_convention_nb = len( + regional_convention) # ------------------------------------------------------ # Onchange @@ -85,6 +97,12 @@ class CGScopCalendar(models.Model): if self.coop_id.city: address += self.coop_id.city self.location = address + if not self.coop_id.ur_financial_system_date or \ + fields.Datetime.now() > self.coop_id.ur_financial_system_date: + self.ur_financial_system_id = self.coop_id.ur_financial_system_id + if not self.coop_id.ur_regional_convention_date or \ + fields.Datetime.now() > self.coop_id.ur_regional_convention_date: + self.ur_regional_convention_id = self.coop_id.ur_regional_convention_id # ------------------------------------------------------ # Fonction boutons @@ -109,4 +127,33 @@ class CGScopCalendar(models.Model): 'unit_amount': event.duration if not event.allday else 8.0, 'partner_id': event.coop_id.id, }) - # event.is_transfered = True + + @api.multi + def duplicate_entry(self): + """ + Duplique la ligne de temps + """ + for event in self: + return { + 'type': 'ir.actions.act_window', + 'res_model': 'calendar.event', + 'view_type': 'form', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_project_id': event.project_id.id, + 'default_name': event.name, + 'default_coop_id': event.coop_id.id, + 'default_partner_ids': event.partner_ids.ids, + 'default_start': event.start, + 'default_duration': event.duration, + 'default_stop': event.stop, + 'default_allday': event.allday, + 'default_type': event.type, + 'default_ur_financial_system_id': event.ur_financial_system_id.id, + }, + 'flags': {'form': { + 'action_buttons': False, + 'options': { + 'mode': 'edit'}}}, + } diff --git a/views/calendar.xml b/views/calendar.xml index 613d27657c32d3aa8d3f11d2fd498af3dbaf916b..446fda12a162cc6cdf0ece07652046da62a600f7 100644 --- a/views/calendar.xml +++ b/views/calendar.xml @@ -18,10 +18,13 @@ <attribute name="invisible">True</attribute> </field> <field name="location" position="after"> + <field name="ur_regional_convention_nb" invisible="1"/> + <field name="ur_financial_system_nb" invisible="1"/> <field name="coop_id"/> <field name="project_id"/> <field name="type"/> - <field name="ur_financial_system_id" options="{'no_open': True, 'no_create': True}" /> + <field name="ur_financial_system_id" options="{'no_open': True, 'no_create': True}" attrs="{'required':[('ur_financial_system_nb', '>', 0)], 'invisible':[('ur_financial_system_nb', '<', 1)]}"/> + <field name="ur_regional_convention_id" options="{'no_open': True, 'no_create': True}" attrs="{'required':[('ur_regional_convention_nb', '>', 0)], 'invisible':[('ur_regional_convention_nb', '<', 1)]}"/> </field> </field> </record> @@ -36,6 +39,12 @@ <!-- Header --> <sheet position="before"> <header> + <button + string="Dupliquer" + type="object" + name="duplicate_entry" + class="oe_highlight" + /> <button string="Transformer en ligne de temps" type="object" @@ -91,7 +100,9 @@ <field name="type" /> <field name="location" /> <field name="ur_financial_system_nb" invisible="1"/> - <field name="ur_financial_system_id" options="{'no_open': True, 'no_create': True}" attrs="{'required':[('ur_financial_system_nb', '>', 0)]}"/> + <field name="ur_regional_convention_nb" invisible="1"/> + <field name="ur_financial_system_id" options="{'no_open': True, 'no_create': True}" attrs="{'required':[('ur_financial_system_nb', '>', 0)], 'invisible':[('ur_financial_system_id', '=', 0)]}"/> + <field name="ur_regional_convention_id" options="{'no_open': True, 'no_create': True}" attrs="{'required':[('ur_regional_convention_nb', '>', 0)], 'invisible':[('ur_regional_convention_nb', '=', 0)]}"/> </group> </group> <group string="Informations complémentaires" name="event_extra_info">