Closed moylop260 closed 7 years ago
@josemoralesp What is the status of the revision of this PR?
Hello @moylop260 We can add this change without problems in Apex, but Lodi has more than 69 records with problems. I figured out that all records belong to the years 2014-2015, only two records in this year What do you advise me for this case?
I don't know the impact if we do something like this:
UPDATE
account_invoice AS i
SET
supplier_invoice_number = i.id || '-' || i.supplier_invoice_number
FROM
account_invoice AS ii
WHERE
lower(regexp_replace(i.supplier_invoice_number, '\W', '', 'g')) = lower(regexp_replace(ii.supplier_invoice_number, '\W', '', 'g'))
AND i.commercial_partner_id = ii.commercial_partner_id
AND i.company_id = ii.company_id AND i.type IN ('in_invoice', 'in_refund')
AND i.state NOT IN ('draft', 'cancel') AND i.id > ii.id;
What do you think?
Remove special chars in the where
using:
- i.supplier_invoice_number = ii.supplier_invoice_number
+ lower(regexp_replace(i.supplier_invoice_number, '\W', '', 'g')) = lower(regexp_replace(ii.supplier_invoice_number, '\W', '', 'g'))
@dsabrinarg Could we merge it?
@moylop260 waiting by the proper PR for lodi (needed code is still inside the DUMMY) in order to merge both PR's, I let you know asap!
@moylop260 done!
For a customer instance we have the following profiling results validating a invoice:
The
invoice_validate
use too much resources to detect a supplier_invoice_number unique.This PR change that constraint a sql unique constraint faster
NOTE: Before to install this module you need verify that the following sql don't emit results:
SELECT supplier_invoice_number,commercial_partner_id,count(*) AS repeated FROM account_invoice WHERE supplier_invoice_number IS NOT NULL AND state NOT IN ('draft', 'cancel') AND type IN ('in_invoice', 'in_refund') GROUP BY commercial_partner_id,supplier_invoice_number, company_id HAVING count(*) >=2