Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
Invoicing Sales version14 sales salesorder
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
Invoicing Sales version14 sales salesorder
About this forum
  1. Sales
  2. Forum

How to export product pictures to excel

Naroči se

Get notified when there's activity on this post

This question has been flagged
exportodoo12
3863 Prikazi
Avatar
Mantra

Add export product picture function,

Export the product picture of the sales order to excel

 thank you. 

I can pay, but not too much  
 line.product_id.image_small# -*- coding: utf-8 -*- 
from odoo import api, fields, modelsimport base64from io import BytesIOfrom dateutil import parserimport datetimefrom datetime import datetime, timedeltafrom odoo.exceptions import Warning
try: import xlwt from xlwt import Bordersexcept ImportError: xlwt = Nonetry: import base64except ImportError: _logger.debug('Cannot `import base64`.')

class YWTExportSaleOrder(models.TransientModel): # Model Name _name = "ywt.export.sale.order"
# Field Declaration datas = fields.Binary(string='File')
@api.multi def ywt_exprot_sale_order(self): sale_order_obj = self.env['sale.order'] active_id = self.ids[0]
today = datetime.now().strftime("%Y-%m-%d") file_name = 'Export Sale Order' + ' ' + today
sale_order_ids = self._context.get('active_ids', []) if not sale_order_ids: raise Warning(_('Please Select At least One Sale Order to Export')) if sale_order_ids: custom_value = {} sale_order_ids_ls = sale_order_obj.search([('id', 'in', sale_order_ids)])
workbook, header_bold, value_style = self.ywt_prepare_design()
for order in sale_order_ids_ls: sheet = workbook.add_sheet(order.name) order_lst = [] for line in order.order_line: order_line = {} order_line['product_name'] = line.product_id.name order_line['product_description'] = line.name
# Add display pictures order_line['product_image'] = line.product_id.image_small
order_line['order_qty'] = line.product_uom_qty order_line['qty_delivered'] = line.qty_delivered order_line['qty_invoiced'] = line.qty_invoiced order_line['price_unit'] = line.price_total order_line['price_subunit'] = str(line.price_subtotal) + ' ' + line.currency_id.symbol order_lst.append(order_line)
custom_value['products'] = order_lst custom_value['partner_id'] = order.partner_id.name custom_value[ 'partner_street'] = order.partner_id and order.partner_id.country_id.name + order.partner_id.city + order.partner_id.street # custom_value['patner_city'] = order.partner_id.city # custom_value['patner_country'] = order.partner_id and order.partner_id.country_id.name custom_value['partner_phone'] = order.partner_id.phone custom_value['partner_mobile'] = order.partner_id.mobile
custom_value['date_order'] = str(order.confirmation_date.strftime("%Y-%m-%d")) custom_value['amount_total'] = str(order.amount_total) + ' ' + order.currency_id.symbol custom_value['amount_untaxed'] = str(order.amount_untaxed) + ' ' + order.currency_id.symbol custom_value['amount_tax'] = str(order.amount_tax) + ' ' + order.currency_id.symbol
sheet.write_merge(10, 10, 0, 1, "Product Name", header_bold) sheet.write_merge(10, 10, 2, 3, "Description", header_bold)
sheet.write_merge(10, 10, 6, 6, "Product Image", header_bold)
sheet.write_merge(10, 10, 7, 8, "Ordered Quantity", header_bold) sheet.write_merge(10, 10, 9, 10, "Unit Price", header_bold) sheet.write(10, 11, 'Sub Total', header_bold)
row = 11 col = 1 for product in custom_value['products']: sheet.write_merge(row, row, 0, 1, product['product_name'], value_style) sheet.write_merge(row, row, 2, 3, product['product_description'], value_style) # sheet.write_merge(row, row, 6, 6, product['product_image'], value_style) sheet.write_merge(row, row, 7, 8, product['order_qty'], value_style) sheet.write_merge(row, row, 9, 10, product['price_unit'], value_style) sheet.write(row, 11, product['price_subunit'], value_style) row += 1; col += 1
sheet.write(5, 1, 'Customer', header_bold) sheet.write(5, 2, custom_value['partner_id']) sheet.write(6, 2, custom_value['partner_street']) sheet.write(7, 2, custom_value['partner_phone']) sheet.write(8, 2, custom_value['partner_mobile']) sheet.write_merge(5, 5, 8, 9, 'Order Date', header_bold) sheet.write_merge(5, 5, 10, 11, custom_value['date_order'])
sheet.write_merge(row + 1, row + 1, 9, 10, 'Untaxed Amount', header_bold) sheet.write(row + 1, 11, custom_value['amount_untaxed'], value_style) sheet.write_merge(row + 2, row + 2, 9, 10, 'Taxes', header_bold) sheet.write(row + 2, 11, custom_value['amount_tax'], value_style) sheet.write_merge(row + 3, row + 3, 9, 10, 'Total', header_bold) sheet.write(row + 3, 11, custom_value['amount_total'], value_style)
fp = BytesIO() workbook.save(fp) fp.seek(0) sale_file = base64.encodestring(fp.read()) fp.close() self.write({'datas': sale_file}) if self.datas: return { 'type': 'ir.actions.act_url', 'url': 'web/content/?download=1&model=ywt.export.sale.order&field=datas&id=%s&filename=%s.xls' % ( active_id, file_name), 'target': 'self', }
@api.multi def ywt_prepare_design(self): workbook = xlwt.Workbook() borders = Borders()
header_border = Borders() header_border.left, header_border.right, header_border.top, header_border.bottom = Borders.THIN, Borders.THIN, Borders.THIN, Borders.THICK
borders.left, borders.right, borders.top, borders.bottom = Borders.THIN, Borders.THIN, Borders.THIN, Borders.THIN
header_bold = xlwt.easyxf( "font: bold on, height 200; pattern: pattern solid, fore_colour gray25;alignment: horizontal center ,vertical center") header_bold.borders = header_border
value_style = xlwt.easyxf( "font: height 200, name Arial; alignment: horizontal center ,vertical center; borders: top thin,right thin,bottom thin,left thin")
return workbook, header_bold, value_style

0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
How do I add a field to the export? From model or view (UPDATE) Solved
action export odoo12
Avatar
Avatar
1
okt. 21
5034
exporteren
export
Avatar
Avatar
1
jul. 25
2582
How can I list/export more than 80 items? Solved
export
Avatar
Avatar
Avatar
3
feb. 25
16221
Export data organisations, contactperson, deals
export
Avatar
Avatar
1
apr. 25
2781
Export Import Solved
export
Avatar
Avatar
1
apr. 25
2965
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now