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 can i count records in domain and display it in line with menu ?

Đă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ờ
4 Trả lời
10058 Lượt xem
Ảnh đại diện
Dr Obx

As I mentioned in title, need count for example all records with state = "in" and add this figure into menu line as it is in Messaging "Inbox"


1
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Pawan
Câu trả lời hay nhất

Dr Obx,

inherit "ir.needaction_mixin" in your class and override _needaction_domain_get()

def _needaction_domain_get(self):
return [('state', '=', 'in')]

 Hope it helps

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

Hi Pawan, Why you not responding my questions on Skype :):):) Thanx, I'll try (Student Rob)

Dr Obx
Tác giả

TypeError: _needaction_domain_get() takes exactly 1 argument (4 given)

Temur

add @api.model decorator to _needaction_domain_get function definition. as follows:

@api.model
def _needaction_domain_get(self):
    return [('state', '=', 'in')]
Temur

or change it to v7 style:

def _needaction_domain_get(self, cr, uid, context=None):
    return [('state', '=', 'in')]
Temur

then it should work... does it?

Dr Obx
Tác giả

Better, no errors now ;) So what next, how to add the counter into the line ?

Temur

do you actually have some records with state=in right now?

Dr Obx
Tác giả

Yes, a lot of them ;)

Temur

if you've done all right, then it should already displaying the counter in the menu... no more actions are required.

Temur

do you inherit additionally "ir.needaction_mixin"? what is your inherit statement?

Dr Obx
Tác giả

_inherit = 'ir.needaction_mixin' @api.model def _needaction_domain_get(self): return[('state','=','in')]

Temur

you should include _name attribute as well, when you inherit from multiple models then it's necessary, you'll get something like:

_name = "a.base.model.name"
_inherit = ["a.base.model.name", "ir.needaction_mixin"]
Temur

"ir.needaction_mixin" should be additional inherit, not the main one... see comment above

Temur

"a.base.model.name" here is the model name you're extending. if you are NOT extending any model, then just add _name parameter:

_name = "my.new.model.name"
_inherit = "ir.needaction_mixin"
...
Dr Obx
Tác giả

''class iprodstep_log(models.Model): _name = 'iprodstep.log' _inherit = ["iprodstep.log","ir.needaction_mixin"] ''

Temur

so if you're extending some model, use first option... but you'll need to add _name in both cases... and do not forget to restart odoo and update module from Settings/Modules... page. normally it should work already

Temur

is the 'iprodstep.log' existing model you're extending? if so, then it's correct... if it's a new model then use second option, _inherit = "ir.needaction_mixin". I do not know your scenario, so I posted all two options

Dr Obx
Tác giả

Whatever i do, either first or second scenario still getting errors :(

class iprodstep_log(models.Model):
    _name = 'iprodstep.log'
    _description = 'iprodstep Log'
    _inherit = ["iprodstep.log","ir.needaction_mixin"]

...
    @api.model
    def _needaction_domain_get(self):
        return[('state','=','in')]
Temur

first things first... is the 'iprodstep.log' another model you're extending OR it's a new model you're creating?

Temur

what kind of errors

Dr Obx
Tác giả

iprodstep.log is a model I'm creating. I'll tell you, just need restore everyting and solve the Server 500 error now :)

Dr Obx
Tác giả
  File "/usr/share/pyshared/werkzeug/serving.py", line 159, in run_wsgi
    execute(app)
  File "/usr/share/pyshared/werkzeug/serving.py", line 146, in execute
    application_iter = app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 285, in app
    return self.app(e, s)
  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 216, in application
    return application_unproxied(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 202, in application_unproxied
    result = handler(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1281, in __call__
    return self.dispatch(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1255, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/share/pyshared/werkzeug/wsgi.py", line 411, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1413, in dispatch
    ir_http = request.registry['ir.http']
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 339, in registry
    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 339, in get
    update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 152, in load_module_graph
    models = registry.load(cr, package)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 163, in load
    model = cls._build_model(self, cr)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 595, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 102, in __getitem__
    return self.models[model_name]
KeyError: 'iprodstep.log'

Temur

error you posted is because 'iprodstep.log' is not an existing model, but new one.. as you're not extending any model, then _inherit = "ir.needaction_mixin" is correct option for you

Dr Obx
Tác giả

Oh i got it, so how can I now assign it to the specified menu ?

Temur

you do not need to.

Temur

it'll be added automatically. you just need to have separated page for your 'iprodstep.log' models, you need ordinary menu for that, nothing special

Dr Obx
Tác giả

Not really, because at this moment I have a few menus which contain records in state 'in', 'out', 'cancelled' so i have to separate it somehow or create same kind of counters for each state. like in messaging, it separate numbers of messages for specified group. I hope you know what i mean.

Pawan

Rob, for what you what to achieve, you have to add this:
'needaction_menu_ref': ['list_of_other_menu_ids_of_same_object']
to your respective Menu's action's context in xml file....
suppose on menu with id 'a' you will have :
'needaction_menu_ref': ['b', 'c']
suppose on menu with id 'b' you will have :
'needaction_menu_ref': ['a', 'c']
and so on...... Hope this helps you.......

Dr Obx
Tác giả

it doesn't work ;(

    @api.model
    def _needaction_iprodstep_log_pack_menu_get(self):
        return[('in','out','pack')]
Pawan

Rob, don't add this part and implement above mentioned functionality in action's context.....
and in _needaction_domain_get() just return [('active', '=', True)]

Dr Obx
Tác giả

Aaaaaa hahahahahah i sorted it. It was quiet simple :)

    @api.model
    def _needaction_domain_get(self):
        return[('state','not in',['draft'])]
and now I can see in each menu a number of orders :) The only problem is.... it update the counter only in one menu if you pass the order to another state. every time you want to know the actual states you have to click on the top bar menu
Temur

congrats :)

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


for count records matching a domain you should use function "search_count", quote from documentation:

search_count(args) → int
Returns the number of records in the current model matching the provided domain.

in your case, it'll be something like,

in v8 style:

count = self.env['model.name.to.search.in'].search_count([('state','=','in')])

in v7 style:

count = self.pool['model.name.to.search.in'].search_count(cr,uid, [('state', '=', 'in')], context=context) 

then in "count" variable you'll have the desired number. adapt it to your case.

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ý
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