Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1380 Vizualizări

hi everyone,

I want to ask, how can I accumulate the number of days in 1 month from each person, where each person inputs the number of days per week. Is there a separate program code?

Imagine profil
Abandonează
Cel mai bun răspuns

Yes, you can achieve this in Odoo by creating computed fields for the number of days and weeks. Here’s a basic example of how you might set this up:


from datetime import datetime


def _days_between(self, cr, uid, ids, field_name, arg, context=None):

    res = {}

    for cur_data in self.browse(cr, uid, ids, context=context):

        st_date = datetime.strptime(cur_data.st_date, "%Y-%m-%d")

        en_date = datetime.strptime(cur_data.en_date, "%Y-%m-%d")

        res[cur_data.id] = abs((en_date - st_date).days)

    return res


_columns = {

    'st_date': fields.date('Start date'),

    'en_date': fields.date('End date'),

    'days': fields.function(_days_between, type='char', string='NoD'),

}



In this example, st_date and en_date are the start and end dates, and days is a computed field that calculates the number of days between these two dates.

If each person inputs the number of days per week, you could create a similar function to accumulate these inputs over a month. However, the exact implementation would depend on how your Odoo system is set up and how the data is being inputted.

Please note that this is a simplified example and might need to be adjusted based on your specific requirements and Odoo setup.

Imagine profil
Abandonează
Autor

How can it be implemented into custom fields created through Odoo Studio?

Related Posts Răspunsuri Vizualizări Activitate
0
mar. 24
1554
2
sept. 23
2568
1
dec. 23
4685
1
ian. 23
5399
2
iun. 23
2699