From 33cd7305c0b0cd8f8f53e1e3f24bf34eb69b3343 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 9 Sep 2021 11:53:26 +0000 Subject: [PATCH] [FIX] sale: Invoicing target on sales team The invoicing target on sales team do not have to take the vendor bills into account. When we click on Sales analysis, we only see sales details. opw:2557852 closes odoo/odoo#77144 X-original-commit: 26871eabe3f95945c6cf2fc084e3af469ed561f6 Signed-off-by: Laurent Smet Signed-off-by: Simon Goffin (sig) --- addons/sale/models/crm_team.py | 11 +++------ addons/sale/tests/test_reinvoice.py | 37 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/addons/sale/models/crm_team.py b/addons/sale/models/crm_team.py index 40b00821a48..8428cef5401 100644 --- a/addons/sale/models/crm_team.py +++ b/addons/sale/models/crm_team.py @@ -74,19 +74,14 @@ class CrmTeam(models.Model): query = ''' SELECT - move.team_id AS team_id, - SUM(-line.balance) AS amount_untaxed_signed + move.team_id AS team_id, + SUM(move.amount_untaxed_signed) AS amount_untaxed_signed FROM account_move move - JOIN account_move_line line ON line.move_id = move.id - JOIN account_account account ON account.id = line.account_id - WHERE move.move_type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund') + WHERE move.move_type IN ('out_invoice', 'out_refund', 'out_receipt') AND move.payment_state IN ('in_payment', 'paid', 'reversed') AND move.state = 'posted' AND move.team_id IN %s AND move.date BETWEEN %s AND %s - AND line.tax_line_id IS NULL - AND line.display_type IS NULL - AND account.internal_type NOT IN ('receivable', 'payable') GROUP BY move.team_id ''' today = fields.Date.today() diff --git a/addons/sale/tests/test_reinvoice.py b/addons/sale/tests/test_reinvoice.py index 0ecb15ed54d..be414b81e8c 100644 --- a/addons/sale/tests/test_reinvoice.py +++ b/addons/sale/tests/test_reinvoice.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from freezegun import freeze_time from odoo.addons.sale.tests.common import TestSaleCommon from odoo.tests import Form, tagged @@ -115,6 +116,42 @@ class TestReInvoice(TestSaleCommon): self.assertEqual((sale_order_line5.price_unit, sale_order_line5.qty_delivered, sale_order_line5.product_uom_qty, sale_order_line5.qty_invoiced), (self.company_data['product_order_cost'].standard_price, 2, 0, 0), 'Sale line 5 is wrong after confirming 2e vendor invoice') self.assertEqual((sale_order_line6.price_unit, sale_order_line6.qty_delivered, sale_order_line6.product_uom_qty, sale_order_line6.qty_invoiced), (self.company_data['product_delivery_cost'].standard_price, 2, 0, 0), 'Sale line 6 is wrong after confirming 2e vendor invoice') + @freeze_time('2020-01-15') + def test_sales_team_invoiced(self): + """ Test invoiced field from sales team ony take into account the amount the sales channel has invoiced this month """ + + invoices = self.env['account.move'].create([ + { + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2020-01-10', + 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 1000.0})], + }, + { + 'move_type': 'out_refund', + 'partner_id': self.partner_a.id, + 'invoice_date': '2020-01-10', + 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 500.0})], + }, + { + 'move_type': 'in_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2020-01-01', + 'date': '2020-01-01', + 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 800.0})], + }, + ]) + invoices.action_post() + + for invoice in invoices: + self.env['account.payment.register']\ + .with_context(active_model='account.move', active_ids=invoice.ids)\ + .create({})\ + ._create_payments() + + invoices.flush() + self.assertRecordValues(invoices.team_id, [{'invoiced': 500.0}]) + def test_sales_price(self): """ Test invoicing vendor bill at sales price for products based on delivered and ordered quantities. Check no existing SO line is incremented, but when invoicing a second time, increment only the delivered so line.