From 1c0f181d7251a630dd327a5ecd3db533c0203439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Cabrera?= Date: Wed, 26 Apr 2023 19:59:07 +0100 Subject: [PATCH] fix: avoid accidental duplicate invoice --- partner_portal_extra_details/models/res_partner.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/partner_portal_extra_details/models/res_partner.py b/partner_portal_extra_details/models/res_partner.py index 481ac42..485a6eb 100644 --- a/partner_portal_extra_details/models/res_partner.py +++ b/partner_portal_extra_details/models/res_partner.py @@ -4,6 +4,7 @@ import logging +from datetime import date from odoo import api, fields, models, _ from odoo.exceptions import UserError @@ -133,8 +134,13 @@ def _send_mail_to_new_validate_user(self): account_invoice = invoices = self.env['account.invoice'] dom = [ ('partner_id', '=', partner.id), - ('state', '=', 'draft') + ( + 'date_invoice', + '>=', + date(date.today().year, 1, 1).strftime("%Y-%m-%d") + ) ] + _logger.debug("Domain: %s", dom) invoices |= account_invoice.search( dom, order='date_invoice asc', limit=1 )