@@ -829,20 +829,25 @@ def create_or_update_customer_order(
829
829
cls , request , production_day , customer , products , point_of_sale = None
830
830
):
831
831
with transaction .atomic ():
832
+ changes_detected = False
832
833
point_of_sale = (
833
834
point_of_sale
834
835
and PointOfSale .objects .get (pk = point_of_sale )
835
836
or customer .point_of_sale
836
837
)
838
+ old_customer_order = CustomerOrder .objects .filter (
839
+ production_day = production_day , customer = customer
840
+ ).first ()
837
841
customer_order , created = CustomerOrder .objects .update_or_create (
838
842
production_day = production_day ,
839
843
customer = customer ,
840
844
defaults = {
841
845
"point_of_sale" : point_of_sale ,
842
846
},
843
847
)
848
+ if old_customer_order and old_customer_order .point_of_sale != point_of_sale :
849
+ changes_detected = True
844
850
for product , quantity in products .items ():
845
- # print(product, quantity)
846
851
production_day_product = ProductionDayProduct .objects .get (
847
852
production_day = production_day , product = product
848
853
)
@@ -883,6 +888,10 @@ def create_or_update_customer_order(
883
888
if product .sale_price :
884
889
price = product .sale_price .price .amount
885
890
price_total = price * quantity
891
+ old_position = CustomerOrderPosition .objects .filter (
892
+ Q (product = product )
893
+ | Q (product__product_template = product , order = customer_order )
894
+ ).first ()
886
895
position , created = CustomerOrderPosition .objects .filter (
887
896
Q (product = product ) | Q (product__product_template = product )
888
897
).update_or_create (
@@ -894,12 +903,19 @@ def create_or_update_customer_order(
894
903
"price_total" : price_total ,
895
904
},
896
905
)
906
+ if created :
907
+ changes_detected = True
908
+ elif old_position and old_position .quantity != quantity :
909
+ changes_detected = True
897
910
elif quantity == 0 :
898
- CustomerOrderPosition .objects .filter (
911
+ deleted , object_types = CustomerOrderPosition .objects .filter (
899
912
Q (product = product ) | Q (product__product_template = product ),
900
913
order = customer_order ,
901
914
).delete ()
902
- return customer_order , created
915
+ if deleted :
916
+ changes_detected = True
917
+
918
+ return customer_order , created , changes_detected
903
919
904
920
def get_production_day_products_ordered_list (self ):
905
921
production_day_products = (
0 commit comments