Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
Invoicing Sales version14 sales salesorder
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
Invoicing Sales version14 sales salesorder
About this forum
  1. Sales
  2. Fòrum

How to export product pictures to excel

Subscriure's

Get notified when there's activity on this post

This question has been flagged
exportodoo12
3850 Vistes
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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
How do I add a field to the export? From model or view (UPDATE) Solved
action export odoo12
Avatar
Avatar
1
d’oct. 21
5024
exporteren
export
Avatar
Avatar
1
de jul. 25
2571
How can I list/export more than 80 items? Solved
export
Avatar
Avatar
Avatar
3
de febr. 25
16197
Export data organisations, contactperson, deals
export
Avatar
Avatar
1
d’abr. 25
2763
Export Import Solved
export
Avatar
Avatar
1
d’abr. 25
2920
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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