Ejemplo n.º 1
0
 async def get_stock_ids_set_from_sub_stock(self, sub_id):
     query = sa.select((sub_user_stock_ix.c.stock_id, ))\
         .where(sub_user_stock_ix.c.sub_id == sub_id)
     current_connection = connection_ctx.get()
     res = await current_connection.execute(query)
     stock_records = await res.fetchall()
     return set((rec[0] for rec in stock_records))
Ejemplo n.º 2
0
 async def update_sub_user_stock(self, sub_id, delete_ids, add_ids):
     current_connection = connection_ctx.get()
     if delete_ids:
         await self._delete_sub_user_stock(current_connection, sub_id,
                                           delete_ids)
     if add_ids:
         await self._add_sub_user_stock(current_connection, sub_id, add_ids)
     await self._set_sub_user_dt_now(current_connection, sub_id)
Ejemplo n.º 3
0
 async def get_stock_ids_set_by_product_id_and_codes(
         self, product_id, type_codes, option_codes):
     stock_query = self._get_stock_query_by_product_id_and_codes(
         product_id, type_codes, option_codes)
     current_connection = connection_ctx.get()
     res = await current_connection.execute(stock_query)
     stock_records = await res.fetchall()
     return set((rec[0] for rec in stock_records))
Ejemplo n.º 4
0
    async def get_subscription_id(self, user_id, product_id):
        """
        используется SELECT FOR UPDATE
        """
        sub_user_query = sa.select((sub_user.c.id, ))\
            .where(and_(sub_user.c.product_id == product_id, sub_user.c.user_id == user_id))\
            .with_for_update()

        current_connection = connection_ctx.get()
        res = await current_connection.execute(sub_user_query)
        sub_id = await res.scalar()
        if not sub_id:
            raise ObjectDoesNotExist
        return sub_id
Ejemplo n.º 5
0
 async def create_sub_user_and_stock_by_product_id(self,
                                                   user_id,
                                                   product_id,
                                                   type_codes=None,
                                                   option_codes=None):
     current_connection = connection_ctx.get()
     parent_product_id = await self._get_product_parent_id_by_product_id(
         current_connection, product_id)
     if parent_product_id:
         product_id_for_sub = parent_product_id
     else:
         product_id_for_sub = product_id
     sub_id = await self._create_sub_user(current_connection, user_id,
                                          product_id_for_sub)
     await self._create_sub_user_stock_by_product_id(
         current_connection, product_id, type_codes, option_codes, sub_id)