@@ -10,23 +10,27 @@ class AccountMove(models.Model):
10
10
student_id = fields .Many2one (
11
11
"res.partner" , domain = "[('id', 'in', student_ids), ('partner_type', '=', 'student')]" , index = True
12
12
)
13
+ require_student_on_invoices = fields .Boolean (related = "company_id.require_student_on_invoices" )
13
14
14
15
@api .constrains ("student_id" , "move_type" )
15
16
def _check_student (self ):
16
17
# Está saltando warning en runbot por esta constrains ya que hay facturas sin estudiante, por lo tanto
17
18
# desactivamos el chequeo cuando se hace la instalación
18
19
if self .env .context .get ("install_mode" ):
19
20
return True
20
- invoices_wo_student = self .filtered (lambda x : x .move_type in ["out_invoice" , "out_refund" ] and not x .student_id )
21
- if invoices_wo_student :
22
- msg = self .env ._ ("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno." )
23
- if len (invoices_wo_student ) > 1 :
24
- msg += (
25
- ".\n "
26
- + self .env ._ ("Los siguientes documentos no cumplen esa condición:" )
27
- + "\n \n - %s" % "\n - " .join (invoices_wo_student .mapped ("display_name" ))
28
- )
29
- raise ValidationError (msg )
21
+ if self .filtered ("require_student_on_invoices" ):
22
+ invoices_wo_student = self .filtered (
23
+ lambda x : x .move_type in ["out_invoice" , "out_refund" ] and not x .student_id
24
+ )
25
+ if invoices_wo_student :
26
+ msg = self .env ._ ("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno." )
27
+ if len (invoices_wo_student ) > 1 :
28
+ msg += (
29
+ ".\n "
30
+ + self .env ._ ("Los siguientes documentos no cumplen esa condición:" )
31
+ + "\n \n - %s" % "\n - " .join (invoices_wo_student .mapped ("display_name" ))
32
+ )
33
+ raise ValidationError (msg )
30
34
31
35
@api .depends ("partner_id" )
32
36
def _compute_student_ids (self ):
0 commit comments