Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
1043 Переглядів

how to automatically create a unique chassis number, consisting of

1️⃣ VIN (Vehicle Identification Number) Structure

General Format:

MG3-VDS-VIS (17 characters in total)

________________________________________

1.1 WMI (World Manufacturer Identifier)

- 3 characters

MG3

- M = Asia

- G = Indonesia

- 3 = PT Marlip Indo Mandiri

________________________________________

1.2 VDS (Vehicle Descriptor Section)

- 6 characters

Format: V-K-MMM

- V = Vehicle Type Code

- K = Battery Capacity Code

- MMM = Vehicle Model Code

V/VEHICLE TYPE CODE:

L1 = 2 Wheel Max speed 50km/h

L2 = 3 Wheel max speed 50km/h

L3 = Wheel 2 Speed More than 50km / hour

L4 = 3 Wheel Speed More than 50km/hour

L5 = Custom 2 Wheel & 3 Wheel

M1 = Passenger Car Max 8 seats

M2 = Passenger Car 8-23 seats

M3 = Passenger Car More than 23 seats

N1 = Goods Car GVW Max 3500kg

N2 = Goods Car GVW More than 3500kg & Max 12000kg

N3 = Goods Car GVW Over 12000kg

D/Code Battery Capacity:

S = 1 - 6 kWh

M = 6.1 - 20 kWh

L = 20.1 - 120 kWh

H = More than 120kWh

S/Vehicle Model Code:

MSP = Motor Sport

MSK = Motor Scooter

MTR = Trail Motorcycle

MCS = Custom Motorcycle

M3K = Cargo 3 Wheel Motorcycle

M3P = Passenger 3 Wheel Motorcycle

M3S = Multipurpose 3 Wheel Motorcycle

MCC = City Car

MSH = Sedan & Hatchback Car

MPV = Multy Purpose Car

MSU = Sport Utility Car

MBS = Micro Bus Shuttle

MBL = Micro Bus Ramp

MBM = Medium Bus Car

MBB = Large Bus Car

UCP = Urban Cargo Pickup

UCL = Urban Cargo Platform

TR1 = Light Truck Platform

TR4 = 4x4 Truck Platform

Example:

- M2LMBM = 8-23 seat passenger car, 20.1-120kWh Battery, Medium Bus Model

________________________________________

1.3 VIS (Vehicle Identifier Section) - 8 characters

Format: Y-L-SSSSS

- Y = Year of Production (S = 2025)

- L = Production Location (J = West Java)

- SSSSS = Production Serial Number (00001 to 99999)

Example VIS: SJ00001

Complete VIN Example: MG3M2LMBMSJ00001


Аватар
Відмінити
Найкраща відповідь

Hi,

Please refer to the code:


from odoo import models, fields, api


class Vehicle(models.Model):

    _name = 'fleet.vehicle'

    _description = 'Vehicle'


    name = fields.Char('VIN', copy=False, readonly=True)

    vehicle_type = fields.Selection([

        ('L1', '2 Wheel Max 50km/h'),

        ('L2', '3 Wheel Max 50km/h'),

        ('M2', 'Passenger 8-23 seats'),

        # add all types...

    ])

    battery_code = fields.Selection([

        ('S', '1-6 kWh'),

        ('M', '6.1-20 kWh'),

        ('L', '20.1-120 kWh'),

        ('H', 'More than 120 kWh'),

    ])

    model_code = fields.Selection([

        ('MSP', 'Motor Sport'), ('MCS', 'Custom Motorcycle'),

        ('MBM', 'Medium Bus Car'),

        # add all model codes...

    ])

    production_year = fields.Integer('Year of Production', default=2025)

    production_location = fields.Selection([

        ('J', 'West Java'), ('B', 'Jakarta'),  # etc.

    ])


    @api.model

    def create(self, vals):

        record = super().create(vals)

        # Step 1: WMI

        wmi = 'MG3'

        # Step 2: VDS

        vds = f"{record.vehicle_type}{record.battery_code}{record.model_code}"

        # Step 3: VIS

        year_map = {2025: 'S', 2026: 'T'}  # map years to letters

        year_code = year_map.get(record.production_year, 'X')

        loc_code = record.production_location or 'X'


        # Find last serial number for same year + location

        last_serial = self.env['fleet.vehicle'].search([

            ('production_year', '=', record.production_year),

            ('production_location', '=', record.production_location)

        ], order='id desc', limit=1).name


        if last_serial:

            # extract last 5 digits

            last_num = int(last_serial[-5:])

            serial = str(last_num + 1).zfill(5)

        else:

            serial = '00001'


        vis = f"{year_code}{loc_code}{serial}"

        vin = f"{wmi}{vds}{vis}"


        record.name = vin

        return record



Hope it helps.

Аватар
Відмінити
Найкраща відповідь
  1. Fixed WMI: "MG3" (constant).
  2. VDS: Built from three input fields:
    • Vehicle Type Code (e.g. "M2")
    • Battery Capacity Code (e.g. "L")
    • Vehicle Model Code (e.g. "MBM")
  3. VIS: Constructed as:
    • Year code "S" for 2025 (map your production year to letter)
    • Location code (e.g. "J")
    • Serial number: a 5-digit zero-padded sequence, unique per year+location.


Sample Python code (inside your Odoo model):

from odoo import models, fields, api

from datetime import datetime


class Vehicle(models.Model):

    _name = 'your_module.vehicle'

    _description = 'Vehicle'


    vehicle_type_code = fields.Selection([...], string="Vehicle Type Code")  # e.g. 'M2'

    battery_capacity_code = fields.Selection([...], string="Battery Capacity Code")  # e.g. 'L'

    vehicle_model_code = fields.Selection([...], string="Vehicle Model Code")  # e.g. 'MBM'

    production_year = fields.Integer(string="Production Year", default=lambda self: datetime.now().year)

    production_location_code = fields.Char(string="Production Location Code")  # e.g. 'J'


    vin = fields.Char(string="VIN", compute="_compute_vin", store=True, readonly=True)


    @api.depends('vehicle_type_code', 'battery_capacity_code', 'vehicle_model_code', 'production_year', 'production_location_code')

    def _compute_vin(self):

        for record in self:

            # Map production year to letter, example: 2025 = 'S'

            year_map = {2025: 'S'}  # Extend as needed

            year_code = year_map.get(record.production_year, 'X')  # Default 'X' if unknown


            # Serial number generation - find max serial for same year + location

            domain = [

                ('production_year', '=', record.production_year),

                ('production_location_code', '=', record.production_location_code),

            ]

            existing_vins = self.search(domain)

            max_serial = 0

            for v in existing_vins:

                if v.vin and len(v.vin) >= 17:

                    serial_str = v.vin[-5:]

                    if serial_str.isdigit():

                        max_serial = max(max_serial, int(serial_str))

            new_serial = str(max_serial + 1).zfill(5)  # zero padded 5 digit


            # Compose VIN

            wmi = "MG3"

            vds = (record.vehicle_type_code or '') + (record.battery_capacity_code or '') + (record.vehicle_model_code or '')

            vis = year_code + (record.production_location_code or '') + new_serial


            record.vin = wmi + vds + vis

The VIN is automatically computed combining WMI + VDS + VIS.

Serial numbers increment uniquely per production year and location.

Extend year_map as needed for other years.

Use dropdowns for the codes (Selection fields) to restrict inputs.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
квіт. 25
956
0
лип. 22
2529
6
бер. 18
6142
3
бер. 15
46189
1
бер. 15
7303