From ad70f91daf3babfb396982a16b4677cd018f7020 Mon Sep 17 00:00:00 2001 From: Axay Javiya Date: Mon, 17 Apr 2017 19:41:54 +0530 Subject: [PATCH] [IMP] account_voucher: convert yml tests into python --- addons/account_voucher/__manifest__.py | 6 - .../account_voucher/test/account_voucher.yml | 54 -------- .../test/account_voucher_chart.yml | 46 ------- .../test/account_voucher_users.yml | 30 ----- addons/account_voucher/test/sales_receipt.yml | 25 ---- addons/account_voucher/tests/__init__.py | 4 + .../tests/test_account_voucher.py | 118 ++++++++++++++++++ 7 files changed, 122 insertions(+), 161 deletions(-) delete mode 100644 addons/account_voucher/test/account_voucher.yml delete mode 100644 addons/account_voucher/test/account_voucher_chart.yml delete mode 100644 addons/account_voucher/test/account_voucher_users.yml delete mode 100644 addons/account_voucher/test/sales_receipt.yml create mode 100644 addons/account_voucher/tests/__init__.py create mode 100644 addons/account_voucher/tests/test_account_voucher.py diff --git a/addons/account_voucher/__manifest__.py b/addons/account_voucher/__manifest__.py index 47ad10e75e6..31ad42bf9f8 100644 --- a/addons/account_voucher/__manifest__.py +++ b/addons/account_voucher/__manifest__.py @@ -34,12 +34,6 @@ This module manages: 'security/account_voucher_security.xml', 'data/account_voucher_data.xml', ], - 'test' : [ - 'test/account_voucher_users.yml', - 'test/account_voucher_chart.yml', - 'test/account_voucher.yml', - 'test/sales_receipt.yml', - ], 'auto_install': False, 'installable': True, } diff --git a/addons/account_voucher/test/account_voucher.yml b/addons/account_voucher/test/account_voucher.yml deleted file mode 100644 index df195e58d62..00000000000 --- a/addons/account_voucher/test/account_voucher.yml +++ /dev/null @@ -1,54 +0,0 @@ -- - I check the voucher module with user who is accountant. -- - !context - uid: 'res_users_account_voucher_user' - -- - In order to check account voucher module in Odoo I create a customer voucher -- - !record {model: account.voucher, id: account_voucher_voucherforaxelor0, view: view_sale_receipt_form}: - voucher_type: sale - account_id: a_cash - amount: 1000.0 - company_id: base.main_company - journal_id: sales_journal - name: Voucher for Axelor - narration: Basic Pc - line_ids: - - account_id: a_recv - price_unit: 1000.0 - name: Voucher for Axelor - partner_id: base.res_partner_12 - date: !eval time.strftime('%Y-%m-%d') - reference: none - -- - I check that Initially customer voucher is in the "Draft" state -- - !assert {model: account.voucher, id: account_voucher_voucherforaxelor0}: - - state == 'draft' -- - Now I create a Vendor Voucher -- - !record {model: account.voucher, id: account_voucher_voucheraxelor0}: - voucher_type: purchase - account_id: a_cash - amount: 1000.0 - company_id: base.main_company - journal_id: j_cash - name: Voucher Axelor - narration: PC Assemble SC234 - line_ids: - - account_id: a_cash - price_unit: 1000.0 - name: Voucher Axelor - partner_id: base.res_partner_12 - date: !eval time.strftime('%Y-%m-%d') - reference: none - -- - I check that Initially vendor voucher is in the "Draft" state -- - !assert {model: account.voucher, id: account_voucher_voucheraxelor0}: - - state == 'draft' diff --git a/addons/account_voucher/test/account_voucher_chart.yml b/addons/account_voucher/test/account_voucher_chart.yml deleted file mode 100644 index ad22fa54c45..00000000000 --- a/addons/account_voucher/test/account_voucher_chart.yml +++ /dev/null @@ -1,46 +0,0 @@ -- - Use voucher accountant user -- - !context - uid: 'res_users_account_voucher_user' -- - Create receivable account -- - !record {model: account.account, id: a_recv}: - code: X1012 - name: Debtors - (test) - reconcile: !eval True - user_type_id: account.data_account_type_receivable -- - Create sales account -- - !record {model: account.account, id: a_sale}: - code: X1020 - name: Product Sales - (test) - user_type_id: account.data_account_type_revenue -- - Create sales journal -- - !record {model: account.journal, id: sales_journal}: - name: Sales Journal - (test) - code: TSAJ - type: sale - refund_sequence: !eval True - default_debit_account_id: a_sale - default_credit_account_id: a_sale -- - Create cash account -- - !record {model: account.account, id: a_cash}: - code: X1015 - name: Cash - (test) - user_type_id: account.data_account_type_liquidity -- - Create cash journal -- - !record {model: account.journal, id: j_cash}: - code: VCSH - name: Cash Journal - (test) - type: cash - default_debit_account_id: a_cash - default_credit_account_id: a_cash diff --git a/addons/account_voucher/test/account_voucher_users.yml b/addons/account_voucher/test/account_voucher_users.yml deleted file mode 100644 index e4bab4df4b4..00000000000 --- a/addons/account_voucher/test/account_voucher_users.yml +++ /dev/null @@ -1,30 +0,0 @@ -- - Create a user as 'Accountant for account voucher' -- - !record {model: res.users, id: res_users_account_voucher_user, view: False}: - company_id: base.main_company - name: Voucher Accountant - login: vacc - email: accountant@yourcompany.com -- - I added groups to Accountant for account voucher. -- - !record {model: res.users, id: res_users_account_voucher_user}: - groups_id: - - base.group_partner_manager - - account.group_account_invoice -- - Create a user as 'Financial Manager for account voucher' -- - !record {model: res.users, id: res_users_account_voucher_manager, view: False}: - company_id: base.main_company - name: Financial Manager for voucher - login: fmv - email: finmanager@yourcompany.com -- - I added groups to Financial Manager for account voucher. -- - !record {model: res.users, id: res_users_account_voucher_manager}: - groups_id: - - base.group_partner_manager - - account.group_account_manager diff --git a/addons/account_voucher/test/sales_receipt.yml b/addons/account_voucher/test/sales_receipt.yml deleted file mode 100644 index d68930692bd..00000000000 --- a/addons/account_voucher/test/sales_receipt.yml +++ /dev/null @@ -1,25 +0,0 @@ -- - Accountant can also be created receipt and validate it there for I checked it with that user who is accountant. -- - !context - uid: 'res_users_account_voucher_user' -- - Creating a Voucher Receipt for partner Seagate with amount 30000.0 -- - !record {model: account.voucher, id: account_voucher_seagate_0, view: view_sale_receipt_form}: - account_id: a_recv - amount: 30000.0 - company_id: base.main_company - journal_id: sales_journal - line_ids: - - account_id: a_sale - price_unit: 30000.0 - name: Voucher Seagate - partner_id: base.res_partner_2 - date: !eval time.strftime("%Y-%m-%d") - voucher_type: sale -- - I check that the voucher state is Draft -- - !assert {model: account.voucher, id: account_voucher_seagate_0}: - - state == 'draft' diff --git a/addons/account_voucher/tests/__init__.py b/addons/account_voucher/tests/__init__.py new file mode 100644 index 00000000000..3f3fc7a78c8 --- /dev/null +++ b/addons/account_voucher/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_account_voucher diff --git a/addons/account_voucher/tests/test_account_voucher.py b/addons/account_voucher/tests/test_account_voucher.py new file mode 100644 index 00000000000..d45d62e4b5e --- /dev/null +++ b/addons/account_voucher/tests/test_account_voucher.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import tools +from odoo.modules.module import get_resource_path +from odoo.tests import common +import time + + +class TestAccountVoucher(common.TransactionCase): + + def _load(self, module, *args): + tools.convert_file(self.cr, 'account_voucher', + get_resource_path(module, *args), + {}, 'init', False, 'test', self.registry._assertion_report) + + def test_00_account_voucher_flow(self): + """ Create Account Voucher for Customer and Vendor """ + self._load('account', 'test', 'account_minimal_test.xml') + + # Models + Voucher = self.env['account.voucher'] + + # User-groups and References + company_id = self.ref('base.main_company') + partner_id = self.ref('base.res_partner_12') + account_id = self.ref('account_voucher.cash') + cash_journal_id = self.ref('account_voucher.cash_journal') + sales_journal_id = self.ref('account_voucher.sales_journal') + account_receivable_id = self.ref('account_voucher.a_recv') + + # Create a Account Voucher User + res_users_account_voucher_user = self.env['res.users'].create({ + 'name': 'Voucher Accountant', + 'login': 'vacc', + 'password': 'vacc', + 'email': 'accountant@yourcompany.com', + 'company_id': company_id, + 'groups_id': [(6, 0, [ + self.ref('base.group_partner_manager'), + self.ref('account.group_account_user'), + self.ref('account.group_account_invoice') + ])] + }) + + # Create Customer Voucher + account_voucher_customer = Voucher.sudo(res_users_account_voucher_user).create({ + 'voucher_type': 'sale', + 'partner_id': partner_id, + 'company_id': company_id, + 'account_id': account_id, + 'journal_id': sales_journal_id, + 'date': time.strftime('%Y-%m-%d'), + 'name': 'Voucher for Axelor', + 'amount': 1000.0, + 'narration': 'Basic Pc', + 'line_ids': [ + (0, 0, { + 'account_id': account_receivable_id, + 'price_unit': 1000.0, + 'name': 'Voucher for Axelor', + })] + }) + # Check Customer Voucher status. + self.assertEquals(account_voucher_customer.state, 'draft', 'Initially customer voucher should be in the "Draft" state') + + # Validate Customer voucher + account_voucher_customer.proforma_voucher() + # Check for Journal Entry of customer voucher + self.assertTrue(account_voucher_customer.move_id, 'No journal entry created !.') + # Find related account move line for Customer Voucher. + customer_voucher_move = account_voucher_customer.move_id + + # Check state of Account move line. + self.assertEquals(customer_voucher_move.state, 'posted', 'Account move state is incorrect.') + # Check partner of Account move line. + self.assertEquals(customer_voucher_move.partner_id.id, partner_id, 'Partner is incorrect on account move.') + # Check journal in Account move line. + self.assertEquals(customer_voucher_move.journal_id.id, sales_journal_id, 'Journal is incorrect on account move.') + # Check amount in Account move line. + self.assertEquals(customer_voucher_move.amount, 1000.0, 'Amount is incorrect in account move.') + + # Create Vendor Voucher + account_voucher_vendor = Voucher.sudo(res_users_account_voucher_user).create({ + 'voucher_type': 'purchase', + 'partner_id': partner_id, + 'company_id': company_id, + 'account_id': account_id, + 'journal_id': cash_journal_id, + 'date': time.strftime('%Y-%m-%d'), + 'name': 'Voucher Axelor', + 'amount': 1000.0, + 'narration': 'PC Assemble SC234', + 'line_ids': [ + (0, 0, { + 'account_id': account_receivable_id, + 'price_unit': 1000.0, + 'name': 'Voucher Axelor', + })] + }) + # Check Vendor Voucher status. + self.assertEquals(account_voucher_vendor.state, 'draft', 'Initially vendor voucher should be in the "Draft" state') + + # Validate Vendor voucher + account_voucher_vendor.proforma_voucher() + # Check for Journal Entry of vendor voucher + self.assertTrue(account_voucher_vendor.move_id, 'No journal entry created !.') + # Find related account move line for Vendor Voucher. + vendor_voucher_move = account_voucher_vendor.move_id + + # Check state of Account move line. + self.assertEquals(vendor_voucher_move.state, 'posted', 'Account move state is incorrect.') + # Check partner of Account move line. + self.assertEquals(vendor_voucher_move.partner_id.id, partner_id, 'Partner is incorrect on account move.') + # Check journal in Account move line. + self.assertEquals(vendor_voucher_move.journal_id.id, cash_journal_id, 'Journal is incorrect on account move.') + # Check amount in Account move line. + self.assertEquals(vendor_voucher_move.amount, 1000.0, 'Amount is incorrect in acccount move.')