Ir al contenido
Menú
Se marcó esta pregunta

Hi All,

I am using odoo 15 enterprise version. For one of my clients projects, I want to import sales orders through an excel file with the sections in the same file. 

Please Help me with how to do it. Which field name do I need to match for that section name?

Avatar
Descartar
Mejor respuesta

Yes it is possible


Name Customer Order Lines/Sequence Order Lines/Display Type Order Lines/Description Order Lines/Product
S00090 Anita Oliver 1 Section Section 1  
    2   Burger Menu Combo Burger Menu Combo
    3   Bricks Bricks
    4 Section Section 2  
    5   Bacon Burger Bacon Burger

I tested in V16 EE

Avatar
Descartar
Mejor respuesta

Hi, you can follow this:


Hope it helps, thanks

Avatar
Descartar
Mejor respuesta

Hi  Imantha,

I think this video can help you: https://www.youtube.com/watch?v=etMYrOJyaiU&list=PLSKcWRTtEl5qzvRaI-VTGavfReiHS_EEb&index=2 (starting at minute 55 in this video)

Avatar
Descartar
Mejor respuesta

Hi

You can try this code
wizard python file

from odoo import models, fields
from io import BytesIO
import base64
import openpyxl
import re


class ImportLines(models.Model):
_name =
'import.lines'

xls_file = fields.Binary(
'File')

def import_xls(self):
   
"""  Import xlsx report to saleOrder line """
    wb = openpyxl.load_workbook(
        filename=BytesIO(base64.b64decode(self.xls_file)),
        read_only=
True
    )
    ws = wb.active
   
for record in ws.iter_rows(min_row=2, max_row=None, min_col=None,
                              max_col=
None, values_only=True):
        active_id = self.env.context.get(
'active_id')
        product = record[
2]
       
if product:
            val = product.split()
            string = re.sub(
"[\([{})\]]", "", val[0])
            new = self.env[
'sale.order.line'].create({
               
'order_id': active_id,
               
'display_type': False,
               
'product_id':  self.env['product.product'].search([
                            (
'default_code', '=', string)]).id,
               
'name': record[0],
               
'product_uom_qty': record[1],
               
'price_unit': record[3],
               
'product_uom':  self.env['uom.uom'].search([
                            (
'name', '=', record[4])]).id
            })

   
return new

XML:

<record id="import_lines_form" model="ir.ui.view">
 
      <field name="name">import.lines.form</field>
 
      <field name="model">import.lines</field>
        <field name="arch" type="xml">
            <form string="Import Lines">
                <group name="main">
                    <field name="xls_file"/>
                </group>
                <footer>
                    <button name="import_xls" type="object" string="Import" class="oe_highlight"/>
                    <button special="cancel" string="Cancel"/>
                </footer>
            </form>
        </field>
    </record>
        
    <record id="import_lines_action" model="ir.actions.act_window">
        <field name="name">Import Lines</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">import.lines</field>
        <field name="view_mode">form</field>

Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
4
nov 24
10285
1
nov 23
5412
3
nov 22
18575
1
jul 22
4201
2
jun 21
3671