跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    商贸服务
    • 维修人员
    • 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
关于此论坛区
帮助

Unable to delete several records selected from Action button. What's the problem?

订阅

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

此问题已终结
computed-fieldssingletonissueOdoo12.0
1 回复
5387 查看
形象
Paulo Matos

Dear all,
I am using Odoo 12, and found a problem when trying to delete several selected records from the "action" button on top. When I delete records one by one (from the action button), it works fine, but If I select several records, I get the error:

raise ValueError("Expected singleton: %s" % self)

I will try to explain what are my requirements.

1. On model_1, I need to show some records from a model_2. This is done when a user makes a selection from a Many2One field that is related to model_2.
Those records are shown on form view and if user saves the form, they are saved on model_1. If user do not save the form, the information is discarded.

In order to achieve that, I had to use "_compute_fields" on model_1 for some fields. So, the workflow is:
- User selects a record (vehicle_id field) from the many2one related field;
- The "_compute_field" function for the desired records, will get all the information required from model_2 for each field;
- The information is passed to this fields in order to be saved on the database "only if user saves the form".

So, besides other fields, my model_1 definition for the computed fields is:

    #Fields definition
    vehicle_id = fields.Many2one('mymodule.model_2', string="Vehicle", required=True)
    customer = fields.Char("Customer", readonly=True, compute='_compute_fields', store=True)
    brand = fields.Char("Brand", size=64, readonly=True, compute='_compute_fields', store=True)
    model = fields.Char("Model", size=64, readonly=True, compute='_compute_fields', store=True)
    #Compute function
    @api.multi
    @api.depends('vehicle_id')
       def _compute_fields(self):
          first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',self.vehicle_id.name)])
        for rec in first_model_rec_set:
            self.customer = rec.customer_id.name
            self.brand = rec.brand_id.name
            self.model = rec.model_id.name

The error is related with this "compute function" and full error is:

Traceback (most recent call last):
  File "C:\odoo12\odoo\api.py", line 1039, in get
    value = self._data[key][field][record.id]
KeyError: 113

During handling of the above exception, another exception occurred:

"Traceback (most recent call last):
  File "C:\odoo12\odoo\fields.py", line 963, in __get__
    value = record.env.cache.get(record, self)
  File "C:\odoo12\odoo\api.py", line 1041, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('mymodule.model_1(113,).customer', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\odoo12\odoo\http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\odoo12\odoo\http.py", line 312, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "C:\odoo12\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "C:\odoo12\odoo\http.py", line 696, in dispatch
    result = self._call_function(**self.params)
  File "C:\odoo12\odoo\http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:\odoo12\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:\odoo12\odoo\http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:\odoo12\odoo\http.py", line 939, in __call__
    return self.method(*args, **kw)
  File "C:\odoo12\odoo\http.py", line 517, in response_wrap
    response = f(*args, **kw)
  File "c:\odoo12\addons\web\controllers\main.py", line 962, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "c:\odoo12\addons\web\controllers\main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "C:\odoo12\odoo\api.py", line 749, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "C:\odoo12\odoo\api.py", line 736, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "c:\workspace_36\odoo_12\custom_addons\mymodule\models\odometer.py", line 145, in unlink
    return super(mymodule_odometro, self).unlink()
  File "C:\odoo12\odoo\models.py", line 3141, in unlink
    self.recompute()
  File "C:\odoo12\odoo\models.py", line 5218, in recompute
    vals = {n: rec[n] for n in ns}
  File "C:\odoo12\odoo\models.py", line 5218, in <dictcomp>
    vals = {n: rec[n] for n in ns}
  File "C:\odoo12\odoo\models.py", line 5065, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "C:\odoo12\odoo\fields.py", line 967, in __get__
    self.determine_value(record)
  File "C:\odoo12\odoo\fields.py", line 1054, in determine_value
    self.compute_value(recs)  File "C:\odoo12\odoo\fields.py", line 1034, in compute_value    self._compute_value(records)  File "C:\odoo12\odoo\fields.py", line 1025, in _compute_value    getattr(records, self.compute)()
  File "c:\workspace_36\odoo_12\custom_addons\mymodule\models\odometer.py", line 77, in _compute_fields
    first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',self.vehicle_id.name)])
  File "C:\odoo12\odoo\fields.py", line 961, in __get__
    record.ensure_one()
  File "C:\odoo12\odoo\models.py", line 4669, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: mymodule.model_1(113, 112)"

How can I solve this error? Any idea about what could be the problem?

Thank you in advance.

Best regards

0
形象
丢弃
形象
Niyas Raphy (Walnut Software Solutions)
最佳答案

Hi,

Update the compute function like this,

    @api.multi
    @api.depends('vehicle_id')
       def _compute_fields(self):
          for record in self:
              first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',record.vehicle_id.name)])
            for rec in first_model_rec_set:
                  record.customer = rec.customer_id.name
                  record.brand = rec.brand_id.name
                  record.model = rec.model_id.name


Thanks

2
形象
丢弃
Paulo Matos
编写者

Thank you @Niyas, it's working as expected.

+1 for you.

喜欢讨论吗?不要只阅读,加入进来!

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

注册
相关帖文 回复 查看 活动
How to prevent "compute" value from being executed on write method 已解决
writeMethod computed-fields Odoo12.0
形象
形象
1
3月 20
10090
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
形象
形象
1
6月 25
16814
Custom Dashboard using js
Odoo12.0
形象
形象
1
4月 25
4565
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
形象
形象
形象
形象
3
4月 25
7405
Compute Fields 已解决
computed-fields
形象
形象
2
7月 24
9249
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • 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