Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ indexes:
- name: parent_code.dest.__key__
- name: scope_code.idx

- kind: shop_address
properties:
- name: cloned_from
- name: customer.dest.__key__
- name: firstname
- name: lastname

- kind: shop_address
properties:
- name: firstname
Expand Down
18 changes: 0 additions & 18 deletions src/viur/shop/modules/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def adminInfo(self) -> dict:
),
"filter": {
"customer.dest.key": user["key"],
"cloned_from": "None",
},
})

Expand Down Expand Up @@ -65,7 +64,6 @@ def listFilter(self, query: db.Query) -> t.Optional[db.Query]:
# The current customer is only allowed to see his own addresses
if (user := current.user.get()) and self.render.kind == "json":
query.filter("customer.dest.__key__ =", user["key"])
query.filter("cloned_from =", None)

if user and (f"{self.moduleName}-view" in user["access"] or "root" in user["access"]):
return query
Expand Down Expand Up @@ -93,21 +91,5 @@ def _disable_old_default(self, skel: SkeletonInstance) -> None:
other_skel["is_default"] = False
other_skel.write()

def clone_address(self, key: db.Key) -> SkeletonInstance_T[AddressSkel]:
# Clone the address, so in case the user edits the address, existing orders wouldn't be affected by this
# TODO: Can we do this copy-on-write instead; clone if an address is edited and replace on used order skels?
src_address_skel = address_skel = self.editSkel()
if not address_skel.read(key):
raise ValueError(f"Address with {key=!r} does not exist")
# create a new instance and copy all values except the key
address_skel = self.shop.address.addSkel()
for name, value in src_address_skel.items(True):
if name == "key":
continue
address_skel[name] = value
address_skel.setBoneValue("cloned_from", key)
address_skel.write()
return address_skel


Address.json = True
7 changes: 0 additions & 7 deletions src/viur/shop/modules/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,6 @@ def freeze_order(
) -> SkeletonInstance_T[OrderSkel]:
cart_skel = self.shop.cart.freeze_cart(order_skel["cart"]["dest"]["key"])
order_skel["total"] = cart_skel["total_discount_price"]

# Clone the address, so in case the user edits the address, existing orders wouldn't be affected by this
# TODO: Can we do this copy-on-write instead; clone if an address is edited and replace on used order skels?
ba_key = order_skel["billing_address"]["dest"]["key"]
ba_skel = self.shop.address.clone_address(ba_key)
assert ba_skel["key"] != ba_key, f'{ba_skel["key"]} != {ba_key}'
order_skel.setBoneValue("billing_address", ba_skel["key"])
order_skel.write()
EVENT_SERVICE.call(Event.ORDER_CHANGED, order_skel=order_skel, deleted=False)

Expand Down
7 changes: 0 additions & 7 deletions src/viur/shop/skeletons/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,3 @@ class AddressSkel(Skeleton):
required=True,
multiple=True,
)

cloned_from = RelationalBone(
kind="{{viur_shop_modulename}}_address",
module="{{viur_shop_modulename}}/address",
readOnly=True, # set by the system
consistency=RelationalConsistency.Ignore,
)
10 changes: 3 additions & 7 deletions src/viur/shop/skeletons/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,9 @@ class CartNodeSkel(TreeSkel):
shipping_address = RelationalBone(
kind="{{viur_shop_modulename}}_address",
module="{{viur_shop_modulename}}/address",
refKeys=[
"key", "name", "customer_type", "salutation", "company_name",
"firstname", "lastname", "street_name", "street_number",
"address_addition", "zip_code", "city", "country",
"email", "phone",
"is_default", "address_type",
],
refKeys={
"*",
},
)

customer_comment = TextBone(
Expand Down
14 changes: 6 additions & 8 deletions src/viur/shop/skeletons/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ class OrderSkel(Skeleton):
billing_address = RelationalBone(
kind="{{viur_shop_modulename}}_address",
module="{{viur_shop_modulename}}/address",
consistency=RelationalConsistency.PreventDeletion,
refKeys=[
"key", "name", "customer_type", "salutation", "company_name",
"firstname", "lastname", "street_name", "street_number",
"address_addition", "zip_code", "city", "country",
"email", "phone", "birthdate",
"is_default", "address_type",
],
searchable=True,
# keep billing address persistent:
updateLevel=RelationalUpdateLevel.OnValueAssignment,
# keep all fields of the billing address as a copy:
refKeys={
"*",
},
)

customer = RelationalBone(
Expand Down
Loading