Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
5452 Weergaven

Hello Guys!!

Could anyone help me to this problem please:

I'm in a kanban view and I want to dynamically allow an id in the context (here: service_type_id) and I didn't know how to do this.

(We have several buttons here and they should display their respective views)

<record id="fleet_vehicle_view_kanban_iso" model="ir.ui.view">
    <field name="name">fleet.vehicle.kanban.iso</field>
    <field name="model">fleet.vehicle</field>
    <field name="inherit_id" ref="fleet.fleet_vehicle_view_kanban"/>
    <field name="arch" type="xml">
        <xpath expr="//kanban/templates/t/div/div[2]/ul" position="after">
        <field name="service_type_ids" on_change="1">
        <tree editable="bottom">
            <field name="service_type_id" />
            <field name="name"/>
            <field name="config_kilometrage" readonly="1"/>
            <field name="type_vehicle_iso_id" readonly="1"/>
            <field name="is_renewal_soon"/>
            <field name="is_renewal_almost"/>
            <field name="is_renewal_ok"/>
       </tree>
      </field>
    </xpath>
    <xpath expr="//kanban/templates/t/div/div[2]/ul" position="after">
        <div class="col-md-12">
        <t t-foreach="record.service_type_ids.raw_value" t-as="o">
            <!-- ### RED ### -->
        <t t-if="o.is_renewal_soon">
           <a
            data-type="object"
            data-name="return_action_to_open_"
            style="margin:0.5px;font-size:10px;width:200px"
            href="#"
            class="col-md-5 oe_kanban_action btn btn-sm btn-danger"
            data-context='{"xml_id":"fleet_vehicle_log_services_action","service_type_id":o.service_type_id.id}'
            role="button">
                <t t-esc="o.name"/>
        </a>
        </t>
            <!-- ### YELLOW ### -->
        <t t-if="o.is_renewal_due_almost">
            <a
                data-type="object"
                data-name="return_action_to_open_"
                style="margin:0.5px;font-size:10px;width:200px"
                href="#"
                class="col-md-5 oe_kanban_action btn btn-sm btn-warning"
                data-context='{"xml_id":"fleet_vehicle_log_services_action","service_type_id":o.service_type_id.id}'
                role="button">
                    <t t-esc="o.name" />
                </a>
            </t>
             <!-- ### GREEN ### -->
        <t t-if="o.is_renewal_ok">
              <a
                data-type="object"
                data-name="return_action_to_open_"
                style="margin:0.5px;font-size:10px;width:200px"
                href="#"
                class="col-md-5 oe_kanban_action btn btn-sm btn-success"
                data-context='{"xml_id":"fleet_vehicle_log_services_action","service_type_id":o.service_type_id.id}'
                role="button">
                    <t t-esc="o.name"/>
                    </a>
                </t>
            </t>
          </div>
        </xpath>
    </field>
</record>

 

##### python ######

def return_action_to_open_(self):
""" This opens the xml view specified in xml_id for the current vehicle """
    self.ensure_one()
    xml_id = self.env.context.get('xml_id')
    service_type_id = self.env.context.get('service_type_id')
    if xml_id:
        res = self.env['ir.actions.act_window'].for_xml_id('fleet', xml_id)
        res.update(
        context=dict(self.env.context, default_vehicle_id=self.id, group_by=False),
        domain=[('vehicle_id', '=', self.id),('cost_subtype_id','=',service_type_id)]
        )
        return res
return False
Avatar
Annuleer