@@ -133,22 +133,6 @@ class CreditControlLine(models.Model):
133133 compute = "_compute_partner_user_id" ,
134134 store = True ,
135135 )
136- auto_process = fields .Selection (
137- selection = [
138- ("no_auto_process" , "No Auto Process" ),
139- ("low_level" , "Low Level" ),
140- ("highest_level" , "Highest Level" ),
141- ],
142- help = "'No Auto Process' lines are not automatically processed "
143- "with other lines.\n "
144- "'Low Level' lines are automatically processed "
145- "with higher level lines.\n "
146- "'Highest Level' indicates that all 'Low Level' lines for this "
147- "line's partner-policy combination will be automatically "
148- "processed with it." ,
149- default = "no_auto_process" ,
150- readonly = True ,
151- )
152136
153137 @api .depends ("partner_id.user_id" )
154138 def _compute_partner_user_id (self ):
@@ -290,16 +274,6 @@ def create_or_update_from_mv_lines(
290274
291275 return new_lines
292276
293- def _update_auto_process (self , exclude_ids = None ):
294- self .ensure_one ()
295- if not self .policy_id .auto_process_lower_levels :
296- return
297- highest_related_line = self ._get_highest_related_line (exclude_ids = exclude_ids )
298- highest_related_line .write ({"auto_process" : "highest_level" })
299- self ._get_related_lines (
300- exclude_ids = ((exclude_ids or []) + highest_related_line .ids )
301- ).write ({"auto_process" : "low_level" })
302-
303277 def unlink (self ):
304278 for line in self :
305279 if line .state != "draft" :
@@ -309,112 +283,10 @@ def unlink(self):
309283 "line that is not in draft state."
310284 )
311285 )
312- line ._update_auto_process (exclude_ids = line .ids )
313286 return super ().unlink ()
314287
315288 def write (self , values ):
316289 res = super ().write (values )
317290 if "manual_followup" in values :
318291 self .partner_id .write ({"manual_followup" : values .get ("manual_followup" )})
319- for line in self :
320- if "state" in values and values .get ("state" ) == "sent" :
321- line .write ({"auto_process" : "no_auto_process" })
322- if "auto_process" not in values :
323- line ._update_auto_process ()
324292 return res
325-
326- @api .model_create_multi
327- def create (self , vals_list ):
328- lines = super ().create (vals_list )
329- for line in lines :
330- if line .state == "sent" :
331- line .write ({"auto_process" : "no_auto_process" })
332- else :
333- line ._update_auto_process ()
334- return lines
335-
336- def _get_highest_related_line (self , exclude_ids = None ):
337- self .ensure_one ()
338- return self ._get_related_lines (exclude_ids = exclude_ids , limit = 1 )
339-
340- def _get_related_lines_domain (self , exclude_ids = None , level = None ):
341- domain = [
342- ("partner_id" , "=" , self .partner_id .id ),
343- ("currency_id" , "=" , self .currency_id .id ),
344- ("policy_id" , "=" , self .policy_id .id ),
345- ("state" , "in" , ("draft" , "to_be_sent" )),
346- ]
347- if exclude_ids :
348- domain .append (("id" , "not in" , exclude_ids ))
349- if level :
350- domain .append (("level" , "<=" , level ))
351- return domain
352-
353- def _get_related_lines (self , exclude_ids = None , limit = None , level = None ):
354- """
355- Return lines from the same group if grouped
356- (ie with same partner, policy and currency).
357-
358- The most important line (ie the one to display to the user)
359- is the first one of the returned recordset.
360- """
361- self .ensure_one ()
362- if self .policy_id .auto_process_lower_levels :
363- return self .search (
364- self ._get_related_lines_domain (exclude_ids , level ),
365- limit = limit ,
366- order = "level DESC, date_due ASC" ,
367- )
368- else :
369- return self
370-
371- def _get_lower_related_lines (self ):
372- """
373- Return lines that will receive the same treatment
374- (ie lines of lower level from the same group if grouped).
375- """
376- self .ensure_one ()
377- if self .policy_id .auto_process_lower_levels :
378- return self ._get_related_lines (level = self .level )
379- else :
380- return self
381-
382- def button_schedule_activity (self ):
383- ctx = self .env .context .copy ()
384- ctx .update (
385- {
386- "default_res_id" : self .ids [0 ],
387- "default_res_model" : self ._name ,
388- }
389- )
390- return {
391- "type" : "ir.actions.act_window" ,
392- "name" : _ ("Schedule activity" ),
393- "res_model" : "mail.activity" ,
394- "view_type" : "form" ,
395- "view_mode" : "form" ,
396- "res_id" : self .activity_ids and self .activity_ids .ids [0 ] or False ,
397- "views" : [[False , "form" ]],
398- "context" : ctx ,
399- "target" : "new" ,
400- }
401-
402- def button_credit_control_line_form (self ):
403- self .ensure_one ()
404- action = self .env .ref ("account_credit_control.credit_control_line_action" )
405- form = self .env .ref ("account_credit_control.credit_control_line_form" )
406- action = action .read ()[0 ]
407- action ["views" ] = [(form .id , "form" )]
408- action ["res_id" ] = self .id
409- return action
410-
411- def act_show_auto_process_line (self ):
412- self .ensure_one ()
413- return {
414- "type" : "ir.actions.act_window" ,
415- "name" : _ ("Credit Control Lines" ),
416- "res_model" : "credit.control.line" ,
417- "domain" : [("id" , "in" , self ._get_lower_related_lines ().ids )],
418- "view_mode" : "list,form" ,
419- "context" : self .env .context ,
420- }
0 commit comments