Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
360 Prikazi

I'm trying to make a filter to use in scheduled actions to give me invoices that are overdue by, let's say 14 days.


The filter to show overdue invoices is: 

["&", "&", ("invoice_date_due", "<", time.strftime("%Y-%m-%d")), ("state", "=", "posted"), ("payment_state", "in", ("not_paid", "partial"))]


I guess I just need to adjust it with timedelta, just don't know how.


Help would be much appriciated.

Avatar
Opusti

What version of Odoo are you using? Are you trying to do this in python, xml, or directly in the UI?

Avtor

it doesn't seem to work, I run Odoo 17 enterprise.

Maybe I'll give more info. I'm trying to make scheduled action to add a warning messeage to customers with ovedue invoices. So far I've manage to do it and it adds the warning, but I want to make it that it'll add the warning to only those who are overdue by more than 14 days.

The scheduled action is:

warnmsgstring='Customer has overdue invoices.'

blockedcontacts=env['res.partner'].search([('sale_warn_msg','=',warnmsgstring)])

for contact in blockedcontacts:

    contact['sale_warn']='no-message'

    contact['sale_warn_msg']=''

overdueinvoices=env['account.move'].search(["&", "&", "&", ("invoice_date_due", "<", time.strftime("%Y-%m-%d")), ("state", "=", "posted"), ("payment_state", "in", ["not_paid", "partial"]), ("amount_residual", "!=", "0")])

for invoice in overdueinvoices:

    invoice.partner_id['sale_warn']='warning'

    invoice.partner_id['sale_warn_msg']=warnmsgstring


It's scheduled to run everyday and first it clears the messeage and than checks for overdue and adds it again where it should.

Best Answer

I did this by creating a computed field on the invoice. The code for the computed field was:
for record in self:


    if record.invoice_date:

        record['x_studio_block_date'] = record.invoice_date + dateutil.relativedelta.relativedelta(days=14)

    else:

        record['x_studio_block_date'] = False


Then update the overdueinvoices=env part of your scheduled action to:

overdueinvoices=env['account.move'].search(["&", "&", "&", ("x_studio_block_date", "<", time.strftime("%Y-%m-%d")), ("state", "=", "posted"), ("payment_state", "in", ["not_paid", "partial"]), ("amount_residual", "!=", "0")])

FYI, it will only update invoices created after the new field is added if I remember correctly. I hope this helps.

Avatar
Opusti
Best Answer

Hi,


You can use datetime and timedelta to calculate the date 14 days ago, and compare invoice_date_due to that.


from datetime import datetime, timedelta

overdue_date = (datetime.today() - timedelta(days=14)).strftime("%Y-%m-%d")

domain = [

    "&", "&",

    ("invoice_date_due", "<", overdue_date),

    ("state", "=", "posted"),

    ("payment_state", "in", ("not_paid", "partial"))

]


Hope it helps


Avatar
Opusti