@@ -274,6 +274,16 @@ def validate(self):
274
274
self .validate_end_date ()
275
275
self .validate_to_follow_calendar_months ()
276
276
self .cost_center = erpnext .get_default_cost_center (self .get ('company' ))
277
+ self .validate_plans_price_lists ()
278
+
279
+ def validate_plans_price_lists (self ):
280
+ if len (self .plans ) <= 1 :
281
+ return
282
+
283
+ price_list = [frappe .get_value ("Subscription Plan" , plan .plan , 'price_list' ) for plan in self .plans ]
284
+ price_list = list (set (list (filter (lambda x : x is not None , price_list ))))
285
+ if len (price_list ) > 1 :
286
+ frappe .throw (_ ("Solo se pueden tener Planes con la misma Lista de Precio en una Suscripción." ))
277
287
278
288
def validate_trial_period (self ):
279
289
"""
@@ -341,14 +351,13 @@ def create_invoice(self, prorate):
341
351
invoice = frappe .new_doc (doctype )
342
352
invoice .subscription = self .name
343
353
344
- # Si solo tiene un plan aplicamos esa lista de precios a la factura
345
- if len (self .plans ) == 1 :
346
- price_list = frappe .get_value ("Subscription Plan" , self .plans [0 ].plan , 'price_list' )
347
- if price_list :
348
- if doctype == "Sales Invoice" :
349
- invoice .selling_price_list = price_list
350
- else :
351
- invoice .buying_price_list = price_list
354
+ # Aplicamos esa lista de precios a la factura
355
+ price_list = frappe .get_value ("Subscription Plan" , self .plans [0 ].plan , 'price_list' )
356
+ if price_list :
357
+ if doctype == "Sales Invoice" :
358
+ invoice .selling_price_list = price_list
359
+ else :
360
+ invoice .buying_price_list = price_list
352
361
353
362
# For backward compatibility
354
363
# Earlier subscription didn't had any company field
@@ -457,6 +466,10 @@ def get_items_from_plans(self, plans, prorate=0):
457
466
458
467
items = []
459
468
party = self .party
469
+
470
+ doctype = "Sales Invoice" if self .party_type == "Customer" else "Purchase Invoice"
471
+ company = self .company
472
+
460
473
for plan in plans :
461
474
plan_doc = frappe .get_doc ('Subscription Plan' , plan .plan )
462
475
@@ -471,10 +484,12 @@ def get_items_from_plans(self, plans, prorate=0):
471
484
472
485
if not prorate :
473
486
item = {'item_code' : item_code , 'qty' : plan .qty , 'rate' : get_plan_rate (plan .plan , plan .qty , party ,
474
- self .current_invoice_start , self .current_invoice_end ), 'cost_center' : plan_doc .cost_center }
487
+ self .current_invoice_start , self .current_invoice_end , 1 , doctype , company ), 'cost_center' : plan_doc .cost_center }
475
488
else :
476
489
item = {'item_code' : item_code , 'qty' : plan .qty , 'rate' : get_plan_rate (plan .plan , plan .qty , party ,
477
- self .current_invoice_start , self .current_invoice_end , prorate_factor ), 'cost_center' : plan_doc .cost_center }
490
+ self .current_invoice_start , self .current_invoice_end , prorate_factor , doctype , company ), 'cost_center' : plan_doc .cost_center }
491
+
492
+
478
493
479
494
if deferred :
480
495
item .update ({
0 commit comments