def export_tier_prices_to_magento( self, cursor, user, store, context ): """ Exports tier prices of products from openerp to magento for this store :param cursor: Database cursor :param user: ID of current user :param store: Browse record of store :param context: Application context :return: List of products """ pricelist_obj = self.pool.get('product.pricelist') products = [] instance = store.website.instance for magento_product in store.website.magento_products: products.append(magento_product.product) price_tiers = magento_product.product.price_tiers or \ store.price_tiers price_data = [] for tier in price_tiers: if hasattr(tier, 'product'): # The price tier comes from a product, then it has a # function field for price, we use it directly price = tier.price else: # The price tier comes from the default tiers on store, # we donr have a product on tier, so we use the current # product in loop for computing the price for this tier price = pricelist_obj.price_get( cursor, user, [store.shop.pricelist_id.id], magento_product.product.id, tier.quantity, context={ 'uom': store.website.default_product_uom.id } )[store.shop.pricelist_id.id] price_data.append({ 'qty': tier.quantity, 'price': price, }) # Update stock information to magento with magento.ProductTierPrice( instance.url, instance.api_user, instance.api_key ) as tier_price_api: tier_price_api.update( magento_product.magento_id, price_data ) return products
def export_tier_prices_to_magento(self): """ Exports tier prices of products from tryton to magento for this store :return: List of products """ instance = self.website.instance for mag_product_template in self.website.magento_product_templates: product_template = mag_product_template.template product = product_template.products[0] # Get the price tiers from the product if the product has a price # tier table else get the default price tiers from current store price_tiers = product_template.price_tiers or self.price_tiers price_data = [] for tier in price_tiers: if hasattr(tier, 'product'): # The price tier comes from a product, then it has a # function field for price, we use it directly price = tier.price else: # The price tier comes from the default tiers on store, # we dont have a product on tier, so we use the current # product in loop for computing the price for this tier price = self.price_list.compute(None, product, product.list_price, tier.quantity, self.website.default_uom) price_data.append({ 'qty': tier.quantity, 'price': float(price), }) # Update stock information to magento with magento.ProductTierPrice(instance.url, instance.api_user, instance.api_key) as tier_price_api: tier_price_api.update(mag_product_template.magento_id, price_data) return len(self.website.magento_product_templates)
def export_product_prices(self): """ Exports tier prices of products from tryton to magento for this channel :return: List of products """ if self.source != 'magento': return super(Channel, self).export_product_prices() ChannelListing = Pool().get('product.product.channel_listing') price_domain = [ ('channel', '=', self.id), ] if self.last_product_price_export_time: price_domain.append([ 'OR', [('product.write_date', '>=', self.last_product_price_export_time)], [('product.template.write_date', '>=', self.last_product_price_export_time)] ]) product_listings = ChannelListing.search(price_domain) self.last_product_price_export_time = datetime.utcnow() self.save() for listing in product_listings: # Get the price tiers from the product listing if the list has # price tiers else get the default price tiers from current # channel price_tiers = listing.price_tiers or self.magento_price_tiers price_data = [] for tier in price_tiers: if hasattr(tier, 'product_listing'): # The price tier comes from a product listing, then it has a # function field for price, we use it directly price = tier.price else: # The price tier comes from the default tiers on # channel, # we dont have a product on tier, so we use the current # product in loop for computing the price for this tier price = self.price_list.compute(None, listing.product, listing.product.list_price, tier.quantity, self.default_uom) price_data.append({ 'qty': tier.quantity, 'price': float(price), }) # Update stock information to magento with magento.ProductTierPrice( self.magento_url, self.magento_api_user, self.magento_api_key) as tier_price_api: tier_price_api.update(listing.product_identifier, price_data, identifierType="productID") return len(product_listings)