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


Python Pool.search_using_ps_id方法代码示例

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


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

示例1: create_using_ps_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def create_using_ps_data(cls, state_data):
        """Create a record for the order state corresponding to state_data

        :param state_data: Objectified XML data for order state
        :return: Created record
        """
        SiteLanguage = Pool().get('prestashop.site.lang')
        SaleChannel = Pool().get('sale.channel')

        channel = SaleChannel(
            Transaction().context['current_channel']
        )

        channel.validate_prestashop_channel()

        # The name of a state can be in multiple languages
        # If the name is in more than one language, create the record with
        # name in first language (if a corresponding one exists on tryton) and
        # updates the rest of the names in different languages by switching the
        # language in context
        name_in_langs = state_data.name.getchildren()

        name_in_first_lang = name_in_langs.pop(0)
        site_lang = SiteLanguage.search_using_ps_id(
            int(name_in_first_lang.get('id'))
        )
        with Transaction().set_context(language=site_lang.language.code):
            vals = {
                'channel': channel.id,
                'prestashop_id': state_data.id.pyval,
                'prestashop_state': name_in_first_lang.pyval,
            }
            vals.update(cls.get_tryton_state(name_in_first_lang.pyval))
            channel_order_state = cls.create([vals])[0]

        # If there is only lang, control wont go to this loop
        for name_in_lang in name_in_langs:
            # Write the name in other languages
            site_lang = SiteLanguage.search_using_ps_id(
                int(name_in_lang.get('id'))
            )
            if not site_lang:
                continue
            with Transaction().set_context(language=site_lang.language.code):
                cls.write([channel_order_state], {
                    'prestashop_state': name_in_lang.pyval,
                })
        return channel_order_state
开发者ID:openlabs,项目名称:trytond-prestashop,代码行数:50,代码来源:sale.py

示例2: get_using_ps_id

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def get_using_ps_id(cls, prestashop_id):
        """
        Return the language corresponding to the prestashop_id for the
        current site in context
        If the language is not found, fetch it from remote.
        Try to link the remote language to a local language.
        If not found, it will show the user the exception sent by prestashop

        :param prestashop_id: Prestashop ID for the language
        :returns: Active record of the language
        """
        SiteLanguage = Pool().get('prestashop.site.lang')
        SaleChannel = Pool().get('sale.channel')

        site_language = SiteLanguage.search_using_ps_id(prestashop_id)

        if not site_language:
            channel = SaleChannel(Transaction().context.get('current_channel'))
            channel.validate_prestashop_channel()

            client = channel.get_prestashop_client()
            site_language = [SiteLanguage.create_using_ps_data(
                client.languages.get(prestashop_id)
            )]

        return site_language.language
开发者ID:riteshshrv,项目名称:trytond-prestashop,代码行数:28,代码来源:lang.py

示例3: import_prestashop_languages

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def import_prestashop_languages(cls, channels):
        """Import Languages from remote and try to link them to tryton
        languages

        :param sites: List of sites for which the languages are to be imported
        :returns: List of languages created
        """
        SiteLanguage = Pool().get('prestashop.site.lang')

        if len(channels) != 1:
            cls.raise_user_error('multiple_channels')
        channel = channels[0]

        channel.validate_prestashop_channel()

        # Set this site in context
        with Transaction().set_context(current_channel=channel.id):

            client = channel.get_prestashop_client()
            languages = client.languages.get_list(display='full')

            new_records = []
            for lang in languages:
                # If the language already exists in `Languages`, skip and do
                # not create it again
                if SiteLanguage.search_using_ps_id(lang.id.pyval):
                    continue
                new_records.append(
                    SiteLanguage.create_using_ps_data(lang)
                )

        return new_records
开发者ID:openlabs,项目名称:trytond-prestashop,代码行数:34,代码来源:channel.py

