Files
enterprise-addons/sale_subscription/tests/test_report.py
T

141 lines
6.8 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.tests import tagged
from odoo.addons.sale_subscription.tests.common_sale_subscription import TestSubscriptionCommon
@tagged('post_install', '-at_install')
class TestSubscriptionReport(TestSubscriptionCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.other_currency = cls.setup_other_currency('CAD')
cls.company_data_2 = cls.setup_other_company()
def test_report_multi_currency(self):
sub_a = self.subscription.create({
'name': 'Company1 - Currency1',
'sale_order_template_id': self.subscription_tmpl.id,
'partner_id': self.user_portal.partner_id.id,
'currency_id': self.company.currency_id.id,
'plan_id': self.plan_month.id,
'order_line': [(0, 0, {
'name': "Product 1",
'product_id': self.product.id,
'product_uom_qty': 1,
})]
})
sub_a.action_confirm()
sub_b = self.subscription.create({
'name': 'Company1 - Currency2',
'partner_id': self.user_portal.partner_id.id,
'plan_id': self.plan_month.id,
'order_line': [(0, 0, {
'name': "Product 1",
'product_id': self.product.id,
'product_uom_qty': 1,
})]
})
sub_b.write({
'currency_id': self.other_currency.id,
})
self.other_currency.write({
'rate_ids': [(0, 0, {
'rate': 2,
})]
})
sub_b.action_confirm()
self.env.flush_all()
report_a = self.env['sale.subscription.report'].search([('name', '=', 'Company1 - Currency1')])
report_b = self.env['sale.subscription.report'].search([('name', '=', 'Company1 - Currency2')])
self.assertEqual(len(report_a), 1, 'There should be on report for the given pair currency/company')
self.assertEqual(len(report_b), 1, 'There should be on report for the given pair currency/company')
self.assertAlmostEqual(report_a.recurring_total, report_b.recurring_total * 2, delta=0.01,
msg='Report B should have 2 time more recurring compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_monthly, report_b.recurring_monthly * 2, delta=0.01,
msg='Report B should have 2 time more recurring monthly compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_yearly, report_b.recurring_yearly *2, delta=0.1,
msg='Report B should have 2 time more recurring yearly compared to A when converted in the same currency')
def test_report_multi_company(self):
sub_a = self.subscription.create({
'name': 'Company1 - Currency1 - Bis',
'sale_order_template_id': self.subscription_tmpl.id,
'partner_id': self.user_portal.partner_id.id,
'company_id': self.company.id,
'plan_id': self.plan_month.id,
'order_line': [Command.create({
'name': "Product 1",
'product_id': self.product.id,
'product_uom_qty': 1,
})]
})
sub_a.action_confirm()
default_pricelist_company_2 = self.env['product.pricelist'].search([
('company_id', '=', self.company_data_2['company'].id)
])
for rule in sub_a.pricelist_id.subscription_item_ids:
rule.copy({'pricelist_id': default_pricelist_company_2.id})
sub_b = self.subscription.create({
'name': 'Company2 - Currency1 - Bis',
'partner_id': self.user_portal.partner_id.id,
'company_id': self.company_data_2['company'].id,
'plan_id': self.plan_month.id,
'order_line': [Command.create({
'name': "Product 1",
'product_id': self.product.id,
'product_uom_qty': 1,
})]
})
sub_b.action_confirm()
sub_c = self.subscription.create({
'name': 'Company2 - Currency2 - Bis',
'partner_id': self.user_portal.partner_id.id,
'company_id': self.company_data_2['company'].id,
'plan_id': self.plan_month.id,
'order_line': [Command.create({
'name': "Product 1",
'product_id': self.product.id,
'product_uom_qty': 1,
})]
})
sub_c.write({
'currency_id': self.other_currency.id,
})
self.other_currency.write({
'rate_ids': [(0, 0, {
'rate': 2,
'company_id': self.company_data_2['company'].id,
})]
})
sub_c.action_confirm()
self.env.flush_all()
report_a = self.env['sale.subscription.report'].search([('name', '=', 'Company1 - Currency1 - Bis')])
report_b = self.env['sale.subscription.report'].search([('name', '=', 'Company2 - Currency1 - Bis')])
report_c = self.env['sale.subscription.report'].search([('name', '=', 'Company2 - Currency2 - Bis')])
self.assertEqual(len(report_a), 1, 'There should be on report for the given pair currency/company')
self.assertEqual(len(report_b), 1, 'There should be on report for the given pair currency/company')
self.assertEqual(len(report_c), 1, 'There should be on report for the given pair currency/company')
self.assertAlmostEqual(report_a.recurring_total, report_b.recurring_total, delta=0.01,
msg='Report B should have the same recurring compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_monthly, report_b.recurring_monthly, delta=0.01,
msg='Report B should have the same recurring monthly compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_yearly, report_b.recurring_yearly, delta=0.01,
msg='Report B should have the same recurring yearly compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_total, report_c.recurring_total * 2, delta=0.01,
msg='Report C should have 2 time more recurring compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_monthly, report_c.recurring_monthly * 2, delta=0.01,
msg='Report C should have 2 time more recurring monthly compared to A when converted in the same currency')
self.assertAlmostEqual(report_a.recurring_yearly, report_c.recurring_yearly * 2, delta=0.1,
msg='Report C should have 2 time more recurring yearly compared to A when converted in the same currency')