From e890682656b4739f489d34b954a1b1e8d9f78065 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 9 Oct 2017 14:57:16 +0200 Subject: [PATCH 1/2] [FIX] account: invoice analysis - Create a customer invoice of 100, validate - Refund the invoice - Go to Accounting > Reports > Business Intelligence > Invoices - A total of 200 is shown, while it should be 0. - The same occurs with a vendor bill (-200 instead of 0) The invoice lines have their sign modified at two places when used in the report: - in method `_compute_price` of `account.invoice.line` - in method `_from` of `account.invoice.report` The signs are computed with the following combination: |Invoice type|`_compute_price`|`_from`|Report sign| |------------|----------------|-------|-----------| |out_invoice | +1| +1| +1| |in_invoice | +1| -1| -1| |out_refund | -1| -1| +1| |in_refund | -1| +1| -1| This is not correct: out_invoice and out_refund should have opposite signs. Same applies to in_invoice and in_refund. opw-772479 Closes #19954 --- addons/account/report/account_invoice_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py index df6c4c5c2f8..7c6bf726a38 100644 --- a/addons/account/report/account_invoice_report.py +++ b/addons/account/report/account_invoice_report.py @@ -141,7 +141,7 @@ class AccountInvoiceReport(models.Model): JOIN ( -- Temporary table to decide if the qty should be added or retrieved (Invoice vs Refund) SELECT id,(CASE - WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text]) + WHEN ai.type::text = ANY (ARRAY['in_refund'::character varying::text, 'in_invoice'::character varying::text]) THEN -1 ELSE 1 END) AS sign From b1ce2dd6c163522633572b31f3aba29a21c5c913 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 10 Oct 2017 10:24:31 +0200 Subject: [PATCH 2/2] [FIX] account: invoiced amount - Create 2 companies: A is parent of B. - Demo is in Company A - Create 2 invoices for a partner: one in A, one in B (100 each) - Validate the invoices Connected as Demo, the 'Invoiced' amount on the partner form view (stat button) is 100, while clicking on it shows both invoices (total of 200). There is no need to manually add the company in the `where` clause since the `_apply_ir_rules` will take care of adding the appropriate multi-company rules. opw-772479 --- addons/account/models/partner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 08037dc6225..07e6c0e7c5f 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -279,7 +279,7 @@ class ResPartner(models.Model): # generate where clause to include multicompany rules where_query = account_invoice_report._where_calc([ - ('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']), ('company_id', '=', self.env.user.company_id.id), + ('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']), ('type', 'in', ('out_invoice', 'out_refund')) ]) account_invoice_report._apply_ir_rules(where_query, 'read')