跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    Trades
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    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
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

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

订阅

此帖文有活动时,接收通知

此问题已终结
developmentinheritanceselection
5 回复
58726 查看
形象
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
形象
丢弃
喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
classical inheritance
development inheritance
形象
形象
1
10月 24
2459
The different "openerp model inheritance" mechanisms: what's the difference between them, and when should they be used ? 已解决
development inheritance
形象
形象
形象
2
8月 23
44546
How to import method from another module?
development inheritance
形象
形象
1
3月 15
11260
Help with inherited view
development inheritance account.tax
形象
形象
1
4月 24
2812
Change the string of an inherited field 已解决
development fields inheritance
形象
形象
形象
形象
形象
7
12月 23
27103
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • 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致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

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