1- # Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev>
2- from odoo import api , fields , models
1+ # Copyright 2024-2025 Ivan Yelizariev <https://twitter.com/yelizariev>
2+ from odoo import fields , models
33
44
55class SyncOrder (models .Model ):
@@ -16,12 +16,17 @@ class SyncOrder(models.Model):
1616 ondelete = "cascade" ,
1717 required = True ,
1818 )
19+ sync_job_id = fields .Many2one ("sync.job" )
1920 description = fields .Html (related = "sync_task_id.sync_order_description" )
21+ # DEPRECATED. Use line_ids.record_id instead
2022 record_id = fields .Reference (
2123 string = "Blackjack" ,
2224 selection = "_selection_record_id" ,
2325 help = "Optional extra information to perform this task" ,
2426 )
27+ line_ids = fields .One2many (
28+ "sync.order.line" , "sync_order_id" , string = "Linked Records"
29+ )
2530
2631 partner_ids = fields .Many2many ("res.partner" , string = "Partners" )
2732 state = fields .Selection (
@@ -34,7 +39,6 @@ class SyncOrder(models.Model):
3439 default = "draft" ,
3540 )
3641
37- @api .model
3842 def _selection_record_id (self ):
3943 mm = self .sync_task_id .sync_order_model_id
4044 if not mm :
@@ -53,3 +57,53 @@ def action_cancel(self):
5357 def action_refresh (self ):
5458 # Magic
5559 pass
60+
61+
62+ class SyncOrderLine (models .Model ):
63+ _name = "sync.order.line"
64+ _description = "Sync Order Records"
65+
66+ sync_order_id = fields .Many2one ("sync.order" )
67+ record_id = fields .Reference (
68+ string = "Linked Record" ,
69+ selection = "_selection_record_id" ,
70+ help = "Optional extra information to perform this task" ,
71+ )
72+ state = fields .Selection (
73+ [
74+ ("draft" , "Draft" ),
75+ ("open" , "In Progress" ),
76+ ("done" , "Done" ),
77+ ("error" , "Failed" ),
78+ ("cancel" , "Canceled" ),
79+ ],
80+ default = "draft" ,
81+ )
82+ value = fields .Char ("Extra Input" )
83+ result = fields .Char ("Result" )
84+
85+ def _selection_record_id (self ):
86+ mm = self .sync_order_id .sync_task_id .sync_order_model_id
87+ if not mm :
88+ return []
89+ return [(mm .model , mm .name )]
90+
91+ def action_done (self , msg = None ):
92+ self .write ({"state" : "done" })
93+ if msg :
94+ self .write ({"result" : msg })
95+
96+ def action_confirm (self , msg = None ):
97+ self .write ({"state" : "open" })
98+ if msg :
99+ self .write ({"result" : msg })
100+
101+ def action_error (self , msg = None ):
102+ self .write ({"state" : "error" })
103+ if msg :
104+ self .write ({"result" : msg })
105+
106+ def action_cancel (self , msg = None ):
107+ self .write ({"state" : "cancel" })
108+ if msg :
109+ self .write ({"result" : msg })
0 commit comments