Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

how to count on selection value

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
selectioncountodoo
2 Replies
1981 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Jainesh Shah(Aktiv Software)
Best Answer

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
Portretas
Atmesti
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)

Portretas
CodeWasher
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
I want to count total no. of bills done by a biller...But always shows 1 from the "highest_biller"...
count odoo
Portretas
0
liep. 21
3127
Add value to selection field without coding
selection odoo
Portretas
Portretas
Portretas
3
gruod. 19
4993
How do I get the value of a selection field - widget=radio ?
selection odoo odoo12
Portretas
0
bal. 22
5203
How to add new value in Selection in Settings Solved
settings selection odoo
Portretas
Portretas
1
geg. 21
4575
Odoo Selection field issue Solved
selection odoo odoo12 odoo12.0
Portretas
Portretas
Portretas
Portretas
3
kov. 24
7981
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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