Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    Real Estate
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    Consulting
    • Accounting Firm
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • Solar Energy Systems
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    Others
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

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

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

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

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
developmentinheritanceselection
5 ตอบกลับ
58706 มุมมอง
อวตาร
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
อวตาร
ละทิ้ง
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?

อวตาร
John
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
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'

อวตาร
Mohammad Alhashash
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
Nicolas Bustillos
ผู้เขียน

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.

อวตาร
Cyril Gaspard (GEM)
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
Nicolas Bustillos
ผู้เขียน

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

อวตาร
NUMERIGRAPHE
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
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.

อวตาร
Adil Akbar
คำตอบที่ดีที่สุด

Hi, 

You can follow following link for this:

https://youtu.be/2CIzEY2p8G8

Thanks

0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
classical inheritance
development inheritance
อวตาร
อวตาร
1
ต.ค. 24
2455
The different "openerp model inheritance" mechanisms: what's the difference between them, and when should they be used ? แก้ไขแล้ว
development inheritance
อวตาร
อวตาร
อวตาร
2
ส.ค. 23
44539
How to import method from another module?
development inheritance
อวตาร
อวตาร
1
มี.ค. 15
11251
Help with inherited view
development inheritance account.tax
อวตาร
อวตาร
1
เม.ย. 24
2802
Change the string of an inherited field แก้ไขแล้ว
development fields inheritance
อวตาร
อวตาร
อวตาร
อวตาร
อวตาร
7
ธ.ค. 23
27099
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة 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 เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

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