Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1913 Näkymät

I am working on a custom module using odoo16 where I have a model gas.route and another model is gas.checkpoint. In gas.route model, for a route there could be multiple checkpoints. on the top of that one checkpoint can be assigned on different route. 
but the problem is, in different route the checkpoints sequence is different. I can not be able to handle it to create different sequence of checkpoint for routes.

my code is 

class Route(models.Model):
_name = 'gas.route'
_description = 'Config Route'
_inherit = ['mail.thread']

name=fields.Char("Name")
start_point= fields.Many2one("gas.checkpoint","Start Point", domain="[('is_start_end_checkpoint', '=', True)]")
end_point= fields.Many2one("gas.checkpoint","End Point",domain="[('is_start_end_checkpoint', '=', True)]")
distance = fields.Float(string='Distance(KM)')
updown = fields.Selection([('up','Up'),('down','Down')],string='Up/Down')
checkpoints=fields.Many2many("gas.checkpoint",'gas_route_checkpoint_rel', 'route_id', 'checkpoint_id', string='Checkpoints')
status=fields.Selection([('active', 'Active'), ('inactive', 'Inactive')],string="Status")


on checkpoint model:

class CheckPoint(models.Model):
_name = 'gas.checkpoint'
_description = 'Config Checkpoint'
_inherit = ['mail.thread']

name=fields.Char("Name")
latitude = fields.Float(string='Geo Latitude', digits=(10, 7))
longitude = fields.Float(string='Geo Longitude', digits=(10, 7))
map_location = fields.Char(string='Current Map Location', compute='_compute_map_location')
address = fields.Char(String="Address", compute='_compute_address', store=True)
is_start_end_checkpoint=fields.Boolean("Is Start/End Point")
status=fields.Selection([('active', 'Active'), ('inactive', 'Inactive')],string="Status")


Avatar
Hylkää
Paras vastaus

Hi, 

You can try this:

First, you can add the widget = "many2many_tags" to your checkpoints (m2m) field in the form view file of gas.route model.
Now assuming that you have two checkpoints CP1 and CP2. You can now select your checkpoints in a sequence of your choice in every Gas Route.

Let's say for gas route 1 you added checkpoints like CP2 and CP1.
For another gas route record, you can add Checkpoints CP1 and CP2 and similarly, you can add checkpoints in any sequence of your choice in every route.

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
helmik. 23
1645
2
helmik. 23
2500
0
kesäk. 22
2205
0
jouluk. 19
4041
2
jouluk. 18
8972