Manage Replace Wizard

issue5820
#036415
This commit is contained in:
Raimon Esteve 2019-01-22 16:37:05 +01:00
parent 48d299f991
commit 245a1626bd
4 changed files with 214 additions and 0 deletions

View File

@ -2,6 +2,7 @@
# copyright notices and license terms.
from trytond.pool import Pool
from . import invoice
from . import party
def register():
@ -10,3 +11,6 @@ def register():
invoice.ConfigurationRelationType,
invoice.Invoice,
module='account_invoice_contact', type_='model')
Pool.register(
party.PartyReplace,
module='account_invoice_contact', type_='wizard')

15
party.py Normal file
View File

@ -0,0 +1,15 @@
# 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.invoice', 'contact'),
]

View File

@ -0,0 +1,188 @@
======================
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, create_tax_code
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
Install account_invoice_contact::
>>> config = activate_modules('account_invoice_contact')
Create company::
>>> _ = create_company()
>>> company = get_company()
>>> tax_identifier = company.party.identifiers.new()
>>> tax_identifier.type = 'eu_vat'
>>> tax_identifier.code = 'BE0897290877'
>>> company.party.save()
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear(company))
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
>>> period_ids = [p.id for p in fiscalyear.periods]
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> account_tax = accounts['tax']
>>> account_cash = accounts['cash']
Create tax::
>>> TaxCode = Model.get('account.tax.code')
>>> tax = create_tax(Decimal('.10'))
>>> tax.save()
>>> invoice_base_code = create_tax_code(tax, 'base', 'invoice')
>>> invoice_base_code.save()
>>> invoice_tax_code = create_tax_code(tax, 'tax', 'invoice')
>>> invoice_tax_code.save()
>>> credit_note_base_code = create_tax_code(tax, 'base', 'credit')
>>> credit_note_base_code.save()
>>> credit_note_tax_code = create_tax_code(tax, 'tax', 'credit')
>>> credit_note_tax_code.save()
Set Cash journal::
>>> Journal = Model.get('account.journal')
>>> journal_cash, = Journal.find([('type', '=', 'cash')])
>>> journal_cash.credit_account = account_cash
>>> journal_cash.debit_account = account_cash
>>> journal_cash.save()
Create party::
>>> Party = Model.get('party.party')
>>> party = Party(name='Party')
>>> party.save()
>>> party2 = Party(name='Party')
>>> party2.save()
Create Relation Types:
>>> RelationType = Model.get('party.relation.type')
>>> relation = RelationType()
>>> relation.name = 'Employee of'
>>> relation.save()
Account Configuration::
>>> Config = Model.get('account.invoice.configuration')
>>> config = Config(1)
>>> config.relation_types.append(relation)
>>> config.save()
Create Relation All:
>>> RelationAll = Model.get('party.relation.all')
>>> relation1 = RelationAll()
>>> relation1.from_ = party2
>>> relation1.to = party
>>> relation1.type = relation
>>> relation1.save()
>>> party2.reload()
>>> len(party2.relations) == 1
True
>>> relation2 = RelationAll()
>>> relation2.from_ = party
>>> relation2.to = party2
>>> relation2.type = relation
>>> relation2.save()
>>> party.reload()
>>> len(party.relations) == 1
True
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')
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.list_price = Decimal('40')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
>>> payment_term = PaymentTerm(name='Term')
>>> line = payment_term.lines.new(type='percent', ratio=Decimal('.5'))
>>> delta, = line.relativedeltas
>>> delta.days = 20
>>> line = payment_term.lines.new(type='remainder')
>>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
Create invoice::
>>> Invoice = Model.get('account.invoice')
>>> InvoiceLine = Model.get('account.invoice.line')
>>> invoice = Invoice()
>>> invoice.party = party2
>>> invoice.payment_term = payment_term
>>> invoice.contact = party
>>> 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)
>>> invoice.untaxed_amount
Decimal('220.00')
>>> invoice.tax_amount
Decimal('20.00')
>>> invoice.total_amount
Decimal('240.00')
>>> invoice.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::
>>> invoice.reload()
>>> invoice.contact == party2
True

View File

@ -2,8 +2,10 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import unittest
import doctest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import doctest_teardown, doctest_checker
class TestCase(ModuleTestCase):
@ -14,4 +16,9 @@ class TestCase(ModuleTestCase):
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
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