Odoo Help


3 الإجابات
الصورة الرمزية

Nikhil Krishnan الإمارات العربية المتحدة

--Nikhil Krishnan--
| 7 7 10
Sharjah, الإمارات العربية المتحدة
--Nikhil Krishnan--

-- Nikhilkrishnan --

Exploring new ways in odoo..!
And want to become a key to the new odoo trends.

-> Odoo Consultancy,
-> Functional and Technical Consultant,
-> Requirement Collection and Analysis,
-> Module Customization,
-> Odoo ERP Community Contributor,
-> Handling ERP/Odoo projects,
-> ERP Workshop Facilitator.
Feel happy working with best and good supporting team.

#PITS Family

Nikhil Krishnan


Nikhil Krishnan الإمارات العربية المتحدة
3‏/3‏/2019 12:19 ص

Hi Daniel Abaka,

I think this will help you.

total_days= fields.Integer(compute="_compute_days", string='Days Count', copy=False, default=0, store=True)

    @api.depends('end_date', 'start_date')
def _compute_days(self): for s in self: if s.end_date and s.start_date:
a = s.end_date - s.start_date s.total_days = a.days else: s.total_days = 0



الصورة الرمزية

Niyas Raphy الهند

--Niyas Raphy--
| 7 7 11
Wayanad, Kerala, الهند
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

LinkedIn: https://www.linkedin.com/in/niyasraphy/
Whatsapp : +917736136763
Happy to help :)

Niyas Raphy الهند
2‏/3‏/2019 10:53 ص


You can make the total days field as a compute field and compute it's values from the entered values. 

Inside the compute function you can get the difference of days by subtracting the dates, see the sample.

If we have d1 as date1 and d2 as date2 , then difference = (d2-d1).days.

 Also see this link: https://stackoverflow.com/questions/151199/how-to-calculate-number-of-days-between-two-given-dates


Daniel Abaka ليبيريا
3‏/3‏/2019 12:56 ص

Hi Nikhil krishnan,
Thanks for the support but i'm facing error on this line

s.total_days = a.days
error message there is no attribute for days
10 التعليقات
Nikhil Krishnan الإمارات العربية المتحدة
3‏/3‏/2019 5:34 ص

Actually i test it in my system and working fine, so can you please show the screen shot of the error. and the python code too.

Nikhil Krishnan الإمارات العربية المتحدة
3‏/3‏/2019 5:37 ص





s.total_days = a.days

show the result to us.

Daniel Abaka ليبيريا
3‏/3‏/2019 4:39 م

Here is my python code

depature_date = fields.Date(string="Depature Date From Work", required=True)

return_date = fields.Date(string="Return Date To Work", required=True)

total_number_of_days = fields.Integer(compute="_compute_days",string="Total Number Of Work Days", copy=False, default=0, store=True)



def _compute_days(self):

for s in self:

if s.depature_date and s.return_date:

a = s.depature_date + s.return_date

s.total_number_of_days = a.days


s.total_number_of_days = 0

here is the error message

s.total_number_of_days = a.days

AttributeError: 'str' object has no attribute 'days'

Nikhil Krishnan الإمارات العربية المتحدة
3‏/3‏/2019 11:20 م

a = s.depature_date + s.return_date

why you are adding?

what is your logic? can you explain what is your exact need?

Daniel Abaka ليبيريا
4‏/3‏/2019 4:14 ص

I'm adding depature_date and return_date to get the total_number_of_days .

Daniel Abaka ليبيريا
4‏/3‏/2019 5:58 ص


The logic is once depature_date and return_date is selected automatically the total_number_of_days should be counted as total days selected.

I'm this ways i want to add depature_date + return_date to get the total days.

Nikhil Krishnan الإمارات العربية المتحدة
4‏/3‏/2019 7:04 ص

ok fine,

You try with this code.

a = s.return_date - s.depature_date

s.total_number_of_days = a.days

Nikhil Krishnan الإمارات العربية المتحدة
4‏/3‏/2019 7:10 ص

if we add two dates, we can't get a total number of days, differece of dates means the number of days between the two dates. i think you got the idea.

upvotes are appreciated

Daniel Abaka ليبيريا
4‏/3‏/2019 7:29 ص


I have try this code and get error

a = s.return_date - s.depature_date

s.total_number_of_days = a.days

Error Message

in _compute_days

a = s.depature_date - s.return_date

TypeError: unsupported operand type(s) for -: 'str' and 'str'

Nikhil Krishnan الإمارات العربية المتحدة
4‏/3‏/2019 11:11 م

please convert them in to date formate.

اطرح سؤالاً
Keep Informed
1 متابعين
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now