123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- # -*- coding: utf-8 -*-
- from freezegun import freeze_time
- from odoo.addons.account.tests.common import AccountTestInvoicingCommon
- from odoo.tests import tagged
- from odoo.tools.misc import format_amount
- @tagged('post_install', '-at_install')
- class TestAccountJournalDashboard(AccountTestInvoicingCommon):
- @freeze_time("2019-01-22")
- def test_customer_invoice_dashboard(self):
- 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,
- 'tax_ids': [],
- })]
- })
- 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,
- 'tax_ids': [],
- })]
- })
- # 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.action_post()
- dashboard_data = journal.get_journal_dashboard_datas()
- self.assertEqual(dashboard_data['number_draft'], 1)
- self.assertIn('-\N{ZERO WIDTH NO-BREAK SPACE}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.action_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
- 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_type == 'asset_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'])
- def test_sale_purchase_journal_for_multi_currency_purchase(self):
- currency = self.currency_data['currency']
- company_currency = self.company_data['currency']
- invoice = self.env['account.move'].create({
- 'move_type': 'in_invoice',
- 'invoice_date': '2017-01-01',
- 'date': '2017-01-01',
- 'partner_id': self.partner_a.id,
- 'currency_id': currency.id,
- 'invoice_line_ids': [
- (0, 0, {'name': 'test', 'price_unit': 200})
- ],
- })
- invoice.action_post()
- payment = self.env['account.payment'].create({
- 'amount': 90.0,
- 'date': '2016-01-01',
- 'payment_type': 'outbound',
- 'partner_type': 'supplier',
- 'partner_id': self.partner_a.id,
- 'currency_id': currency.id,
- })
- payment.action_post()
- (invoice + payment.move_id).line_ids.filtered_domain([
- ('account_id', '=', self.company_data['default_account_payable'].id)
- ]).reconcile()
- dashboard_data = self.company_data['default_journal_purchase'].get_journal_dashboard_datas()
- self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_waiting'])
- self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_late'])
- def test_sale_purchase_journal_for_multi_currency_sale(self):
- currency = self.currency_data['currency']
- company_currency = self.company_data['currency']
- invoice = self.env['account.move'].create({
- 'move_type': 'out_invoice',
- 'invoice_date': '2017-01-01',
- 'date': '2017-01-01',
- 'partner_id': self.partner_a.id,
- 'currency_id': currency.id,
- 'invoice_line_ids': [
- (0, 0, {'name': 'test', 'price_unit': 200})
- ],
- })
- invoice.action_post()
- payment = self.env['account.payment'].create({
- 'amount': 90.0,
- 'date': '2016-01-01',
- 'payment_type': 'inbound',
- 'partner_type': 'customer',
- 'partner_id': self.partner_a.id,
- 'currency_id': currency.id,
- })
- payment.action_post()
- (invoice + payment.move_id).line_ids.filtered_domain([
- ('account_id', '=', self.company_data['default_account_receivable'].id)
- ]).reconcile()
- dashboard_data = self.company_data['default_journal_sale'].get_journal_dashboard_datas()
- self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_waiting'])
- self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_late'])
|