示例4: import_order_states

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def import_order_states(self):
        """
        Import order states for prestashop channel
        Downstream implementation for channel.import_order_states
        """
        SiteLanguage = Pool().get('prestashop.site.lang')

        if self.source != 'prestashop':
            return super(Channel, self).import_order_states()

        with Transaction().set_context({'current_channel': self.id}):

            # If channel languages don't exist, then raise an error
            if not self.prestashop_languages:
                self.raise_user_error('languages_not_imported')

            client = self.get_prestashop_client()
            order_states = client.order_states.get_list(display='full')

            for state in order_states:
                # The name of a state can be in multiple languages
                # If the name is in more than one language, create the record
                # with name in first language (if a corresponding one exists on
                # tryton) and updates the rest of the names in different
                # languages by switching the language in context
                name_in_langs = state.name.getchildren()
                name_in_first_lang = name_in_langs.pop(0)

                site_lang = SiteLanguage.search_using_ps_id(
                    int(name_in_first_lang.get('id'))
                )
                with Transaction().set_context(
                        language=site_lang.language.code):
                    self.create_order_state(
                        str(state.id.pyval), name_in_first_lang.pyval)
开发者ID:riteshshrv,项目名称:trytond-prestashop,代码行数:37,代码来源:channel.py

示例5: import_prestashop_order_states

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def import_prestashop_order_states(cls, channels):
        """Import Order States from remote and try to link them to tryton
        order states

        :returns: List of order states created
        """
        SiteOrderState = Pool().get('prestashop.site.order_state')

        if len(channels) != 1:
            cls.raise_user_error('multiple_channels')
        channel = channels[0]

        channel.validate_prestashop_channel()

        # Set this channel to context
        with Transaction().set_context(current_channel=channel.id):

            # If channel languages don't exist, then raise an error
            if not channel.prestashop_languages:
                cls.raise_user_error('languages_not_imported')

            client = channel.get_prestashop_client()
            order_states = client.order_states.get_list(display='full')

            new_records = []
            for state in order_states:
                # If this order state already exists for this channel, skip and
                # do not create it again
                if SiteOrderState.search_using_ps_id(state.id.pyval):
                    continue

                new_records.append(
                    SiteOrderState.create_using_ps_data(state)
                )

        return new_records
开发者ID:openlabs,项目名称:trytond-prestashop,代码行数:38,代码来源:channel.py

示例6: get_ps_main_product

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def get_ps_main_product(cls, channel, product_data):
        """
        Return prestashop main product
        """
        Template = Pool().get('product.template')
        Listing = Pool().get('product.product.channel_listing')
        SiteLang = Pool().get('prestashop.site.lang')

        # The name of a product can be in multiple languages
        # If the name is in more than one language, create the record with
        # name in first language (if a corresponding one exists on tryton) and
        # updates the rest of the names in different languages by switching the
        # language in context
        # Same applies to description as well
        name_in_langs = product_data.name.getchildren()
        desc_in_langs = product_data.description.getchildren()

        name_in_first_lang = name_in_langs.pop(0)
        desc_in_first_lang = desc_in_langs[0]
        site_lang = SiteLang.search_using_ps_id(
            int(name_in_first_lang.get('id'))
        )
        variant_data = {
            'code': unicode(product_data.reference.pyval),
            'list_price': round_price(str(product_data.price)),
            'cost_price': round_price(str(product_data.wholesale_price)),
        }
        # Product name and description can be in different first languages
        # So create the variant with description only if the first language is
        # same on both
        if name_in_first_lang.get('id') == desc_in_first_lang.get('id'):
            desc_in_first_lang = desc_in_langs.pop(0)
            variant_data['description'] = desc_in_first_lang.pyval

        # For a product in prestashop, create a template and a product in
        # tryton.
        with Transaction().set_context(language=site_lang.language.code):
            template_values = cls.extract_product_values_from_ps_data(
                channel, name_in_first_lang.pyval, product_data
            )
            template_values.update({
                'products': [('create', [variant_data])],
            })

            template, = Template.create([template_values])
            product, = template.products

        # If there is only lang for name, control wont go to this loop
        for name_in_lang in name_in_langs:
            # Write the name in other languages
            site_lang = SiteLang.search_using_ps_id(
                int(name_in_lang.get('id'))
            )
            if not site_lang:
                continue
            with Transaction().set_context(language=site_lang.language.code):
                Template.write([template], {
                    'name': name_in_lang.pyval,
                })

        # If there is only lang for description which has already been used,
        # control wont go to this loop
        for desc_in_lang in desc_in_langs:
            # Write the description in other languages
            site_lang = SiteLang.search_using_ps_id(
                int(desc_in_lang.get('id'))
            )
            if not site_lang:
                continue
            with Transaction().set_context(language=site_lang.language.code):
                cls.write(template.products, {
                    'description': desc_in_lang.pyval,
                })

        Listing.create_from(channel, product_data)

        return product
