[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 <smetl@users.noreply.github.com>
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2021-09-27 13:43:56 +00:00
committed by Laurent Smet
parent 639ea1e362
commit 33cd7305c0
2 changed files with 40 additions and 8 deletions
+3 -8
View File
@@ -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()
+37
View File
@@ -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.