Fix deletion of products with taxes on invoice edit
This commit is contained in:
parent
dfdc9fde76
commit
c882158da3
|
@ -20,6 +20,7 @@ $$
|
||||||
declare
|
declare
|
||||||
iid integer;
|
iid integer;
|
||||||
products_to_keep integer[];
|
products_to_keep integer[];
|
||||||
|
products_to_delete integer[];
|
||||||
company integer;
|
company integer;
|
||||||
ccode text;
|
ccode text;
|
||||||
product edited_invoice_product;
|
product edited_invoice_product;
|
||||||
|
@ -78,7 +79,16 @@ begin
|
||||||
join unnest(product.tax) as ptax(tax_id) using (tax_id);
|
join unnest(product.tax) as ptax(tax_id) using (tax_id);
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
delete from invoice_product where invoice_id = iid and not (invoice_product_id = any(products_to_keep));
|
select array_agg(invoice_product_id)
|
||||||
|
into products_to_delete
|
||||||
|
from invoice_product
|
||||||
|
where invoice_id = iid
|
||||||
|
and not (invoice_product_id = any(products_to_keep));
|
||||||
|
|
||||||
|
if array_length(products_to_delete, 1) > 0 then
|
||||||
|
delete from invoice_product_tax where invoice_product_id = any(products_to_delete);
|
||||||
|
delete from invoice_product where invoice_product_id = any(products_to_delete);
|
||||||
|
end if;
|
||||||
|
|
||||||
delete from invoice_tag where invoice_id = iid;
|
delete from invoice_tag where invoice_id = iid;
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,8 @@ values (19, 15, 7, 'P1.0', 1100)
|
||||||
;
|
;
|
||||||
|
|
||||||
insert into invoice_product_tax (invoice_product_id, tax_id, tax_rate)
|
insert into invoice_product_tax (invoice_product_id, tax_id, tax_rate)
|
||||||
values (20, 4, 0.21)
|
values (19, 4, 0.21)
|
||||||
|
, (20, 4, 0.21)
|
||||||
, (21, 3, -0.07)
|
, (21, 3, -0.07)
|
||||||
, (21, 4, 0.21)
|
, (21, 4, 0.21)
|
||||||
, (22, 3, -0.15)
|
, (22, 3, -0.15)
|
||||||
|
|
Loading…
Reference in New Issue