Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Odoo 10: Load default data in a custom module using xml file

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
moduledatacustomdefaults
3 Trả lời
18387 Lượt xem
Ảnh đại diện
Andrew Brownrigg

The Current Setup

I am attempting to load default data into a module I am designing.  To do so, I have my model setup in cra_model.py, and the default data setup in cra_data.xml  which is referenced in my __manifest__.py as such:

{
     ...
     'data': ['data/cra_data.xml'],
     ...
}

Here are the contents of my models and data files.

cra_model.py
# -*- encoding: utf-8 -*-
from odoo import models, fields, api
class CraCats(models.Model):
     _name = 'cra.cat'
     name = fields.Char('CRA Category')
     type = fields.Selection(
         [('in','Income'), ('out','Expense')],
         string='Income or Expense?')


cra_cat_data.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="cra_cat_a" model="cra.cat">
        <field name="name">Income from sales</field>
        <field name="type">in</field>
    </record>
    <record id="cra_cat_b" model="cra.cat">
        <field name="name">Purchases for sales</field>
        <field name="type">out</field>
    </record>
</odoo>

The Problem at Hand

I am able to install the module just fine without the data file reference in the __manifest__.py.  As soon as I add the data file reference back, and attempt an install or upgrade of the module, I receive the following traceback on the server.  The webui merely gets stuck in a loading state.

2018-01-17 00:48:48,989 83958 CRITICAL Testing odoo.service.server: Failed to initialize database `Testing`.

Traceback (most recent call last):

  File "/usr/local/odoo/odoo/service/server.py", line 911, in preload_registries

    registry = Registry.new(dbname, update_module=update_module)

  File "/usr/local/odoo/odoo/modules/registry.py", line 83, in new

    odoo.modules.load_modules(registry._db, force_demo, status, update_module)

  File "/usr/local/odoo/odoo/modules/loading.py", line 339, in load_modules

    loaded_modules, update_module)

  File "/usr/local/odoo/odoo/modules/loading.py", line 237, in load_marked_modules

    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)

  File "/usr/local/odoo/odoo/modules/loading.py", line 156, in load_module_graph

    _load_data(cr, module_name, idref, mode, kind='data')

  File "/usr/local/odoo/odoo/modules/loading.py", line 95, in _load_data

    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)

  File "/usr/local/odoo/odoo/tools/convert.py", line 845, in convert_file

    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)

  File "/usr/local/odoo/odoo/tools/convert.py", line 898, in convert_xml_import

    doc = etree.parse(xmlfile)

  File "src/lxml/lxml.etree.pyx", line 3427, in lxml.etree.parse (src/lxml/lxml.etree.c:85131)

  File "src/lxml/parser.pxi", line 1803, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:124287)

  File "src/lxml/parser.pxi", line 1823, in lxml.etree._parseFilelikeDocument (src/lxml/lxml.etree.c:124599)

  File "src/lxml/parser.pxi", line 1718, in lxml.etree._parseDocFromFilelike (src/lxml/lxml.etree.c:123258)

  File "src/lxml/parser.pxi", line 1139, in lxml.etree._BaseParser._parseDocFromFilelike (src/lxml/lxml.etree.c:117808)

  File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:110510)

  File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:112276)

  File "src/lxml/parser.pxi", line 613, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:111124)

XMLSyntaxError: xmlParseEntityRef: no name, line 16, column 29

 

What am I missing?  Where have I gone wrong?

0
Ảnh đại diện
Huỷ bỏ
Niyas Raphy (Walnut Software Solutions)

In above given code, there is no errors i think. The error is from xml file, you can check the line number mentioned in the error. probably it may be missing of something or misplaced thing in the XML. check the line 16 and column 29

Andrew Brownrigg
Tác giả

Ok. I looked into my XML deeper, and saw an & instead of an &amp; the XML was generated from an excel spreadsheet, and I forgot to check for &s.

Ảnh đại diện
Bart Criel
Câu trả lời hay nhất

Hi Andrew,


Here's the start of my Odoo 10 data file (which works). I think you forgot the <data> tag. Close it as well :-)

NB. noupdate ensures that the data, once changed by a user, are not overwritten when you update the module.


Bart

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="property_management.subdivision_type" id="type_office">
<field name="name">Office</field>
<field name="sequence">1</field>
</record>

     
     

0
Ảnh đại diện
Huỷ bỏ
Andrew Brownrigg
Tác giả

Bart, thanks for the info. However, "[t]he <odoo> top element in data files was introduced in version 9.0 and replaces the former <openerp> tag. The <data> section inside the top element is still supported, but it is now optional. In fact, now <odoo> and <data> are equivalent, so we could use either one as top elements for our XML data files." <<Odoo 10 Development Essentials, Daniel Reis, pg 84>> This is to say that <odoo> and <data> are now interchangeable top elements. There is no longer the need to place the <data> element between <odoo> and <record>. In your provided example, you could also get away with <odoo noupdate="1">. I am genuinely grateful for your desire to help me troubleshoot. My problem was, in the end, caused by a missing escape character. I had an ampersand(&) where I ought to have had the escape character equivalent (&amp;). Peace and all good! Proost!

Bart Criel

Good that it was *only* a syntax issue. Odoo is not very good at pointing these things out, and we ourselves often look too far :-)

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
Custom Module Not Populating in Apps List Đã xử lý
module custom
Ảnh đại diện
Ảnh đại diện
4
thg 10 20
9931
Import data from CSV
module import data custom odoo8.0
Ảnh đại diện
0
thg 10 15
4187
For Odoo hosted version, how would I upload a custom module? Đã xử lý
module upload custom
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
3
thg 2 24
11528
importing custom module
module custom importing
Ảnh đại diện
Ảnh đại diện
1
thg 11 23
3855
error while parsing inherit view
module xml custom
Ảnh đại diện
Ảnh đại diện
1
thg 6 23
4358
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة 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 là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

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