Skip to Content
मेन्यू
This question has been flagged

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
Discard
Best Answer

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
Discard
Author

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

Related Posts Replies Views Activity
0
मार्च 24
1556
2
सित॰ 23
2569
1
दिस॰ 23
4685
1
जन॰ 23
5400
2
जून 23
2699