This question has been flagged
2 Replies
2043 Views

Hi everyone. 

I have a custom module name ''timbrados'', wich have 2 dates. DATEA1 AND DATEB1 and a integer field value = '154258'

what i want is to compare the dates on TIMBRADOS with the dates on ACCOUNT.MOVE

if dateA1<= INVOICEDATE1 and dateB1>= INVOICEDATE2

if the condition is true, i need to add that value from ''timbrados'' in the account.move form


i know it is about some python function but I'm a newbie on this and i dont know where to begin


Avatar
Discard
Best Answer

Hi,

If the fields are of type date, you can directly compare the values.

eg: if self.date_field_1 <= self.date_field_2:
# Write the code

If you want to add integer with field of type date, you should import relativedelta as shown below.

from datetime import date
from dateutil.relativedelta import relativedelta

value = 10
self.date_field_1 = date.today()
self.date_field_2 = self.date_field_1 + relativedelta(days=value)

Now the value of field date_field_2 will be date_field_1 + 10 days

Regards

Avatar
Discard
Best Answer

Hello, Diana

I hope you are doing well.

- You can compare two dates with a simple if function as shown in the example below.

Find Code in Comment. 

Hope, This will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari 

Avatar
Discard

Example:
So, You can write like this, in function in which you want to update your custom field:

You have two dates e.g. dateA1 and dateB1

def function_name(self):
custom_module_records = self.env[model].search([])
for record in custom_module_records:
for invoice in self:
if record.dateA1<= invoice.INVOICEDATE and record.dateB1>= invoice.INVOICEDATE:
invoice.update({'field':record.custom_field })

FYI:
model: Custom module records.
field: account.move's field that you want to update.
custom_field: custom module's field which you want to update in account.move.