开发者ID:riteshshrv,项目名称:trytond-prestashop,代码行数:79,代码来源:product.py

示例7: create_using_ps_data

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import search_using_ps_id [as 别名]
    def create_using_ps_data(cls, product_record):
        """Create a template from the product record sent by prestashop client

        ..note:: Product name and description from product record are stored a
        level deeper than other values. They are stored under a language
        object under name and description objects.

        :param product_record: Objectified XML record sent by pystashop
        :returns: Active record of created template
        """
        Product = Pool().get('product.product')
        Uom = Pool().get('product.uom')
        SaleChannel = Pool().get('sale.channel')
        SiteLang = Pool().get('prestashop.site.lang')

        channel = SaleChannel(Transaction().context['current_channel'])
        channel.validate_prestashop_channel()

        # The name of a product can be in multiple languages
        # If the name is in more than one language, create the record with
        # name in first language (if a corresponding one exists on tryton) and
        # updates the rest of the names in different languages by switching the
        # language in context
        # Same applies to description as well
        name_in_langs = product_record.name.getchildren()
        desc_in_langs = product_record.description.getchildren()

        name_in_first_lang = name_in_langs.pop(0)
        desc_in_first_lang = desc_in_langs[0]
        site_lang = SiteLang.search_using_ps_id(
            int(name_in_first_lang.get('id'))
        )

        # Product name and description can be in different first languages
        # So create the variant with description only if the first language is
        # same on both
        if name_in_first_lang.get('id') == desc_in_first_lang.get('id'):
            desc_in_first_lang = desc_in_langs.pop(0)
            variant_data = {
                'code': product_record.reference.pyval or None,
                'description': desc_in_first_lang.pyval,
                'prestashop_combination_ids': [('create', [{
                    'prestashop_combination_id': 0,
                }])]
            }
        else:
            variant_data = {
                'code': product_record.reference.pyval or None,
                'prestashop_combination_ids': [('create', [{
                    'prestashop_combination_id': 0,
                }])]
            }

        # For a product in prestashop, create a template and a product in
        # tryton.
        unit, = Uom.search([('name', '=', 'Unit')], limit=1)
        with Transaction().set_context(language=site_lang.language.code):
            # XXX: Rounding prices to 4 decimal places.
            # In 3.6 rounding digites can be configured in tryton config
            round_price = lambda price: Decimal(price).quantize(
                Decimal('0.0001'), rounding=ROUND_HALF_EVEN
            )
            template, = cls.create([{
                'name': name_in_first_lang.pyval,
                'list_price': round_price(str(product_record.price)),
                'cost_price': round_price(str(product_record.wholesale_price)),
                'salable': True,
                'default_uom': unit.id,
                'sale_uom': unit.id,
                'products': [('create', [variant_data])],
                'prestashop_ids': [('create', [{
                    'prestashop_id': product_record.id.pyval,
                }])]
            }])

        # If there is only lang for name, control wont go to this loop
        for name_in_lang in name_in_langs:
            # Write the name in other languages
            site_lang = SiteLang.search_using_ps_id(
                int(name_in_lang.get('id'))
            )
            if not site_lang:
                continue
            with Transaction().set_context(language=site_lang.language.code):
                cls.write([template], {
                    'name': name_in_lang.pyval,
                })

        # If there is only lang for description which has already been used,
        # control wont go to this loop
        for desc_in_lang in desc_in_langs:
            # Write the description in other languages
            site_lang = SiteLang.search_using_ps_id(
                int(desc_in_lang.get('id'))
            )
            if not site_lang:
                continue
            with Transaction().set_context(language=site_lang.language.code):
                Product.write(template.products, {
                    'description': desc_in_lang.pyval,
#.........这里部分代码省略.........
开发者ID:priyankarani,项目名称:trytond-prestashop,代码行数:103,代码来源:product.py


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