Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2174 Lượt xem

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")


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 23
1877
2
thg 2 23
2689
0
thg 6 22
2408
0
thg 12 19
4270
2
thg 12 18
9187