def is_changed(self): from application.models import Item head = Item.objects(item_id=self.head).first() if not head: return True if self.modified != head.modified:return True return False
def update_item_availability(item_id): from application.models import Item item = Item.objects(item_id=item_id, availability=True).first() if not item: return for spec in item.specs: if spec.availability: return item.update(set__availability=False, set__status='DEL')
def update_to_head(self): from application.models import Item head = Item.objects(item_id=self.head).first() if head: data = head._data for k, v in data.items(): setattr(self, k, v) self.save() else: return self
def create_from_skus(cls, customer_id, skus, logistic_provider, coupon_codes, coin=0, cash=0, address=None, **kwargs): from application.models import OrderEntry, ForexRate, Item, ItemSpec entries = [] for e in skus: availability = check_availability_and_update_stock( e['item_id'], e['sku'], e['quantity']) if not availability: return e spec = ItemSpec.objects(sku=e['sku']).first() item = Item.objects(item_id=e['item_id']).first() entry = OrderEntry(spec=spec, item=item, quantity=e['quantity']).save() entries.append(entry) order = cls(customer_id=customer_id, entries=entries, logistic_provider=logistic_provider, coupon_codes=coupon_codes, coin=coin, cash=cash, **kwargs) if not order.forex: order.forex = ForexRate.get() order.update_amount() order.reload() for e in order.entries: e.create_snapshot() if address: order.set_address(address) import application.services.jobs as Jobs #Jobs.stat.update_user_stats(str(order.customer_id)) Signals.order_created.send('system', order=order) return order