当前位置: 首页>>代码示例>>Python>>正文


Python Pool.create_using_magento_data方法代码示例

本文整理汇总了Python中trytond.pool.Pool.create_using_magento_data方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.create_using_magento_data方法的具体用法?Python Pool.create_using_magento_data怎么用?Python Pool.create_using_magento_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trytond.pool.Pool的用法示例。


在下文中一共展示了Pool.create_using_magento_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_product

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def import_product(self, sku):
        """
        Import specific product for this magento channel

        Downstream implementation for channel.import_product
        """
        Product = Pool().get('product.product')

        if self.source != 'magento':
            return super(Channel, self).import_product(sku)

        product = Product.find_using_magento_sku(sku)

        if not product:
            # if product is not found get the info from magento and
            # delegate to create_using_magento_data
            with magento.Product(
                self.magento_url, self.magento_api_user,
                self.magento_api_key
            ) as product_api:
                product_data = product_api.info(sku)

            product = Product.create_using_magento_data(product_data)

        return product
开发者ID:openlabs,项目名称:trytond-magento,代码行数:27,代码来源:channel.py

示例2: import_order

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def import_order(self, order_info):
        "Downstream implementation to import sale order from magento"
        if self.source != "magento":
            return super(Channel, self).import_order(order_info)

        Sale = Pool().get("sale.sale")

        sale = Sale.find_using_magento_data(order_info)
        if sale:
            return sale

        with Transaction().set_context({"current_channel": self.id}):
            with magento.Order(self.magento_url, self.magento_api_user, self.magento_api_key) as order_api:
                order_data = order_api.info(order_info["increment_id"])
                return Sale.create_using_magento_data(order_data)
开发者ID:prakashpp,项目名称:trytond-magento,代码行数:17,代码来源:channel.py

示例3: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def get_sale_using_magento_data(cls, order_data):
        """
        Return an active record of the sale from magento data
        """
        Sale = Pool().get('sale.sale')
        Party = Pool().get('party.party')
        Address = Pool().get('party.address')
        Currency = Pool().get('currency.currency')
        Uom = Pool().get('product.uom')
        Channel = Pool().get('sale.channel')

        channel = Channel.get_current_magento_channel()

        currency = Currency.search_using_magento_code(
            order_data['order_currency_code']
        )

        if order_data['customer_id']:
            party = Party.find_or_create_using_magento_id(
                order_data['customer_id']
            )
        else:
            firstname = order_data['customer_firstname'] or (
                order_data['billing_address'] and
                order_data['billing_address']['firstname']
            )
            lastname = order_data['customer_lastname'] or (
                order_data['billing_address'] and
                order_data['billing_address']['lastname']
            )
            party = Party.create_using_magento_data({
                'firstname': firstname,
                'lastname': lastname,
                'email': order_data['customer_email'],
                'customer_id': 0
            })

        party_invoice_address = None
        if order_data['billing_address']:
            party_invoice_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['billing_address']
                )

        party_shipping_address = None
        if order_data['shipping_address']:
            party_shipping_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['shipping_address']
                )
        unit, = Uom.search([('name', '=', 'Unit')])

        tryton_action = channel.get_tryton_action(order_data['state'])

        if not party_shipping_address:
            # if there is no shipment address, this could be a digital
            # delivery which won't need a shipment. No shipment_address is
            # hence assumed as no shipment needed. So set the method as
            # manual
            shipment_method = 'manual'
        else:
            shipment_method = tryton_action['shipment_method']

        return Sale(**{
            'reference': channel.magento_order_prefix +
                order_data['increment_id'],
            'sale_date': order_data['created_at'].split()[0],
            'party': party.id,
            'currency': currency.id,
            'invoice_address': party_invoice_address,
            'shipment_address': party_shipping_address or party_invoice_address,
            'magento_id': int(order_data['order_id']),
            'channel': channel.id,
            'invoice_method': tryton_action['invoice_method'],
            'shipment_method': shipment_method,
            'lines': [],
        })
开发者ID:usudaysingh,项目名称:trytond-magento,代码行数:79,代码来源:sale.py

示例4: create_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def create_using_magento_data(cls, order_data):
        """
        Create a sale from magento data

        :param order_data: Order data from magento
        :return: Active record of record created
        """
        Party = Pool().get('party.party')
        Address = Pool().get('party.address')
        StoreView = Pool().get('magento.store.store_view')
        Currency = Pool().get('currency.currency')
        Uom = Pool().get('product.uom')

        store_view = StoreView(Transaction().context.get('magento_store_view'))
        instance = store_view.instance

        currency = Currency.search_using_magento_code(
            order_data['order_currency_code']
        )

        if order_data['customer_id']:
            party = Party.find_or_create_using_magento_id(
                order_data['customer_id']
            )
        else:
            party = Party.create_using_magento_data({
                'firstname': order_data['customer_firstname'],
                'lastname': order_data['customer_lastname'],
                'email': order_data['customer_email'],
                'customer_id': 0
            })

        party_invoice_address = \
            Address.find_or_create_for_party_using_magento_data(
                party, order_data['billing_address']
            )
        party_shipping_address = \
            Address.find_or_create_for_party_using_magento_data(
                party, order_data['shipping_address']
            )
        unit, = Uom.search([('name', '=', 'Unit')])

        tryton_state = MagentoOrderState.get_tryton_state(order_data['state'])

        sale_data = {
            'reference': instance.order_prefix + order_data['increment_id'],
            'sale_date': order_data['created_at'].split()[0],
            'party': party.id,
            'currency': currency.id,
            'invoice_address': party_invoice_address.id,
            'shipment_address': party_shipping_address.id,
            'magento_id': int(order_data['order_id']),
            'magento_instance': instance.id,
            'magento_store_view': store_view.id,
            'invoice_method': tryton_state['invoice_method'],
            'shipment_method': tryton_state['shipment_method'],
            'lines': cls.get_item_line_data_using_magento_data(order_data)
        }

        if Decimal(order_data.get('shipping_amount')):
            sale_data['lines'].append(
                cls.get_shipping_line_data_using_magento_data(order_data)
            )

        if Decimal(order_data.get('discount_amount')):
            sale_data['lines'].append(
                cls.get_discount_line_data_using_magento_data(order_data)
            )

        sale, = cls.create([sale_data])

        # Process sale now
        sale.process_sale_using_magento_state(order_data['state'])

        return sale
开发者ID:GauravButola,项目名称:trytond-magento,代码行数:77,代码来源:sale.py

示例5: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def get_sale_using_magento_data(cls, order_data):
        """
        Return an active record of the sale from magento data
        """
        Sale = Pool().get('sale.sale')
        Party = Pool().get('party.party')
        Address = Pool().get('party.address')
        Currency = Pool().get('currency.currency')
        Channel = Pool().get('sale.channel')

        channel = Channel.get_current_magento_channel()

        currency = Currency.search_using_magento_code(
            order_data['order_currency_code']
        )

        if order_data['customer_id']:
            party = Party.find_or_create_using_magento_id(
                order_data['customer_id']
            )
        else:
            firstname = order_data['customer_firstname'] or (
                order_data['billing_address'] and
                order_data['billing_address']['firstname']
            ) or (
                order_data['shipping_address'] and
                order_data['shipping_address']['firstname']
            )
            lastname = order_data['customer_lastname'] or (
                order_data['billing_address'] and
                order_data['billing_address']['lastname']
            ) or (
                order_data['shipping_address'] and
                order_data['shipping_address']['lastname']
            )
            party = Party.create_using_magento_data({
                'firstname': firstname,
                'lastname': lastname,
                'email': order_data['customer_email'],
                'customer_id': 0
            })

        party_invoice_address = None
        if order_data['billing_address']:
            party_invoice_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['billing_address']
                )

        party_shipping_address = None
        if order_data['shipping_address']:
            party_shipping_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['shipping_address']
                )

        tryton_action = channel.get_tryton_action(order_data['state'])

        if not party_shipping_address:
            # if there is no shipment address, this could be a digital
            # delivery which won't need a shipment. No shipment_address is
            # hence assumed as no shipment needed. So set the method as
            # manual
            shipment_method = 'manual'
        else:
            shipment_method = tryton_action['shipment_method']

        timezone = pytz.timezone(channel.timezone)
        sale_time = datetime.strptime(
            order_data['created_at'], '%Y-%m-%d %H:%M:%S'
        )
        sale_time = timezone.localize(sale_time)
        utc_sale_time = sale_time.astimezone(pytz.utc)

        return Sale(**{
            'reference': channel.magento_order_prefix +
                order_data['increment_id'],
            'sale_date': utc_sale_time.date(),
            'party': party.id,
            'currency': currency.id,
            'invoice_address': party_invoice_address,
            'shipment_address': party_shipping_address or party_invoice_address,
            'magento_id': int(order_data['order_id']),
            'channel': channel.id,
            'invoice_method': tryton_action['invoice_method'],
            'shipment_method': shipment_method,
            'lines': [],
        })
开发者ID:bhavana94,项目名称:trytond-magento,代码行数:90,代码来源:sale.py

示例6: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import create_using_magento_data [as 别名]
    def get_sale_using_magento_data(cls, order_data):
        """
        Return an active record of the sale from magento data
        """
        Sale = Pool().get('sale.sale')
        Party = Pool().get('party.party')
        Address = Pool().get('party.address')
        StoreView = Pool().get('magento.store.store_view')
        Currency = Pool().get('currency.currency')
        Uom = Pool().get('product.uom')
        MagentoOrderState = Pool().get('magento.order_state')

        store_view = StoreView(Transaction().context.get('magento_store_view'))
        instance = store_view.instance

        currency = Currency.search_using_magento_code(
            order_data['order_currency_code']
        )

        if order_data['customer_id']:
            party = Party.find_or_create_using_magento_id(
                order_data['customer_id']
            )
        else:
            party = Party.create_using_magento_data({
                'firstname': order_data['customer_firstname'],
                'lastname': order_data['customer_lastname'],
                'email': order_data['customer_email'],
                'customer_id': 0
            })

        party_invoice_address = None
        if order_data['billing_address']:
            party_invoice_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['billing_address']
                )

        party_shipping_address = None
        if order_data['shipping_address']:
            party_shipping_address = \
                Address.find_or_create_for_party_using_magento_data(
                    party, order_data['shipping_address']
                )
        unit, = Uom.search([('name', '=', 'Unit')])

        tryton_state = MagentoOrderState.get_tryton_state(order_data['state'])

        if not party_shipping_address:
            # if there is no shipment address, this could be a digital
            # delivery which won't need a shipment. No shipment_address is
            # hence assumed as no shipment needed. So set the method as
            # manual
            shipment_method = 'manual'
        else:
            shipment_method = tryton_state['shipment_method']

        return Sale(**{
            'reference': instance.order_prefix + order_data['increment_id'],
            'sale_date': order_data['created_at'].split()[0],
            'party': party.id,
            'currency': currency.id,
            'invoice_address': party_invoice_address,
            'shipment_address': party_shipping_address or party_invoice_address,
            'magento_id': int(order_data['order_id']),
            'magento_instance': instance.id,
            'magento_store_view': store_view.id,
            'invoice_method': tryton_state['invoice_method'],
            'shipment_method': shipment_method,
            'lines': [],
        })
开发者ID:hotkee,项目名称:trytond-magento,代码行数:73,代码来源:sale.py


注:本文中的trytond.pool.Pool.create_using_magento_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。