@@ -83,6 +83,16 @@ class ProductionDay(CommonBaseClass):
8383 unique = True , verbose_name = _ ("Day of Sale" ), db_index = True
8484 )
8585 description = models .TextField (blank = True , null = True , verbose_name = _ ("Description" ))
86+ point_of_sales = models .ManyToManyField (
87+ "shop.PointOfSale" ,
88+ blank = False ,
89+ related_name = "production_days" ,
90+ verbose_name = _ ("Point of Sales" ),
91+ help_text = _ (
92+ "Select the point of sales where this production day is available. At least"
93+ " one must be selected."
94+ ),
95+ )
8696
8797 objects = ProductionDayQuerySet .as_manager ()
8898
@@ -1215,41 +1225,50 @@ def create_abo_orders_for_production_days(
12151225 production_day .production_day_products .filter (product = product )
12161226 )
12171227 if not customer_order_position .exists () and production_day_product :
1218- production_day_product = production_day_product .get ()
1219- max_quantity = production_day_product .calculate_max_quantity (
1220- customer
1221- )
1222- quantity = min (
1223- customer_order_template_position .quantity , max_quantity
1224- )
1225- if not production_day_product .is_locked and quantity > 0 :
1226- print (
1227- "Create Abo order: " , production_day , product , quantity
1228+ if (
1229+ not production_day .point_of_sales .exists ()
1230+ or customer .point_of_sale
1231+ in production_day .point_of_sales .all ()
1232+ ):
1233+ # check if pos is available for this production day
1234+ production_day_product = production_day_product .get ()
1235+ max_quantity = (
1236+ production_day_product .calculate_max_quantity (customer )
12281237 )
1229- customer_order , created = (
1230- CustomerOrder .objects .get_or_create (
1231- production_day = production_day ,
1232- customer = customer ,
1233- defaults = {
1234- "point_of_sale" : customer .point_of_sale ,
1235- },
1236- )
1237- )
1238- price = None
1239- price_total = None
1240- if product .sale_price :
1241- price = product .sale_price .price .amount
1242- price_total = price * quantity
1243- position = CustomerOrderPosition .objects .create (
1244- order = customer_order ,
1245- product = product ,
1246- quantity = quantity ,
1247- price = price ,
1248- price_total = price_total ,
1238+ quantity = min (
1239+ customer_order_template_position .quantity , max_quantity
12491240 )
1250- customer_order_template_position .orders .add (position )
1251- customer_order_template_position .order_template .set_locked ()
1252- is_order_created = True
1241+ if not production_day_product .is_locked and quantity > 0 :
1242+ print (
1243+ "Create Abo order: " ,
1244+ production_day ,
1245+ product ,
1246+ quantity ,
1247+ )
1248+ customer_order , created = (
1249+ CustomerOrder .objects .get_or_create (
1250+ production_day = production_day ,
1251+ customer = customer ,
1252+ defaults = {
1253+ "point_of_sale" : customer .point_of_sale ,
1254+ },
1255+ )
1256+ )
1257+ price = None
1258+ price_total = None
1259+ if product .sale_price :
1260+ price = product .sale_price .price .amount
1261+ price_total = price * quantity
1262+ position = CustomerOrderPosition .objects .create (
1263+ order = customer_order ,
1264+ product = product ,
1265+ quantity = quantity ,
1266+ price = price ,
1267+ price_total = price_total ,
1268+ )
1269+ customer_order_template_position .orders .add (position )
1270+ customer_order_template_position .order_template .set_locked ()
1271+ is_order_created = True
12531272 from bakeup .pages .models import EmailSettings
12541273
12551274 if (
0 commit comments