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ợ

How to add a new value to a selection field (`state` in `sale.order`)?

Đă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ờ
developmentinheritanceselection
5 Trả lời
58719 Lượt xem
Ảnh đại diện
Nicolas Bustillos

I really need to add an additional 'state' value on my Sale Order object. Since version 7.0, the 'sale_stock' module does exactly that already. When you try to do the same thing from your own module, your key,value just gets ignored. Is there any other alternative to achieve this?
As I found out, this seems to be an old time issue from two years ago as explained in this thread. A suggested workaround there was to do something like this:

_inherit = 'sale.order'
def __init__(self, pool, cr):
    super(sale_order, self)._columns['state'].selection.append(('keyx', 'valuex'))

I found this approach logical, but it resulted in the following error:

`File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 2958, in _auto_init
    self._field_create(cr, context=context)
File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 764, in _field_create
    ir_model_fields_obj = self.pool.get('ir.model.fields')
AttributeError: 'sale.order' object has no attribute 'pool'`

Should this bug be reported at launchpad or is it an unintended use? What other possible solutions can you suggest? Thanks in advance.

6
Ảnh đại diện
Huỷ bỏ
Atchuthan - Technical Consultant, Sodexis Inc

@Nico Bustillos, Is this issue solved by changing the whole state when inherited by other modules or done using other method?

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

Hi, In V8 you have selection_add attribute, it can be used like

state = fields.Selection(selection_add=[('early_payment', 'Early payment: Discount early payment')])
19
Ảnh đại diện
Huỷ bỏ
Gopakumar N G

The newly added state always comes last in the header even after specifying statusbar_visible field in proper order. Is there anyway to correct it?

For example, the existing states are Draft->Post and I have added 'Validated' using selection_add but is coming in the form view as Draft->Post->Validated and what I was expecting is Draft->Validated->Post(statusbar_visible="draft,validate,post").

Jacky

state = fields.Selection(selection_add=[("to_approve", "To Approve"),("sale",))

This will add the new state just before the state 'sale'

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

Redefine the state field and make your module depending on sale_stock instead of sale (in __openerp__.py). That way, you insure your object will be the last to update the state field properties.

In OpenERP inheritance, when several classes try to update the same field, the last one will win.

You cannot use the __init__() because the inheritance tree is built after instantiation by the ORM. When __init__() is called, your object would not have sale_order class as an ancestor or pool attribute.

7
Ảnh đại diện
Huỷ bỏ
Nicolas Bustillos
Tác giả

Thank you. Indeed this simple change solves my particular problem. I guess in some other cases where the 3rd party addon is unknown this inherit issue could still be a problem. Fortunately, in my case 'sale_stock' is among the certified addons and I have no problem including it as a dependency. Thanks again.

Pouya Malekinejad

Hi, in new api the correct way is to use selection_add attribute as in the documentation: class openerp.fields.Selection(selection=None, string=None, **kwargs) Bases: openerp.fields.Field Parameters: selection – specifies the possible values for this field. It is given as either a list of pairs (value, string), or a model method, or a method name. selection_add – provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string). The attribute selection is mandatory except in the case of related fields or field extensions.

Ảnh đại diện
Cyril Gaspard (GEM)
Câu trả lời hay nhất

Hi,

to add a field type selection in the class, do like this :

class sale_order(osv.osv):
   _inherit = 'sale.order'
   _columns = {
       'state': fields.selection((('keyx', 'valuex'), ('keyz', 'valuez')), 'State'),
   }
   _defaults = {
       'state': 'keyx',  
   }
sale_order()

Hope this will help and work.

Bye

4
Ảnh đại diện
Huỷ bỏ
Nicolas Bustillos
Tác giả

This would be the standard way to add a value to any given 'selection' field and it usually works. The key problem here however is that there is a 3rd addon that does exactly that and is being priorized upon my own module, which ultimately gets ignored. But as you can see from the correct answer given, it is just a matter of making the dependencies lineal among the three addons (instead of both addons inheriting from a single one). Also note that I don't want to change my new value as the default one, as I still need 'draft' to be the initial state. Thanks a lot anyway.

Cyril Gaspard (GEM)

Hi, then you could use states parameter too, this will follow the workflow and depend not of the dependencies, it will overwrite all properties, see openerp developer documentation : http://doc.openerp.com/v6.1/developer/03_modules_2.html .thanks for the comment. Bye

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

Hi, Please note that super(...)._columns['state'] will only work if no other module has a _inherit to the same class. Otherwise, super(...)._columns may contain the columns added/modified by the other module.

To achieve this cleanly, the main class must be patched to make the state selection a class attribute. This has not been done for Sale Orders yet but it looks like something you could reasonably ask for. Check out Purchase Orders for example:

class purchase_order(osv.osv):
    ...
    STATE_SELECTION = [
        ('draft', 'Draft PO'),
        ('sent', 'RFQ Sent'),
        ('confirmed', 'Waiting Approval'),
        ('approved', 'Purchase Order'),
        ('except_picking', 'Shipping Exception'),
        ('except_invoice', 'Invoice Exception'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')
    ]
    ...
    _columns = {
        ...
        'state': fields.selection(STATE_SELECTION, 'Status', ...),
        ...
    }

Then you can add states like this:

class PurchaseOrder (osv.osv):
    _inherit = 'purchase.order'    
    def __init__(self, pool, cr):
        """Add a new state value"""
        super(PurchaseOrder, self).STATE_SELECTION.append(('foo', 'Foo'))
        return super(PurchaseOrder, self).__init__(pool, cr)
3
Ảnh đại diện
Huỷ bỏ
Mohammad Alhashash

This is completely wrong. When __init__() method is called, the inherited class would not be in the MRO chain and is not reachable through super(). That is why the OP got the missing pool attribute error; the model was not initialized yet and has no pool attribute. This is not standard python inheritance. You can use init() method which is called by the ORM after initialization, but this will not solve the problem too.

Mohammad Alhashash

Having the list as a class attribute is irrelevant because model._columns['state'].selection is a reference to that list whether it is inline, class or module variable and using it is the most reliable way to reach the list. The problem of the OP was that sale_stock module is replacing the list with a new one that overrides his list. Check my answer for the correct solution.

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

Hi, 

You can follow following link for this:

https://youtu.be/2CIzEY2p8G8

Thanks

0
Ảnh đại diện
Huỷ bỏ
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
classical inheritance
development inheritance
Ảnh đại diện
Ảnh đại diện
1
thg 10 24
2456
The different "openerp model inheritance" mechanisms: what's the difference between them, and when should they be used ? Đã xử lý
development inheritance
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 8 23
44543
How to import method from another module?
development inheritance
Ảnh đại diện
Ảnh đại diện
1
thg 3 15
11255
Help with inherited view
development inheritance account.tax
Ảnh đại diện
Ảnh đại diện
1
thg 4 24
2808
Change the string of an inherited field Đã xử lý
development fields inheritance
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
7
thg 12 23
27100
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