From 9488a630711abcdfc6b9836b361ce146bb7a2f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismael=20Marcos=20Mart=C3=ADnez?= Date: Wed, 31 Jul 2024 10:05:12 +0200 Subject: [PATCH] =?UTF-8?q?Convert=20=E2=80=98test=E2=80=99=20files=20to?= =?UTF-8?q?=20.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/scenario_party_replace.rst | 134 ------------- tests/test_scenario.py | 23 --- tests/test_scenario_compensation_move.py | 235 +++++++++++++++++++++++ tests/test_scenario_party_replace.py | 128 ++++++++++++ 4 files changed, 363 insertions(+), 157 deletions(-) delete mode 100644 tests/scenario_party_replace.rst delete mode 100644 tests/test_scenario.py create mode 100644 tests/test_scenario_compensation_move.py create mode 100644 tests/test_scenario_party_replace.py diff --git a/tests/scenario_party_replace.rst b/tests/scenario_party_replace.rst deleted file mode 100644 index 585d728..0000000 --- a/tests/scenario_party_replace.rst +++ /dev/null @@ -1,134 +0,0 @@ -====================== -Party Replace Scenario -====================== - -Imports:: - >>> import datetime - >>> from dateutil.relativedelta import relativedelta - >>> from decimal import Decimal - >>> from operator import attrgetter - >>> from proteus import Model, Wizard - >>> from trytond.tests.tools import activate_modules - >>> from trytond.modules.company.tests.tools import create_company, \ - ... get_company - >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ - ... create_chart, get_accounts, create_tax - >>> from trytond.modules.account_invoice.tests.tools import \ - ... set_fiscalyear_invoice_sequences, create_payment_term - >>> today = datetime.date.today() - -Install account_bank Module:: - - >>> config = activate_modules('account_bank') - -Create company:: - - >>> _ = create_company() - >>> company = get_company() - -Create fiscal year:: - - >>> fiscalyear = set_fiscalyear_invoice_sequences( - ... create_fiscalyear(company)) - >>> fiscalyear.click('create_period') - -Create chart of accounts:: - - >>> _ = create_chart(company) - >>> accounts = get_accounts(company) - >>> receivable = accounts['receivable'] - >>> revenue = accounts['revenue'] - >>> expense = accounts['expense'] - >>> cash = accounts['cash'] - -Create tax:: - - >>> tax = create_tax(Decimal('.10')) - >>> tax.save() - -Create party:: - - >>> Party = Model.get('party.party') - >>> party = Party(name='Party') - >>> party.save() - -Create party2:: - - >>> party2 = Party(name='Party') - >>> party2.save() - -Create bank account:: - - >>> Bank = Model.get('bank') - >>> BankAccount = Model.get('bank.account') - >>> BankNumber = Model.get('bank.account.number') - >>> bparty = Party() - >>> bparty.name = 'Bank' - >>> bparty.save() - >>> bank = Bank(party=bparty) - >>> bank.save() - >>> bank_account = BankAccount() - >>> bank_account.bank = bank - >>> bank_number = bank_account.numbers.new() - >>> bank_number.type = 'iban' - >>> bank_number.number = 'BE82068896274468' - >>> bank_number = bank_account.numbers.new() - >>> bank_number.type = 'other' - >>> bank_number.number = 'not IBAN' - >>> bank_account.save() - >>> party.bank_accounts.append(bank_account) - >>> party.save() - -Create account category:: - - >>> ProductCategory = Model.get('product.category') - >>> account_category = ProductCategory(name="Account Category") - >>> account_category.accounting = True - >>> account_category.account_expense = expense - >>> account_category.account_revenue = revenue - >>> account_category.customer_taxes.append(tax) - >>> account_category.save() - -Create product:: - - >>> ProductUom = Model.get('product.uom') - >>> unit, = ProductUom.find([('name', '=', 'Unit')]) - >>> ProductTemplate = Model.get('product.template') - >>> Product = Model.get('product.product') - >>> template = ProductTemplate() - >>> template.name = 'product' - >>> template.default_uom = unit - >>> template.type = 'service' - >>> template.list_price = Decimal('40') - >>> template.account_category = account_category - >>> product, = template.products - >>> product.cost_price = Decimal('25') - >>> template.save() - >>> product, = template.products - -Create payment term:: - - >>> payment_term = create_payment_term() - >>> payment_term.save() - -Create payment type and link to party:: - - >>> PaymentType = Model.get('account.payment.type') - >>> payment_type = PaymentType(name='Type', kind='both') - >>> payment_type.account_bank='other' - >>> payment_type.party = party - >>> payment_type.bank_account = bank_account - >>> payment_type.save() - -Try replace active party:: - - >>> replace = Wizard('party.replace', models=[party]) - >>> replace.form.source = party - >>> replace.form.destination = party2 - >>> replace.execute('replace') - -Check fields have been replaced:: - - >>> payment_type.reload() - >>> payment_type.party == party2 - True diff --git a/tests/test_scenario.py b/tests/test_scenario.py deleted file mode 100644 index b5e24ad..0000000 --- a/tests/test_scenario.py +++ /dev/null @@ -1,23 +0,0 @@ - -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. - -import doctest -import glob -import os - -from trytond.tests.test_tryton import doctest_checker, doctest_teardown - - -def load_tests(loader, tests, pattern): - cwd = os.getcwd() - try: - os.chdir(os.path.dirname(__file__)) - for scenario in glob.glob('*.rst'): - tests.addTests(doctest.DocFileSuite( - scenario, tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) - finally: - os.chdir(cwd) - return tests \ No newline at end of file diff --git a/tests/test_scenario_compensation_move.py b/tests/test_scenario_compensation_move.py new file mode 100644 index 0000000..e1c4f3c --- /dev/null +++ b/tests/test_scenario_compensation_move.py @@ -0,0 +1,235 @@ +# ================ +# Invoice Scenario +# ================ + +# Imports +from trytond.modules.account_invoice.tests.tools import set_fiscalyear_invoice_sequences, create_payment_term +from trytond.modules.account.tests.tools import create_fiscalyear, create_chart, get_accounts, create_tax +from trytond.modules.company.tests.tools import create_company, get_company +from trytond.tests.tools import activate_modules +from proteus import Model, Wizard +from decimal import Decimal +import datetime +import unittest +from trytond.tests.test_tryton import drop_db + +class Test(unittest.TestCase): + def setUp(self): + drop_db() + super().setUp() + + def tearDown(self): + drop_db() + super().tearDown() + + def test(self): + + today = datetime.date.today() + + # Install account_bank Module + config = activate_modules('account_bank') + + # Create company + _ = create_company() + company = get_company() + + # Create fiscal year + fiscalyear = set_fiscalyear_invoice_sequences( + create_fiscalyear(company)) + fiscalyear.click('create_period') + + # Create chart of accounts + _ = create_chart(company) + accounts = get_accounts(company) + receivable = accounts['receivable'] + revenue = accounts['revenue'] + expense = accounts['expense'] + cash = accounts['cash'] + + # Create tax + tax = create_tax(Decimal('.10')) + tax.save() + + # Create party + Party = Model.get('party.party') + party = Party(name='Party') + party.save() + + # Create bank account + Bank = Model.get('bank') + BankAccount = Model.get('bank.account') + BankNumber = Model.get('bank.account.number') + bparty = Party() + bparty.name = 'Bank' + bparty.save() + bank = Bank(party=bparty) + bank.save() + bank_account = BankAccount() + bank_account.bank = bank + bank_number = bank_account.numbers.new() + bank_number.type = 'iban' + bank_number.number = 'BE82068896274468' + bank_number = bank_account.numbers.new() + bank_number.type = 'other' + bank_number.number = 'not IBAN' + bank_account.save() + party.bank_accounts.append(bank_account) + party.save() + + # Create account category + ProductCategory = Model.get('product.category') + account_category = ProductCategory(name="Account Category") + account_category.accounting = True + account_category.account_expense = expense + account_category.account_revenue = revenue + account_category.customer_taxes.append(tax) + account_category.save() + + # Create product + ProductUom = Model.get('product.uom') + unit, = ProductUom.find([('name', '=', 'Unit')]) + ProductTemplate = Model.get('product.template') + Product = Model.get('product.product') + template = ProductTemplate() + template.name = 'product' + template.default_uom = unit + template.type = 'service' + template.list_price = Decimal('40') + template.account_category = account_category + product, = template.products + product.cost_price = Decimal('25') + template.save() + product, = template.products + + # Create payment term + payment_term = create_payment_term() + payment_term.save() + + # Create payment type and link to party + PaymentType = Model.get('account.payment.type') + payable_payment_type = PaymentType(name='Type', kind='payable') + payable_payment_type.save() + receivable_payment_type = PaymentType(name='Type', kind='receivable') + receivable_payment_type.account_bank = 'party' + receivable_payment_type.save() + party.customer_payment_type = receivable_payment_type + party.supplier_payment_type = payable_payment_type + party.save() + + # Create invoice + Invoice = Model.get('account.invoice') + InvoiceLine = Model.get('account.invoice.line') + invoice = Invoice() + invoice.party = party + invoice.payment_term = payment_term + line = InvoiceLine() + invoice.lines.append(line) + line.product = product + line.quantity = 5 + line.unit_price = Decimal(40) + line = InvoiceLine() + invoice.lines.append(line) + line.account = revenue + line.description = 'Test' + line.quantity = 1 + line.unit_price = Decimal(20) + self.assertEqual(invoice.untaxed_amount + , Decimal('220.00') + ) + self.assertEqual(invoice.tax_amount + , Decimal('20.00') + ) + self.assertEqual(invoice.total_amount + , Decimal('240.00') + ) + self.assertEqual(invoice.payment_type, receivable_payment_type) + invoice.bank_account = bank_account + invoice.save() + invoice.click('post') + self.assertEqual(invoice.state, 'posted') + self.assertEqual(invoice.amount_to_pay, Decimal(240)) + line1, line2, _, _ = invoice.move.lines + self.assertEqual(line1.payment_type, receivable_payment_type) + self.assertEqual(line1.bank_account, bank_account) + self.assertEqual(line2.payment_type, None) + self.assertEqual(line2.bank_account, None) + + # Create credit note + Invoice = Model.get('account.invoice') + InvoiceLine = Model.get('account.invoice.line') + credit_note = Invoice() + credit_note.type = 'out' + credit_note.party = party + credit_note.payment_term = payment_term + credit_note.payment_type = payable_payment_type + line = InvoiceLine() + credit_note.lines.append(line) + line.product = product + line.quantity = -1 + line.unit_price = Decimal(40) + self.assertEqual(credit_note.untaxed_amount, Decimal(-40)) + self.assertEqual(credit_note.tax_amount, Decimal(-4)) + self.assertEqual(credit_note.total_amount, Decimal(-44)) + credit_note.save() + Invoice.post([credit_note.id], config.context) + credit_note.reload() + self.assertEqual(credit_note.state, 'posted') + self.assertEqual(credit_note.amount_to_pay, Decimal(-44)) + + # Partialy reconcile both lines + MoveLine = Model.get('account.move.line') + lines = MoveLine.find([ + ('account', '=', receivable.id)]) + compensation_move = Wizard('account.move.compensation_move', + models=lines) + compensation_move.form.maturity_date = today + compensation_move.form.account = receivable + compensation_move.form.payment_type = receivable_payment_type + compensation_move.form.bank_account = None + compensation_move.execute('create_move') + credit_note.reload() + self.assertEqual(credit_note.amount_to_pay + , Decimal('0') + ) + invoice.reload() + self.assertEqual(invoice.amount_to_pay + , Decimal('0') + ) + + # Create a move that pays the pending amount + Period = Model.get('account.period') + Move = Model.get('account.move') + move = Move() + period, = Period.find([ + ('start_date', '<=', today), + ('end_date', '>=', today), + ('type', '=', 'standard'), + ]) + move.period = period + move.date = today + move.journal = lines[0].move.journal + line = move.lines.new() + line.account = receivable + line.credit = Decimal('196.0') + line.debit = Decimal('0.0') + line.party = party + line = move.lines.new() + line.account = cash + line.debit = Decimal('196.0') + line.credit = Decimal('0.0') + move.click('post') + invoice.reload() + self.assertEqual(invoice.amount_to_pay + , Decimal('0') + ) + lines = MoveLine.find([ + ('account', '=', receivable.id)]) + to_reconcile = [l for l in lines if not l.reconciliation] + reconcile_lines = Wizard('account.move.reconcile_lines', + to_reconcile) + self.assertEqual(reconcile_lines.state, 'end') + invoice.reload() + self.assertEqual(invoice.amount_to_pay + , Decimal('0') + ) + self.assertEqual(invoice.state, 'paid') \ No newline at end of file diff --git a/tests/test_scenario_party_replace.py b/tests/test_scenario_party_replace.py new file mode 100644 index 0000000..8fbc2bb --- /dev/null +++ b/tests/test_scenario_party_replace.py @@ -0,0 +1,128 @@ +# ====================== +# Party Replace Scenario +# ====================== + +# Imports +from trytond.modules.account_invoice.tests.tools import set_fiscalyear_invoice_sequences, create_payment_term +from trytond.modules.account.tests.tools import create_fiscalyear, create_chart, get_accounts, create_tax +from trytond.modules.company.tests.tools import create_company, get_company +from trytond.tests.tools import activate_modules +from proteus import Model, Wizard +from decimal import Decimal +import datetime +import unittest +from trytond.tests.test_tryton import drop_db + +class Test(unittest.TestCase): + def setUp(self): + drop_db() + super().setUp() + + def tearDown(self): + drop_db() + super().tearDown() + + def test(self): + + today = datetime.date.today() + + # Install account_bank Module + config = activate_modules('account_bank') + + # Create company + _ = create_company() + company = get_company() + + # Create fiscal year + fiscalyear = set_fiscalyear_invoice_sequences( + create_fiscalyear(company)) + fiscalyear.click('create_period') + + # Create chart of accounts + _ = create_chart(company) + accounts = get_accounts(company) + receivable = accounts['receivable'] + revenue = accounts['revenue'] + expense = accounts['expense'] + cash = accounts['cash'] + + # Create tax + tax = create_tax(Decimal('.10')) + tax.save() + + # Create party + Party = Model.get('party.party') + party = Party(name='Party') + party.save() + + # Create party2 + party2 = Party(name='Party') + party2.save() + + # Create bank account + Bank = Model.get('bank') + BankAccount = Model.get('bank.account') + BankNumber = Model.get('bank.account.number') + bparty = Party() + bparty.name = 'Bank' + bparty.save() + bank = Bank(party=bparty) + bank.save() + bank_account = BankAccount() + bank_account.bank = bank + bank_number = bank_account.numbers.new() + bank_number.type = 'iban' + bank_number.number = 'BE82068896274468' + bank_number = bank_account.numbers.new() + bank_number.type = 'other' + bank_number.number = 'not IBAN' + bank_account.save() + party.bank_accounts.append(bank_account) + party.save() + + # Create account category + ProductCategory = Model.get('product.category') + account_category = ProductCategory(name="Account Category") + account_category.accounting = True + account_category.account_expense = expense + account_category.account_revenue = revenue + account_category.customer_taxes.append(tax) + account_category.save() + + # Create product + ProductUom = Model.get('product.uom') + unit, = ProductUom.find([('name', '=', 'Unit')]) + ProductTemplate = Model.get('product.template') + Product = Model.get('product.product') + template = ProductTemplate() + template.name = 'product' + template.default_uom = unit + template.type = 'service' + template.list_price = Decimal('40') + template.account_category = account_category + product, = template.products + product.cost_price = Decimal('25') + template.save() + product, = template.products + + # Create payment term + payment_term = create_payment_term() + payment_term.save() + + # Create payment type and link to party + PaymentType = Model.get('account.payment.type') + payment_type = PaymentType(name='Type', kind='both') + payment_type.account_bank='other' + payment_type.party = party + payment_type.bank_account = bank_account + payment_type.save() + + # Try replace active party + replace = Wizard('party.replace', models=[party]) + replace.form.source = party + replace.form.destination = party2 + replace.execute('replace') + + # Check fields have been replaced + payment_type.reload() + self.assertEqual(payment_type.party, party2) \ No newline at end of file