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 count on selection value

Đă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ờ
selectioncountodoo
2 Trả lời
1985 Lượt xem
Ảnh đại diện
mmd

I making a module for student's to select their lunch in a day and it's a selection .
how i can see how many student's select food1 and how many select food2 ?


this is my food class :

class Lunch(models.Model):
_name = "food.foods"

name = fields.Char(string="نام غذا", required=True)
food_type = fields.Selection([('withrice','WithRice'),('whitoutrice' , 'WithoutRice')] , string="select" )

and this is my days class :

class DayOfWeek(models.Model):
_name = 'food.days'
_description = 'days of week'

name = fields.Char(string='day' , compute='_complite_name')
date = fields.Date(string='date', required=True)
week_id = fields.Many2one('food.weeks', string='week')
food_id = fields.Many2many('food.foods', string='food name')






0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Jainesh Shah(Aktiv Software)
Câu trả lời hay nhất

Hello mmd,


To see how many students selected Food 1 and Food 2, you can add two counters in your "food.days" model.

Based on your Many2many relationship with food_ids, you can count the selections as follows:


Add compute fields:

//Code in Comment//

Hope this Helps,

If you need any help in customization feel free to contact us.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

0
Ảnh đại diện
Huỷ bỏ
Jainesh Shah(Aktiv Software)

Code :
with_rice_count = fields.Integer(string='With Rice Count',
compute='_compute_food_counts',
store=True)

without_rice_count = fields.Integer(string='Without Rice Count',
compute='_compute_food_counts',
store=True)

Compute method:
@api.depends('food_id')
def _compute_food_counts(self):
for record in self:
with_rice = record.food_id.filtered(
lambda f: f.food_type == 'withrice')
without_rice = record.food_id.filtered(
lambda f: f.food_type == 'whitoutrice')
record.with_rice_count = len(with_rice)
record.without_rice_count = len(without_rice)

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

To achieve the functionality where you can see how many students have selected food1 and how many have selected food2, you need to create a relation between the DayOfWeek and the students' selection of a specific lunch. You can create an additional model to capture each student's food selection on a particular day.


Here's an overview of what you need to add:


Create a new model to track student food selection.

Link the new model to the DayOfWeek and Lunch models, as well as to the student.



Updated Models:

Add Student Food Selection Model: This new model will track each student's food choice for a given day.



from odoo import models, fields


class Student(models.Model):

    _name = 'food.student'

    _description = 'Student'


    name = fields.Char(string='Student Name', required=True)

    student_id = fields.Char(string='Student ID', required=True)


class Lunch(models.Model):

    _name = "food.foods"


    name = fields.Char(string="Food Name", required=True)

    food_type = fields.Selection([('withrice', 'WithRice'), ('whitoutrice', 'WithoutRice')], string="Select")


class DayOfWeek(models.Model):

    _name = 'food.days'

    _description = 'Days of the Week'


    name = fields.Char(string='Day', compute='_compute_name')

    date = fields.Date(string='Date', required=True)

    week_id = fields.Many2one('food.weeks', string='Week')

    food_ids = fields.Many2many('food.foods', string='Food Name')


class StudentFoodSelection(models.Model):

    _name = 'food.student.selection'

    _description = 'Student Food Selection'


    student_id = fields.Many2one('food.student', string='Student', required=True)

    day_id = fields.Many2one('food.days', string='Day', required=True)

    food_id = fields.Many2one('food.foods', string='Selected Food', required=True)






Explanation:

Student model:


Added a Student model to represent each student. You might already have a similar student model, in which case, you can skip this one.

Lunch model (food.foods):


This is your existing Lunch model. No changes here.

DayOfWeek model (food.days):


This is also your existing model for representing each day. The only change is a change in the field name from food_id to food_ids to make it clear it's a list of options.

StudentFoodSelection model (food.student.selection):


This new model captures each student's food choice on a given day. It has three fields:

student_id: A reference to the student.

day_id: A reference to the day for which the selection is made.

food_id: A reference to the food selected by the student




Computing the Selection Count

To calculate how many students have selected food1 or food2, you can add a computed field on the DayOfWeek model or create a method to run the calculation:



class DayOfWeek(models.Model):

    _inherit = 'food.days'


    food_selection_summary = fields.Text(string='Food Selection Summary', compute='_compute_food_selection_summary')


    def _compute_food_selection_summary(self):

        for record in self:

            summary = ""

            food_counts = {}

            selections = self.env['food.student.selection'].search([('day_id', '=', record.id)])

            for selection in selections:

                if selection.food_id.name not in food_counts:

                    food_counts[selection.food_id.name] = 0

                food_counts[selection.food_id.name] += 1


            summary = "\n".join(f"{food_name}: {count} students" for food_name, count in food_counts.items())

            record.food_selection_summary = summary





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
I want to count total no. of bills done by a biller...But always shows 1 from the "highest_biller"...
count odoo
Ảnh đại diện
0
thg 7 21
3127
Add value to selection field without coding
selection odoo
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
3
thg 12 19
4995
How do I get the value of a selection field - widget=radio ?
selection odoo odoo12
Ảnh đại diện
0
thg 4 22
5209
How to add new value in Selection in Settings Đã xử lý
settings selection odoo
Ảnh đại diện
Ảnh đại diện
1
thg 5 21
4577
Odoo Selection field issue Đã xử lý
selection odoo odoo12 odoo12.0
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
3
thg 3 24
7983
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