-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] base, tests: use freezegun lib to mock dates and datetimes
closes odoo#54227 Related: odoo/enterprise#11742 Signed-off-by: Olivier Dony (odo) <[email protected]>
- Loading branch information
Showing
8 changed files
with
155 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
# -*- coding: utf-8 -*- | ||
from freezegun import freeze_time | ||
|
||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon | ||
from odoo.tests import tagged | ||
|
||
|
||
@tagged('post_install', '-at_install') | ||
class TestAccountJournalDashboard(AccountTestInvoicingCommon): | ||
|
||
@freeze_time("2019-01-22") | ||
def test_customer_invoice_dashboard(self): | ||
with self.mocked_today('2019-01-22'): | ||
|
||
journal = self.company_data['default_journal_sale'] | ||
|
||
invoice = self.env['account.move'].create({ | ||
'move_type': 'out_invoice', | ||
'journal_id': journal.id, | ||
'partner_id': self.partner_a.id, | ||
'invoice_date': '2019-01-21', | ||
'date': '2019-01-21', | ||
'invoice_line_ids': [(0, 0, { | ||
'product_id': self.product_a.id, | ||
'quantity': 40.0, | ||
'name': 'product test 1', | ||
'discount': 10.00, | ||
'price_unit': 2.27, | ||
})] | ||
}) | ||
refund = self.env['account.move'].create({ | ||
'move_type': 'out_refund', | ||
'journal_id': journal.id, | ||
'partner_id': self.partner_a.id, | ||
'invoice_date': '2019-01-21', | ||
'date': '2019-01-21', | ||
'invoice_line_ids': [(0, 0, { | ||
'product_id': self.product_a.id, | ||
'quantity': 1.0, | ||
'name': 'product test 1', | ||
'price_unit': 13.3, | ||
})] | ||
}) | ||
|
||
# Check Draft | ||
dashboard_data = journal.get_journal_dashboard_datas() | ||
|
||
self.assertEqual(dashboard_data['number_draft'], 2) | ||
self.assertIn('68.42', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_waiting']) | ||
|
||
# Check Both | ||
invoice.post() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 1) | ||
self.assertIn('-13.30', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 1) | ||
self.assertIn('81.72', dashboard_data['sum_waiting']) | ||
|
||
# Check waiting payment | ||
refund.post() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 2) | ||
self.assertIn('68.42', dashboard_data['sum_waiting']) | ||
|
||
# Check partial | ||
receivable_account = refund.line_ids.mapped('account_id').filtered(lambda a: a.internal_type == 'receivable') | ||
payment = self.env['account.payment'].create({ | ||
'amount': 10.0, | ||
'payment_type': 'outbound', | ||
'partner_type': 'customer', | ||
'partner_id': self.partner_a.id, | ||
}) | ||
payment.action_post() | ||
|
||
(refund + payment.move_id).line_ids\ | ||
.filtered(lambda line: line.account_internal_type == 'receivable')\ | ||
.reconcile() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 2) | ||
self.assertIn('78.42', dashboard_data['sum_waiting']) | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_late'], 2) | ||
self.assertIn('78.42', dashboard_data['sum_late']) | ||
journal = self.company_data['default_journal_sale'] | ||
|
||
invoice = self.env['account.move'].create({ | ||
'move_type': 'out_invoice', | ||
'journal_id': journal.id, | ||
'partner_id': self.partner_a.id, | ||
'invoice_date': '2019-01-21', | ||
'date': '2019-01-21', | ||
'invoice_line_ids': [(0, 0, { | ||
'product_id': self.product_a.id, | ||
'quantity': 40.0, | ||
'name': 'product test 1', | ||
'discount': 10.00, | ||
'price_unit': 2.27, | ||
})] | ||
}) | ||
refund = self.env['account.move'].create({ | ||
'move_type': 'out_refund', | ||
'journal_id': journal.id, | ||
'partner_id': self.partner_a.id, | ||
'invoice_date': '2019-01-21', | ||
'date': '2019-01-21', | ||
'invoice_line_ids': [(0, 0, { | ||
'product_id': self.product_a.id, | ||
'quantity': 1.0, | ||
'name': 'product test 1', | ||
'price_unit': 13.3, | ||
})] | ||
}) | ||
|
||
# Check Draft | ||
dashboard_data = journal.get_journal_dashboard_datas() | ||
|
||
self.assertEqual(dashboard_data['number_draft'], 2) | ||
self.assertIn('68.42', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_waiting']) | ||
|
||
# Check Both | ||
invoice.post() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 1) | ||
self.assertIn('-13.30', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 1) | ||
self.assertIn('81.72', dashboard_data['sum_waiting']) | ||
|
||
# Check waiting payment | ||
refund.post() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 2) | ||
self.assertIn('68.42', dashboard_data['sum_waiting']) | ||
|
||
# Check partial | ||
receivable_account = refund.line_ids.mapped('account_id').filtered(lambda a: a.internal_type == 'receivable') | ||
payment = self.env['account.payment'].create({ | ||
'amount': 10.0, | ||
'payment_type': 'outbound', | ||
'partner_type': 'customer', | ||
'partner_id': self.partner_a.id, | ||
}) | ||
payment.action_post() | ||
|
||
(refund + payment.move_id).line_ids\ | ||
.filtered(lambda line: line.account_internal_type == 'receivable')\ | ||
.reconcile() | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_draft'], 0) | ||
self.assertIn('0.00', dashboard_data['sum_draft']) | ||
|
||
self.assertEqual(dashboard_data['number_waiting'], 2) | ||
self.assertIn('78.42', dashboard_data['sum_waiting']) | ||
|
||
dashboard_data = journal.get_journal_dashboard_datas() | ||
self.assertEqual(dashboard_data['number_late'], 2) | ||
self.assertIn('78.42', dashboard_data['sum_late']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.