Coverage for ingadhoc-argentina-sale / l10n_ar_stock_ux / wizards / arba_cot_wizard.py: 26%

44 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 18:22 +0000

1############################################################################## 

2# For copyright and license notices, see __manifest__.py file in module root 

3# directory 

4############################################################################## 

5import re 

6 

7from odoo import api, fields, models 

8from odoo.exceptions import ValidationError 

9 

10 

11class ArbaCotWizard(models.TransientModel): 

12 _name = "arba.cot.wizard" 

13 _description = "arba.cot.wizard" 

14 

15 datetime_out = fields.Datetime( 

16 required=True, help="Fecha de salida. No debe ser inferior a ayer ni superior a dentro de 30 días." 

17 ) 

18 tipo_recorrido = fields.Selection( 

19 [("U", "Urbano"), ("R", "Rural"), ("M", "Mixto")], 

20 required=True, 

21 default="M", 

22 ) 

23 partner_id = fields.Many2one( 

24 "res.partner", 

25 string="Transportista", 

26 required=True, 

27 ) 

28 

29 patente_vehiculo = fields.Char( 

30 help="Requerido si CUIT Transportista = CUIT Compañía\n3 letras y 3 numeros o 2 letras, 3 números y 2 letras" 

31 ) 

32 patente_acoplado = fields.Char(help="3 letras y 3 numeros o 2 letras, 3 números y 2 letras") 

33 prod_no_term_dev = fields.Selection( 

34 [("0", "No"), ("1", "Si")], 

35 string="Productos no terminados / devoluciones", 

36 default="0", 

37 required=True, 

38 ) 

39 importe = fields.Float( 

40 string="Importe Neto", 

41 ) 

42 

43 @api.constrains("patente_vehiculo", "patente_acoplado") 

44 def _constrain_check_format_patente(self): 

45 formato_antiguo = r"^[A-Z]{2}\d{3}[A-Z]{2}$" # LLNNNLL 

46 formato_nuevo = r"^[A-Z]{3}\d{3}$" # LLLNNN 

47 patente_vehiculo_valida = patente_acoplado_valida = False 

48 

49 if not self.patente_vehiculo and not self.patente_acoplado: 

50 return True 

51 

52 if self.patente_vehiculo and ( 

53 re.match(formato_antiguo, self.patente_vehiculo.upper()) or re.match(formato_nuevo, self.patente_vehiculo) 

54 ): 

55 patente_vehiculo_valida = True 

56 

57 if self.patente_acoplado: 

58 if bool(re.match(formato_antiguo, self.patente_acoplado.upper())) or bool( 

59 re.match(formato_nuevo, self.patente_acoplado) 

60 ): 

61 patente_acoplado_valida = True 

62 

63 error = [] 

64 if not patente_acoplado_valida: 

65 error.append("Patente Acoplado") 

66 if not patente_vehiculo_valida: 

67 error.append("Patente Vehiculo") 

68 if error: 

69 raise ValidationError(self.env._("El formato de patente no es válido (%s)" % ", ".join(error))) 

70 

71 def confirm(self): 

72 self.ensure_one() 

73 ctx = self.env.context or {} 

74 pickings = self.env["stock.picking"] 

75 

76 # Soporta acción desde remitos individuales o múltiples 

77 if ctx.get("active_model") == "stock.picking": 

78 picking_ids = ctx.get("active_ids", []) 

79 pickings = self.env["stock.picking"].browse(picking_ids) 

80 else: 

81 # Fallback para compatibilidad 

82 picking_ids = ctx.get("active_ids", []) 

83 pickings = self.env["stock.picking"].browse(picking_ids) 

84 

85 for pick in pickings: 

86 pick._arba_send_picking( 

87 fields.Date.from_string(self.datetime_out), 

88 self.tipo_recorrido, 

89 self.partner_id, 

90 self.patente_vehiculo, 

91 self.patente_acoplado, 

92 self.prod_no_term_dev, 

93 self.importe, 

94 ) 

95 

96 return True