1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
# -*- coding: utf-8 -*-
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import tagged
from odoo import fields
@tagged('post_install', '-at_install')
class TestAccountInvoiceReport(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.other_currency = cls.setup_other_currency('EUR')
cls.company_data_2 = cls.setup_other_company()
cls.invoices = cls.env['account.move'].create([
{
'move_type': 'out_invoice',
'partner_id': cls.partner_a.id,
'invoice_date': fields.Date.from_string('2016-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 3,
'price_unit': 750,
}),
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 3000,
}),
]
},
{
'move_type': 'out_receipt',
'invoice_date': fields.Date.from_string('2016-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 6000,
}),
]
},
{
'move_type': 'out_refund',
'partner_id': cls.partner_a.id,
'invoice_date': fields.Date.from_string('2017-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 1200,
}),
]
},
{
'move_type': 'in_invoice',
'partner_id': cls.partner_a.id,
'invoice_date': fields.Date.from_string('2016-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 60,
}),
]
},
{
'move_type': 'in_receipt',
'partner_id': cls.partner_a.id,
'invoice_date': fields.Date.from_string('2016-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 60,
}),
]
},
{
'move_type': 'in_refund',
'partner_id': cls.partner_a.id,
'invoice_date': fields.Date.from_string('2017-01-01'),
'currency_id': cls.other_currency.id,
'invoice_line_ids': [
(0, None, {
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 12,
}),
]
},
])
def assertInvoiceReportValues(self, expected_values_list):
reports = self.env['account.invoice.report'].search([('company_id', '=', self.company_data['company'].id)], order='price_subtotal DESC, quantity ASC')
expected_values_dict = [{
'price_average': vals[0],
'price_subtotal': vals[1],
'quantity': vals[2],
'price_margin': vals[3],
'inventory_value': vals[4],
} for vals in expected_values_list]
self.assertRecordValues(reports, expected_values_dict)
def test_invoice_report_multiple_types(self):
self.assertInvoiceReportValues([
# pylint: disable=bad-whitespace
# price_average, price_subtotal, quantity, price_margin, inventory_value
[ 2000, 2000, 1, 1200, -800], # price_unit = 6000, currency.rate = 3.0
[ 1000, 1000, 1, 200, -800], # price_unit = 3000, currency.rate = 3.0
[ 250, 750, 3, -1650, -2400], # price_unit = 750, currency.rate = 2.0
[ 6, 6, 1, 0, -800], # price_unit = 12, currency.rate = 2.0
[ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0
[ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0
[ 600, -600, -1, 0, 800], # price_unit = 1200, currency.rate = 2.0
])
def test_invoice_report_multicompany_product_cost(self):
"""
In a multicompany environment, if you define one product with different standard price per company
the invoice analysis report should only display the product from the company
Standard Price in Company A: 800 (default setup)
Standard Price in Company B: 700
-> invoice report for Company A should remain the same
"""
self.product_a.with_company(self.company_data_2.get('company')).write({'standard_price': 700.0})
self.assertInvoiceReportValues([
# pylint: disable=bad-whitespace
# price_average, price_subtotal, quantity, price_margin, inventory_value
[ 2000, 2000, 1, 1200, -800], # price_unit = 6000, currency.rate = 3.0
[ 1000, 1000, 1, 200, -800], # price_unit = 3000, currency.rate = 3.0
[ 250, 750, 3, -1650, -2400], # price_unit = 750, currency.rate = 2.0
[ 6, 6, 1, 0, -800], # price_unit = 12, currency.rate = 2.0
[ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0
[ 20, -20, -1, 0, 800], # price_unit = 60, currency.rate = 3.0
[ 600, -600, -1, 0, 800], # price_unit = 1200, currency.rate = 2.0
])
|