Help

0

On create Ticket : How to get Project id and Task Id on smart button action (Ticket)

Avatar
alaoui ikram

Python Code

Problem : When i create a ticket action smart button, i want to get current project id and task id in the view. i tested the code bellow but it doesn't work. and gives the following error :

EOL while scanning string literal ('', 1, 36, "{'project_id': subticket_projet_id'}") None" while parsing file:/d:/odoo 11.0/server/odoo/addons/dev/views/tickets.xml:15, near

class button_Tickets(models.Model):
    
        _name = 'ticket.ticket'
        _rec_name = 'objet'
        _inherit = ['mail.thread', 'mail.activity.mixin']
        _mail_post_access = 'read'
    
        date_heure = fields.Datetime(string='Date de ticket', readonly=True, default=lambda self: fields.datetime.now())
        objet = fields.Selection([('technique', 'Blockage Technique'), ('fonctionnel', 'Bolckage Fonctionnel'), ('odoo', 'Systeme Odoo')])
        demande = fields.Html(String='Demande d\'assistance')
        Date = fields.Datetime(compute='_change_etat_ticket', string='Date Resolution')
        Etat_tickets = fields.Selection([('Non Resolue', 'Non Resolue'), ('res', 'Resolue')], 'Type', default='Non Resolue')
        assigne = fields.Many2one('res.users', string='Assigné à', domain="[('groups_id', 'in', [163])]")
    
        project_id = fields.Many2one('project.project',
                                     string='Project',
                                     default=lambda self: self.env.context.get('default_project_id'),
                                     index=True,
                                     track_visibility='onchange',
                                     change_default=True)
        task_id = fields.Many2one('project.task', string='Tâche')

XML View

<record id="project_views_ticket" model="ir.ui.view">
              <field name="name">project.task.form.inheritss</field>
              <field name="model">project.task</field>
              <field name="inherit_id" ref="project.view_task_form2"/>
              <field name="arch" type="xml">
                  <div class="oe_button_box" name="button_box">
                         <xpath expr="//button[@name='subtask_count']" position="before">
                                 <button name="%(open_tickets_count)d" type="action" class="oe_stat_button" icon="fa-tasks"
                                 context="{'project_id': subticket_projet_id'}">
                                   <field name="ticket_count" string="Tickets" widget="statinfo"/>
                                 </button>
                        </xpath>
                  </div>
              </field>
  </record>

XML Action window

<record id="open_tickets_count" model="ir.actions.act_window">
            <field name="name">Tickets</field>
            <field name="res_model">ticket.ticket</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'default_parent_id' : active_id,
                'default_project_id' : project_id,
                }</field>
            <field name="domain">[]</field>
        </record>

Action button function

@api.multi
    def open_tickets_count(self):
        return {
            'name': _('Tickets'),
            'domain': [],
            'res_model': 'ticket.ticket',
            'type': 'ir.actions.act_window',
            'view_id': False,
            'view_mode': 'tree,form',
            'view_type': 'form',
        }
Avatar
Abaikan
1 Jawaban
0
Best Answer

Hello, 

Replace your xml with below code then error will be solved:

<record id="project_views_ticket" model="ir.ui.view">

              <field name="name">project.task.form.inheritss</field>

              <field name="model">project.task</field>

              <field name="inherit_id" ref="project.view_task_form2"/>

              <field name="arch" type="xml">

                  <div class="oe_button_box" name="button_box">

                         <xpath expr="//button[@name='subtask_count']" position="before">

                                 <button name="%(open_tickets_count)d" type="action" class="oe_stat_button" icon="fa-tasks"

                                 context="{'project_id': 'subticket_projet_id'}">

                                   <field name="ticket_count" string="Tickets" widget="statinfo"/>

                                 </button>

                        </xpath>

                  </div>

              </field>

  </record>

Thank You!

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Abaikan