Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

Hi, you can follow this:


Hope it helps, thanks

Avatar
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
4
Nov. 24
10448
1
Nov. 23
5485
3
Nov. 22
18660
1
Juli 22
4343
2
Juni 21
3720