From 78dee28d0c7f1434b6ab5878a45efefdfc72bbbb Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Tue, 22 Jan 2019 11:00:54 +0100 Subject: [PATCH] Manage Replace Wizard issue582 #036415 --- __init__.py | 2 + party.py | 17 ++++ tests/scenario_party_replace.rst | 134 +++++++++++++++++++++++++++++++ tests/test_account_bank.py | 4 + 4 files changed, 157 insertions(+) create mode 100644 party.py create mode 100644 tests/scenario_party_replace.rst diff --git a/__init__.py b/__init__.py index 0752058..1c07d33 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,7 @@ from trytond.pool import Pool from . import account from . import payment +from . import party def register(): @@ -22,4 +23,5 @@ def register(): Pool.register( payment.PayLine, account.CompensationMove, + party.PartyReplace, module='account_bank', type_='wizard') diff --git a/party.py b/party.py new file mode 100644 index 0000000..62e751e --- /dev/null +++ b/party.py @@ -0,0 +1,17 @@ +# This file is part of account_bank module for Tryton. +# The COPYRIGHT file at the top level of this repository contains +# the full copyright notices and license terms. +from trytond.pool import PoolMeta + +__all__ = ['PartyReplace'] + + +class PartyReplace(metaclass=PoolMeta): + __name__ = 'party.replace' + + @classmethod + def fields_to_replace(cls): + return super(PartyReplace, cls).fields_to_replace() + [ + ('account.payment.type', 'party'), + ('account.payment.journal', 'party'), + ] diff --git a/tests/scenario_party_replace.rst b/tests/scenario_party_replace.rst new file mode 100644 index 0000000..585d728 --- /dev/null +++ b/tests/scenario_party_replace.rst @@ -0,0 +1,134 @@ +====================== +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_account_bank.py b/tests/test_account_bank.py index 4a41ca8..4f0363f 100644 --- a/tests/test_account_bank.py +++ b/tests/test_account_bank.py @@ -22,4 +22,8 @@ def suite(): tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite('scenario_party_replace.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite