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


Python Pool.find_or_create_using_magento_id方法代码示例

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


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

示例1: import_products

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def import_products(self, website):
        """
        Imports products for the current instance

        :param website: Active record of website
        """
        Product = Pool().get('product.template')

        instance = website.instance
        Transaction().set_context({
            'magento_instance': instance.id,
            'magento_website': website.id
        })
        with magento.Product(
            instance.url, instance.api_user, instance.api_key
        ) as product_api:
            magento_products = product_api.list()

            products = []
            for magento_product in magento_products:
                products.append(
                    Product.find_or_create_using_magento_id(
                        magento_product['product_id']
                    )
                )

        return map(int, products)
开发者ID:hotkee,项目名称:trytond-magento,代码行数:29,代码来源:product.py

示例2: create_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def create_using_magento_data(cls, product_data):
        """
        Create a new product with the `product_data` from magento.This method
        also looks for the category of the product. If found, it uses that
        category to assign the product to. If no category is found, it assigns
        the product to `Unclassified Magento Product` category

        :param product_data: Product Data from Magento
        :returns: Browse record of product created
        """
        Template = Pool().get('product.template')
        Category = Pool().get('product.category')
        Channel = Pool().get('sale.channel')

        channel = Channel.get_current_magento_channel()

        # Get only the first category from the list of categories
        # If no category is found, put product under unclassified category
        # which is created by default data
        if product_data.get('categories'):
            category = Category.find_or_create_using_magento_id(
                int(product_data['categories'][0])
            )
        else:
            categories = Category.search([
                ('name', '=', 'Unclassified Magento Products')
            ])
            category = categories[0]

        product_template_values = cls.extract_product_values_from_data(
            product_data
        )
        product_template_values.update({
            'products': [('create', [{
                'description': product_data.get('description'),
                'code': product_data['sku'],
                'list_price': Decimal(
                    product_data.get('special_price') or
                    product_data.get('price') or
                    0.00
                ),
                'cost_price': Decimal(product_data.get('cost') or 0.00),
                'channel_listings': [('create', [{
                    'product_identifier': product_data['product_id'],
                    'channel': channel.id,
                    'magento_product_type': product_data['type'],
                }])],
            }])],
            'category': category.id,
        })
        product_template, = Template.create([product_template_values])

        return product_template.products[0]
开发者ID:openlabs,项目名称:trytond-magento,代码行数:55,代码来源:product.py

示例3: create_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def create_using_magento_data(cls, product_data):
        """
        Create a new product with the `product_data` from magento.This method
        also looks for the category of the product. If found, it uses that
        category to assign the product to. If no category is found, it assigns
        the product to `Unclassified Magento Product` category

        :param product_data: Product Data from Magento
        :returns: Browse record of product created
        """
        # TODO: Remove this method completely and stick to the channel API
        # The method above (create_from) should be used instead.
        Template = Pool().get("product.template")
        Category = Pool().get("product.category")

        # Get only the first category from the list of categories
        # If no category is found, put product under unclassified category
        # which is created by default data
        if product_data.get("categories"):
            category = Category.find_or_create_using_magento_id(int(product_data["categories"][0]))
        else:
            categories = Category.search([("name", "=", "Unclassified Magento Products")])
            category = categories[0]

        product_template_values = cls.extract_product_values_from_data(product_data)
        product_template_values.update(
            {
                "products": [
                    (
                        "create",
                        [
                            {
                                "description": product_data.get("description"),
                                "code": product_data["sku"],
                                "list_price": Decimal(
                                    product_data.get("special_price") or product_data.get("price") or 0.00
                                ),
                                "cost_price": Decimal(product_data.get("cost") or 0.00),
                            }
                        ],
                    )
                ],
                "category": category.id,
            }
        )
        product_template, = Template.create([product_template_values])
        return product_template.products[0]
开发者ID:usudaysingh,项目名称:trytond-magento,代码行数:49,代码来源:product.py

示例4: get_sale_line_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def get_sale_line_using_magento_data(self, item):
        """
        Get sale.line data from magento data.
        """
        SaleLine = Pool().get('sale.line')
        ProductTemplate = Pool().get('product.template')
        MagentoException = Pool().get('magento.exception')
        Uom = Pool().get('product.uom')
        StoreView = Pool().get('magento.store.store_view')

        sale_line = None
        unit, = Uom.search([('name', '=', 'Unit')])
        if not item['parent_item_id']:
            # If its a top level product, create it
            try:
                product = ProductTemplate.find_or_create_using_magento_id(
                    item['product_id'],
                ).products[0]
            except xmlrpclib.Fault, exception:
                if exception.faultCode == 101:
                    # Case when product doesnot exist on magento
                    # create magento exception
                    MagentoException.create([{
                        'origin': '%s,%s' % (self.__name__, self.id),
                        'log': "Product #%s does not exist" %
                            item['product_id']
                    }])
                    product = None
                    self.has_magento_exception = True
                else:
                    raise
            sale_line = SaleLine(**{
                'sale': self.id,
                'magento_id': int(item['item_id']),
                'description': item['name'] or product.name,
                'unit_price': Decimal(item['price']),
                'unit': unit.id,
                'quantity': Decimal(item['qty_ordered']),
                'note': item.get('comments'),
                'product': product,
            })
            if item.get('tax_percent') and Decimal(item.get('tax_percent')):
                store_view = StoreView.get_current_store_view()
                taxes = store_view.get_taxes(
                    Decimal(item['tax_percent']) / 100
                )
                sale_line.taxes = taxes
开发者ID:hotkee,项目名称:trytond-magento,代码行数:49,代码来源:sale.py

示例5: create_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def create_using_magento_data(cls, product_data):
        """
        Create a new product with the `product_data` from magento.This method
        also looks for the category of the product. If found, it uses that
        category to assign the product to. If no category is found, it assigns
        the product to `Unclassified Magento Product` category

        :param product_data: Product Data from Magento
        :returns: Browse record of product created
        """
        Category = Pool().get('product.category')

        # Get only the first category from the list of categories
        # If no category is found, put product under unclassified category
        # which is created by default data
        if product_data.get('categories'):
            category = Category.find_or_create_using_magento_id(
                int(product_data['categories'][0])
            )
        else:
            categories = Category.search([
                ('name', '=', 'Unclassified Magento Products')
            ])
            category = categories[0]

        product_template_values = cls.extract_product_values_from_data(
            product_data
        )
        product_template_values.update({
            'products': [('create', [{
                'description': product_data['description'],
                'code': product_data['sku'],
            }])],
            'category': category.id,
            'magento_product_type': product_data['type'],
            'magento_ids': [('create', [{
                'magento_id': int(product_data['product_id']),
                'website': Transaction().context.get('magento_website'),
            }])],
        })

        product_template, = cls.create([product_template_values])

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

示例6: get_item_line_data_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def get_item_line_data_using_magento_data(cls, order_data):
        """
        Make data for an item line from the magento data.
        This method decides the actions to be taken on different product types

        :param order_data: Order Data from magento
        :return: List of data of order lines in required format
        """
        Uom = Pool().get('product.uom')
        ProductTemplate = Pool().get('product.template')
        Bom = Pool().get('production.bom')

        unit, = Uom.search([('name', '=', 'Unit')])

        line_data = []
        for item in order_data['items']:
            if not item['parent_item_id']:
                # If its a top level product, create it
                values = {
                    'magento_id': int(item['item_id']),
                    'description': item['name'],
                    'unit_price': Decimal(item['price']),
                    'unit': unit.id,
                    'quantity': Decimal(item['qty_ordered']),
                    'note': item['product_options'],
                    'product': ProductTemplate.find_or_create_using_magento_id(
                        item['product_id'],
                    ).products[0].id
                }
                line_data.append(('create', [values]))

            # If the product is a child product of a bundle product, do not
            # create a separate line for this.
            if 'bundle_option' in item['product_options'] and \
                    item['parent_item_id']:
                continue

        # Handle bundle products.
        # Find/Create BoMs for bundle products
        # If no bundle products exist in sale, nothing extra will happen
        Bom.find_or_create_bom_for_magento_bundle(order_data)

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

示例7: import_products

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def import_products(self, website):
        """
        Imports products for the current instance

        :param website: Active record of website
        """
        Product = Pool().get('product.template')

        instance = website.instance
        Transaction().set_context({
            'magento_instance': instance.id,
            'magento_website': website.id
        })
        with magento.Product(
            instance.url, instance.api_user, instance.api_key
        ) as product_api:
            magento_products = []
            products = []

            # Products are linked to websites. But the magento api filters
            # the products based on store views. The products available on
            # website are always available on all of its store views.
            # So we get one store view for each website in current instance.
            magento_products.extend(
                product_api.list(
                    store_view=website.stores[0].store_views[0].magento_id
                )
            )

            for magento_product in magento_products:
                products.append(
                    Product.find_or_create_using_magento_id(
                        magento_product['product_id']
                    )
                )

        return map(int, products)
开发者ID:GauravButola,项目名称:trytond-magento,代码行数:39,代码来源:product.py

示例8: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [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

示例9: find_or_create_bom_for_magento_bundle

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [as 别名]
    def find_or_create_bom_for_magento_bundle(cls, order_data):
        """
        Find or create a BoM for bundle product from the data sent in
        magento order

        :param order_data: Order Data from magento
        :return: Found or created BoM's active record
        """
        Uom = Pool().get('product.uom')
        ProductTemplate = Pool().get('product.template')
        ProductBom = Pool().get('product.product-production.bom')

        identified_boms = cls.identify_boms_from_magento_data(order_data)

        if not identified_boms:
            return

        for item_id, data in identified_boms.iteritems():
            bundle_product_template = \
                ProductTemplate.find_or_create_using_magento_id(
                    data['bundle']['product_id']
                )
            bundle_product = bundle_product_template.products[0]

            # It contains a list of tuples, in which the first element is the
            # product's active record and second is its quantity in the BoM
            child_products = [(
                ProductTemplate.find_or_create_using_magento_id(
                    each['product_id']
                ).products[0], (
                    float(each['qty_ordered']) /
                    float(data['bundle']['qty_ordered'])
                )
            ) for each in data['components']]

            # Here we match the sets of BoM components for equality
            # Each set contains tuples of product and quantity of that
            # product in the BoM
            # If everything for a BoM matches, then we dont create a new one
            # and use this BoM itself
            # XXX This might eventually have issues because of rounding
            # in quantity
            for product_bom in bundle_product.boms:
                existing_bom_set = set([
                    (input.product.id, input.quantity)
                    for input in product_bom.bom.inputs
                ])
                new_bom_set = set([
                    (product.id, qty) for product, qty in child_products
                ])
                if existing_bom_set == new_bom_set:
                    break
            else:
                # No matching BoM found, create a new one
                unit, = Uom.search([('name', '=', 'Unit')])
                bom, = cls.create([{
                    'name': bundle_product.name,
                    'inputs': [('create', [{
                        'uom': unit.id,
                        'product': product.id,
                        'quantity': quantity,
                    }]) for product, quantity in child_products],
                    'outputs': [('create', [{
                        'uom': unit,
                        'product': bundle_product.id,
                        'quantity': bundle_product.quantity,
                    }])]
                }])

                product_bom = ProductBom.create([{
                    'product': bundle_product.id,
                    'bom': bom.id,
                }])

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

示例10: create_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [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

示例11: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [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

示例12: get_sale_using_magento_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import find_or_create_using_magento_id [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.find_or_create_using_magento_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。