Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1382 Zobrazení

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?

Avatar
Zrušit
Nejlepší odpověď

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.

Avatar
Zrušit
Autor

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

Related Posts Odpovědi Zobrazení Aktivita
0
bře 24
1556
2
zář 23
2569
1
pro 23
4685
1
led 23
5400
2
čvn 23
2699