Skip to Content
Menu
This question has been flagged
2794 Views

I use odoo 10 and I created a custom module to plan trips. I create a view for the plans in which I will select the list of my travels. My problem now is how I can get the Start and Destination fields of each trip insert in this view knowing that the field that displays the list of trips is travel_ids = fields.Many2many ('tms.travel', copy = False, string = 'Travels'). I try a lot but no result. Any idea for help please ??

here is a picture link :https://ibb.co/fGgtfV

tms_travel_planning.xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>

    <record id="view_tms_travel_planning_form" model="ir.ui.view">
        <field name="name">view.tms.travel.planning.form</field>
        <field name="model">tms.planning</field>
        <field name="arch" type="xml">
            <form string="Plannification des voyage">
                <header>
                    <field name="state" statusbar_visible="draft,approved,confirmed" widget="statusbar"/>
                </header>
                <sheet>
                <div class="oe_title">
                    <h1>
                        <label class="oe_inline" style="font-size:30px;" string="Plannification - " attrs="{'invisible':[('name','=', False)]}"/>
                        <field name="name" readonly="1"/>
                    </h1>
                </div>
                <group>
                    <group>

                        <field name="datetime"/>
                        <field attrs="{'readonly':[('state','in',('confirmed', 'cancel'))]}" name="operating_unit_id"/>
                    </group>

                    <group>
                        <field name="num_vehicule_dispo"/>
                        <field name="num_chauffeur_dispo"/>

                    </group>
                </group>
                <notebook colspan="1">
                    <page string="Les voyages à planifier">
                        <separator coslpan="4" string="Voyages"/>
                        <!--<field attrs="{'readonly':[('state','in',('confirmed', 'cancel'))]}" name="operating_unit_id"/>-->
                        <field attrs="{'readonly':[('state','in',('confirmed', 'cancel'))]}" colspan="4"
                               domain="[('state','not in',('cancel','closed'))]" name="travel_ids" nolabel="1"/>
                        <separator coslpan="4" string="Véhicules"/>
                        <field  colspan="4" name="fleet_ids" nolabel="1"/>
                        <separator coslpan="4" string="Conducteurs"/>
                        <field  colspan="4" name="employee_ids" nolabel="1"/>

                    </page>

                </notebook>
                </sheet>
            </form>
        </field>
    </record>
</data>
 </odoo>

tms_travel_planning.py

 # -*- coding: utf-8 -*-

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class TmsTravelPlanning(models.Model):
_name = 'tms.planning'

name = fields.Char('Num du plannification')
operating_unit_id = fields.Many2one(
    'operating.unit', string='Operating Unit', required=True)
id_planning=fields.Integer(string="Numéro du plannification")
datetime=fields.Date(string="Date")
num_vehicule_dispo=fields.Integer(string="Nombre de véhicule disponible")
num_chauffeur_dispo=fields.Integer(string="Nombre de chauffeur disponible")
tms
fleet_ids = fields.Many2many('fleet.vehicle', copy=False, string='Véhicules')
employee_ids = fields.Many2many('hr.employee', copy=False, string='Conducteurs')

state = fields.Selection([
    ('draft', 'Pending'),
    ('approved', 'Approved'),
    ('confirmed', 'Confirmed'),
    ('cancel', 'Cancelled')], readonly=True,
    help="Gives the state of the Waybill.",
    default='draft')

@api.model
def create(self, values):
    planning = super(TmsTravelPlanning, self).create(values)
    if not planning.operating_unit_id.planning_sequence_id:
        raise ValidationError(_(
            'You need to define the sequence for planning in base %s' %
            planning.operating_unit_id.name
        ))
    sequence = planning.operating_unit_id.planning_sequence_id
    planning.name = sequence.next_by_id()
    print(str(values['num_vehicule_dispo']))
    print(str(values['num_chauffeur_dispo']))
    return planning

tms_travel.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <odoo>
    <record id="view_tms_travel_tree" model="ir.ui.view">
          <field name="name">tms.travel.tree</field>
            <field name="model">tms.travel</field>
         <field name="priority">1</field>
         <field name="arch" type="xml">
            <tree>
                 <field name="name"/>
                <field name="date"/>
              <field name="departure_id"/>
                 <field name="arrival_id"/>
                  <field name="state"/>
                 <button groups="tms.group_traffic,tms.group_expenses" icon="fa-thumbs-up" name="action_progress" states="draft" string="Dispatch Travel" type="object"/>
            <button groups="tms.group_traffic,tms.group_expenses" icon="fa-check-square" name="action_end" states="progress" string="End Travel" type="object"/>
        </tree>
    </field>
</record>
</odoo>
Avatar
Discard
Related Posts Replies Views Activity
0
Dec 24
41
2
Oct 24
216
1
Aug 24
573
2
Jul 24
267
1
Jul 24
287