diff --git a/CHANGELOG b/CHANGELOG
index 4278f26..308dafe 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+Version 3.8.0 - 2015-12-09
* Add sequence on contract lines
* Make contracts start date and end date functional fields based on lines
* Improve rec_names of all fields
diff --git a/contract.py b/contract.py
index 19393ee..c4ce1a6 100644
--- a/contract.py
+++ b/contract.py
@@ -9,14 +9,13 @@ from sql.conditionals import Case
from sql.aggregate import Max, Min, Sum
from decimal import Decimal
-from trytond.config import config
from trytond.model import Workflow, ModelSQL, ModelView, Model, fields
from trytond.pool import Pool
from trytond.pyson import Eval, Bool, If
from trytond.transaction import Transaction
from trytond.tools import reduce_ids, grouped_slice
from trytond.wizard import Wizard, StateView, StateAction, Button
-DIGITS = config.getint('digits', 'unit_price_digits', 4)
+from trytond.modules.product import price_digits
__all__ = ['ContractService', 'Contract', 'ContractLine', 'RRuleMixin',
'ContractConsumption', 'CreateConsumptionsStart', 'CreateConsumptions']
@@ -367,7 +366,7 @@ class Contract(RRuleMixin, Workflow, ModelSQL, ModelView):
return ContractConsumption.create([c._save_values for c in to_create])
-class ContractLine(Workflow, ModelSQL, ModelView):
+class ContractLine(ModelSQL, ModelView):
'Contract Line'
__name__ = 'contract.line'
@@ -389,7 +388,7 @@ class ContractLine(Workflow, ModelSQL, ModelView):
],
depends=['start_date'])
description = fields.Text('Description', required=True)
- unit_price = fields.Numeric('Unit Price', digits=(16, DIGITS),
+ unit_price = fields.Numeric('Unit Price', digits=price_digits,
required=True)
last_consumption_date = fields.Function(fields.Date(
'Last Consumption Date'), 'get_last_consumption_date')
@@ -425,21 +424,17 @@ class ContractLine(Workflow, ModelSQL, ModelView):
@fields.depends('service', 'unit_price', 'description')
def on_change_service(self):
- changes = {}
if self.service:
- changes['name'] = self.service.rec_name
+ self.name = self.service.rec_name
if not self.unit_price:
- changes['unit_price'] = self.service.product.list_price
+ self.unit_price = self.service.product.list_price
if not self.description:
- changes['description'] = self.service.product.rec_name
- return changes
+ self.description = self.service.product.rec_name
@fields.depends('start_date', 'first_invoice_date')
def on_change_start_date(self):
- changes = {}
if self.start_date and not self.first_invoice_date:
- changes['first_invoice_date'] = self.start_date
- return changes
+ self.first_invoice_date = self.start_date
@classmethod
def get_last_consumption_date(cls, lines, name):
diff --git a/contract.xml b/contract.xml
index 55bf7cf..d8c8071 100644
--- a/contract.xml
+++ b/contract.xml
@@ -54,14 +54,14 @@
id="act_contract_domain_draft">
Draft
- [('state', '=', 'draft')]
+
Validated
- [('state', '=', 'validated')]
+
To Invoice
- [('invoice_lines', '=', None)]
+
Invoices
account.invoice
- [('lines.origin.id', 'in', Eval('active_ids'), Eval('active_model'))]
+
form_relate
@@ -135,7 +137,8 @@
Consumptions
contract.consumption
- [('contract', 'in', Eval('active_ids'))]
+
form_relate
@@ -145,7 +148,8 @@
Consumptions
contract.consumption
- [('contract_line', 'in', Eval('active_ids'))]
+
diff --git a/invoice.py b/invoice.py
index a4339fb..8ef5d8d 100644
--- a/invoice.py
+++ b/invoice.py
@@ -68,6 +68,15 @@ class CreditInvoiceStart:
help=('If true, the consumption that generated this line will be '
'reinvoiced.'))
+ @classmethod
+ def view_attributes(cls):
+ states = {'invisible': ~Bool(Eval('from_contract'))}
+ return [
+ ('/form//image[@name="tryton-dialog-warning"]', 'states', states),
+ ('/form//label[@id="credit_contract"]', 'states', states),
+ ]
+
+
class CreditInvoice:
__name__ = 'account.invoice.credit'
diff --git a/party.xml b/party.xml
index 52d8b4e..03779f0 100644
--- a/party.xml
+++ b/party.xml
@@ -11,7 +11,8 @@
Contracts
contract
- [('party', 'in', Eval('active_ids'))]
+
diff --git a/tests/scenario_contract_grouping.rst b/tests/scenario_contract_grouping.rst
index da2d8b4..fc5825e 100644
--- a/tests/scenario_contract_grouping.rst
+++ b/tests/scenario_contract_grouping.rst
@@ -8,6 +8,12 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
+ >>> 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, set_tax_code
+ >>> from.trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
@@ -19,124 +25,40 @@ Create database::
Install contract module::
- >>> Module = Model.get('ir.module.module')
+ >>> Module = Model.get('ir.module')
>>> contract_module, = Module.find([('name', '=', 'contract')])
>>> contract_module.click('install')
- >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
+ >>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company::
- >>> Currency = Model.get('currency.currency')
- >>> CurrencyRate = Model.get('currency.currency.rate')
- >>> currencies = Currency.find([('code', '=', 'USD')])
- >>> if not currencies:
- ... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
- ... rounding=Decimal('0.01'), mon_grouping='[]',
- ... mon_decimal_point='.')
- ... currency.save()
- ... CurrencyRate(date=today + relativedelta(month=1, day=1),
- ... rate=Decimal('1.0'), currency=currency).save()
- ... else:
- ... currency, = currencies
- >>> Company = Model.get('company.company')
- >>> Party = Model.get('party.party')
- >>> company_config = Wizard('company.company.config')
- >>> company_config.execute('company')
- >>> company = company_config.form
- >>> party = Party(name='Dunder Mifflin')
- >>> party.save()
- >>> company.party = party
- >>> company.currency = currency
- >>> company_config.execute('add')
- >>> company, = Company.find([])
-
-Reload the context::
-
- >>> User = Model.get('res.user')
- >>> config._context = User.get_preferences(True, config.context)
+ >>> _ = create_company()
+ >>> company = get_company()
Create fiscal year::
- >>> FiscalYear = Model.get('account.fiscalyear')
- >>> Sequence = Model.get('ir.sequence')
- >>> SequenceStrict = Model.get('ir.sequence.strict')
- >>> fiscalyear = FiscalYear(name=str(today.year))
- >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
- >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
- >>> fiscalyear.company = company
- >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
- ... company=company)
- >>> post_move_seq.save()
- >>> fiscalyear.post_move_sequence = post_move_seq
- >>> invoice_seq = SequenceStrict(name=str(today.year),
- ... code='account.invoice', company=company)
- >>> invoice_seq.save()
- >>> fiscalyear.out_invoice_sequence = invoice_seq
- >>> fiscalyear.in_invoice_sequence = invoice_seq
- >>> fiscalyear.out_credit_note_sequence = invoice_seq
- >>> fiscalyear.in_credit_note_sequence = invoice_seq
- >>> fiscalyear.save()
- >>> FiscalYear.create_period([fiscalyear.id], config.context)
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+ >>> period = fiscalyear.periods[0]
Create chart of accounts::
- >>> AccountTemplate = Model.get('account.account.template')
- >>> Account = Model.get('account.account')
- >>> account_template, = AccountTemplate.find([('parent', '=', None)])
- >>> create_chart = Wizard('account.create_chart')
- >>> create_chart.execute('account')
- >>> create_chart.form.account_template = account_template
- >>> create_chart.form.company = company
- >>> create_chart.execute('create_account')
- >>> receivable, = Account.find([
- ... ('kind', '=', 'receivable'),
- ... ('company', '=', company.id),
- ... ])
- >>> payable, = Account.find([
- ... ('kind', '=', 'payable'),
- ... ('company', '=', company.id),
- ... ])
- >>> revenue, = Account.find([
- ... ('kind', '=', 'revenue'),
- ... ('company', '=', company.id),
- ... ])
- >>> expense, = Account.find([
- ... ('kind', '=', 'expense'),
- ... ('company', '=', company.id),
- ... ])
- >>> account_tax, = Account.find([
- ... ('kind', '=', 'other'),
- ... ('company', '=', company.id),
- ... ('name', '=', 'Main Tax'),
- ... ])
- >>> create_chart.form.account_receivable = receivable
- >>> create_chart.form.account_payable = payable
- >>> create_chart.execute('create_properties')
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> receivable = accounts['receivable']
+ >>> revenue = accounts['revenue']
+ >>> expense = accounts['expense']
+ >>> account_tax = accounts['tax']
Create tax::
- >>> TaxCode = Model.get('account.tax.code')
- >>> Tax = Model.get('account.tax')
- >>> tax = Tax()
- >>> tax.name = 'Tax'
- >>> tax.description = 'Tax'
- >>> tax.type = 'percentage'
- >>> tax.rate = Decimal('.10')
- >>> tax.invoice_account = account_tax
- >>> tax.credit_note_account = account_tax
- >>> invoice_base_code = TaxCode(name='invoice base')
- >>> invoice_base_code.save()
- >>> tax.invoice_base_code = invoice_base_code
- >>> invoice_tax_code = TaxCode(name='invoice tax')
- >>> invoice_tax_code.save()
- >>> tax.invoice_tax_code = invoice_tax_code
- >>> credit_note_base_code = TaxCode(name='credit note base')
- >>> credit_note_base_code.save()
- >>> tax.credit_note_base_code = credit_note_base_code
- >>> credit_note_tax_code = TaxCode(name='credit note tax')
- >>> credit_note_tax_code.save()
- >>> tax.credit_note_tax_code = credit_note_tax_code
+ >>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax.save()
+ >>> invoice_base_code = tax.invoice_base_code
+ >>> invoice_tax_code = tax.invoice_tax_code
+ >>> credit_note_base_code = tax.credit_note_base_code
+ >>> credit_note_tax_code = tax.credit_note_tax_code
Create party::
@@ -170,13 +92,11 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
- >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Term')
- >>> payment_term_line = PaymentTermLine(type='percent', days=20,
- ... percentage=Decimal(50))
- >>> payment_term.lines.append(payment_term_line)
- >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
- >>> payment_term.lines.append(payment_term_line)
+ >>> line = payment_term.lines.new(type='percent', percentage=Decimal(50))
+ >>> delta = line.relativedeltas.new(days=20)
+ >>> line = payment_term.lines.new(type='remainder')
+ >>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
>>> party.customer_payment_term = payment_term
>>> party.save()
diff --git a/tests/scenario_monthly_full_month_contract.rst b/tests/scenario_monthly_full_month_contract.rst
index 464b187..92e531a 100644
--- a/tests/scenario_monthly_full_month_contract.rst
+++ b/tests/scenario_monthly_full_month_contract.rst
@@ -16,6 +16,12 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
+ >>> 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, set_tax_code
+ >>> from.trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
@@ -27,124 +33,40 @@ Create database::
Install account_invoice::
- >>> Module = Model.get('ir.module.module')
+ >>> Module = Model.get('ir.module')
>>> contract_module, = Module.find([('name', '=', 'contract')])
>>> Module.install([contract_module.id], config.context)
- >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
+ >>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company::
- >>> Currency = Model.get('currency.currency')
- >>> CurrencyRate = Model.get('currency.currency.rate')
- >>> currencies = Currency.find([('code', '=', 'USD')])
- >>> if not currencies:
- ... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
- ... rounding=Decimal('0.01'), mon_grouping='[]',
- ... mon_decimal_point='.')
- ... currency.save()
- ... CurrencyRate(date=today + relativedelta(month=1, day=1),
- ... rate=Decimal('1.0'), currency=currency).save()
- ... else:
- ... currency, = currencies
- >>> Company = Model.get('company.company')
- >>> Party = Model.get('party.party')
- >>> company_config = Wizard('company.company.config')
- >>> company_config.execute('company')
- >>> company = company_config.form
- >>> party = Party(name='Dunder Mifflin')
- >>> party.save()
- >>> company.party = party
- >>> company.currency = currency
- >>> company_config.execute('add')
- >>> company, = Company.find([])
-
-Reload the context::
-
- >>> User = Model.get('res.user')
- >>> config._context = User.get_preferences(True, config.context)
+ >>> _ = create_company()
+ >>> company = get_company()
Create fiscal year::
- >>> FiscalYear = Model.get('account.fiscalyear')
- >>> Sequence = Model.get('ir.sequence')
- >>> SequenceStrict = Model.get('ir.sequence.strict')
- >>> fiscalyear = FiscalYear(name=str(today.year))
- >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
- >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
- >>> fiscalyear.company = company
- >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
- ... company=company)
- >>> post_move_seq.save()
- >>> fiscalyear.post_move_sequence = post_move_seq
- >>> invoice_seq = SequenceStrict(name=str(today.year),
- ... code='account.invoice', company=company)
- >>> invoice_seq.save()
- >>> fiscalyear.out_invoice_sequence = invoice_seq
- >>> fiscalyear.in_invoice_sequence = invoice_seq
- >>> fiscalyear.out_credit_note_sequence = invoice_seq
- >>> fiscalyear.in_credit_note_sequence = invoice_seq
- >>> fiscalyear.save()
- >>> FiscalYear.create_period([fiscalyear.id], config.context)
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+ >>> period = fiscalyear.periods[0]
Create chart of accounts::
- >>> AccountTemplate = Model.get('account.account.template')
- >>> Account = Model.get('account.account')
- >>> account_template, = AccountTemplate.find([('parent', '=', None)])
- >>> create_chart = Wizard('account.create_chart')
- >>> create_chart.execute('account')
- >>> create_chart.form.account_template = account_template
- >>> create_chart.form.company = company
- >>> create_chart.execute('create_account')
- >>> receivable, = Account.find([
- ... ('kind', '=', 'receivable'),
- ... ('company', '=', company.id),
- ... ])
- >>> payable, = Account.find([
- ... ('kind', '=', 'payable'),
- ... ('company', '=', company.id),
- ... ])
- >>> revenue, = Account.find([
- ... ('kind', '=', 'revenue'),
- ... ('company', '=', company.id),
- ... ])
- >>> expense, = Account.find([
- ... ('kind', '=', 'expense'),
- ... ('company', '=', company.id),
- ... ])
- >>> account_tax, = Account.find([
- ... ('kind', '=', 'other'),
- ... ('company', '=', company.id),
- ... ('name', '=', 'Main Tax'),
- ... ])
- >>> create_chart.form.account_receivable = receivable
- >>> create_chart.form.account_payable = payable
- >>> create_chart.execute('create_properties')
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> receivable = accounts['receivable']
+ >>> revenue = accounts['revenue']
+ >>> expense = accounts['expense']
+ >>> account_tax = accounts['tax']
Create tax::
- >>> TaxCode = Model.get('account.tax.code')
- >>> Tax = Model.get('account.tax')
- >>> tax = Tax()
- >>> tax.name = 'Tax'
- >>> tax.description = 'Tax'
- >>> tax.type = 'percentage'
- >>> tax.rate = Decimal('.10')
- >>> tax.invoice_account = account_tax
- >>> tax.credit_note_account = account_tax
- >>> invoice_base_code = TaxCode(name='invoice base')
- >>> invoice_base_code.save()
- >>> tax.invoice_base_code = invoice_base_code
- >>> invoice_tax_code = TaxCode(name='invoice tax')
- >>> invoice_tax_code.save()
- >>> tax.invoice_tax_code = invoice_tax_code
- >>> credit_note_base_code = TaxCode(name='credit note base')
- >>> credit_note_base_code.save()
- >>> tax.credit_note_base_code = credit_note_base_code
- >>> credit_note_tax_code = TaxCode(name='credit note tax')
- >>> credit_note_tax_code.save()
- >>> tax.credit_note_tax_code = credit_note_tax_code
+ >>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax.save()
+ >>> invoice_base_code = tax.invoice_base_code
+ >>> invoice_tax_code = tax.invoice_tax_code
+ >>> credit_note_base_code = tax.credit_note_base_code
+ >>> credit_note_tax_code = tax.credit_note_tax_code
Create party::
@@ -175,13 +97,11 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
- >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Term')
- >>> payment_term_line = PaymentTermLine(type='percent', days=20,
- ... percentage=Decimal(50))
- >>> payment_term.lines.append(payment_term_line)
- >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
- >>> payment_term.lines.append(payment_term_line)
+ >>> line = payment_term.lines.new(type='percent', percentage=Decimal(50))
+ >>> delta = line.relativedeltas.new(days=20)
+ >>> line = payment_term.lines.new(type='remainder')
+ >>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
>>> party.customer_payment_term = payment_term
>>> party.save()
diff --git a/tests/scenario_monthly_full_month_with_invoice_date_contract.rst b/tests/scenario_monthly_full_month_with_invoice_date_contract.rst
index 8e15ef2..3027126 100644
--- a/tests/scenario_monthly_full_month_with_invoice_date_contract.rst
+++ b/tests/scenario_monthly_full_month_with_invoice_date_contract.rst
@@ -16,6 +16,12 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
+ >>> 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, set_tax_code
+ >>> from.trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
@@ -25,126 +31,42 @@ Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
-Install account_invoice::
+Install contract::
- >>> Module = Model.get('ir.module.module')
+ >>> Module = Model.get('ir.module')
>>> contract_module, = Module.find([('name', '=', 'contract')])
>>> Module.install([contract_module.id], config.context)
- >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
+ >>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company::
- >>> Currency = Model.get('currency.currency')
- >>> CurrencyRate = Model.get('currency.currency.rate')
- >>> currencies = Currency.find([('code', '=', 'USD')])
- >>> if not currencies:
- ... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
- ... rounding=Decimal('0.01'), mon_grouping='[]',
- ... mon_decimal_point='.')
- ... currency.save()
- ... CurrencyRate(date=today + relativedelta(month=1, day=1),
- ... rate=Decimal('1.0'), currency=currency).save()
- ... else:
- ... currency, = currencies
- >>> Company = Model.get('company.company')
- >>> Party = Model.get('party.party')
- >>> company_config = Wizard('company.company.config')
- >>> company_config.execute('company')
- >>> company = company_config.form
- >>> party = Party(name='Dunder Mifflin')
- >>> party.save()
- >>> company.party = party
- >>> company.currency = currency
- >>> company_config.execute('add')
- >>> company, = Company.find([])
-
-Reload the context::
-
- >>> User = Model.get('res.user')
- >>> config._context = User.get_preferences(True, config.context)
+ >>> _ = create_company()
+ >>> company = get_company()
Create fiscal year::
- >>> FiscalYear = Model.get('account.fiscalyear')
- >>> Sequence = Model.get('ir.sequence')
- >>> SequenceStrict = Model.get('ir.sequence.strict')
- >>> fiscalyear = FiscalYear(name=str(today.year))
- >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
- >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
- >>> fiscalyear.company = company
- >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
- ... company=company)
- >>> post_move_seq.save()
- >>> fiscalyear.post_move_sequence = post_move_seq
- >>> invoice_seq = SequenceStrict(name=str(today.year),
- ... code='account.invoice', company=company)
- >>> invoice_seq.save()
- >>> fiscalyear.out_invoice_sequence = invoice_seq
- >>> fiscalyear.in_invoice_sequence = invoice_seq
- >>> fiscalyear.out_credit_note_sequence = invoice_seq
- >>> fiscalyear.in_credit_note_sequence = invoice_seq
- >>> fiscalyear.save()
- >>> FiscalYear.create_period([fiscalyear.id], config.context)
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+ >>> period = fiscalyear.periods[0]
Create chart of accounts::
- >>> AccountTemplate = Model.get('account.account.template')
- >>> Account = Model.get('account.account')
- >>> account_template, = AccountTemplate.find([('parent', '=', None)])
- >>> create_chart = Wizard('account.create_chart')
- >>> create_chart.execute('account')
- >>> create_chart.form.account_template = account_template
- >>> create_chart.form.company = company
- >>> create_chart.execute('create_account')
- >>> receivable, = Account.find([
- ... ('kind', '=', 'receivable'),
- ... ('company', '=', company.id),
- ... ])
- >>> payable, = Account.find([
- ... ('kind', '=', 'payable'),
- ... ('company', '=', company.id),
- ... ])
- >>> revenue, = Account.find([
- ... ('kind', '=', 'revenue'),
- ... ('company', '=', company.id),
- ... ])
- >>> expense, = Account.find([
- ... ('kind', '=', 'expense'),
- ... ('company', '=', company.id),
- ... ])
- >>> account_tax, = Account.find([
- ... ('kind', '=', 'other'),
- ... ('company', '=', company.id),
- ... ('name', '=', 'Main Tax'),
- ... ])
- >>> create_chart.form.account_receivable = receivable
- >>> create_chart.form.account_payable = payable
- >>> create_chart.execute('create_properties')
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> receivable = accounts['receivable']
+ >>> revenue = accounts['revenue']
+ >>> expense = accounts['expense']
+ >>> account_tax = accounts['tax']
Create tax::
- >>> TaxCode = Model.get('account.tax.code')
- >>> Tax = Model.get('account.tax')
- >>> tax = Tax()
- >>> tax.name = 'Tax'
- >>> tax.description = 'Tax'
- >>> tax.type = 'percentage'
- >>> tax.rate = Decimal('.10')
- >>> tax.invoice_account = account_tax
- >>> tax.credit_note_account = account_tax
- >>> invoice_base_code = TaxCode(name='invoice base')
- >>> invoice_base_code.save()
- >>> tax.invoice_base_code = invoice_base_code
- >>> invoice_tax_code = TaxCode(name='invoice tax')
- >>> invoice_tax_code.save()
- >>> tax.invoice_tax_code = invoice_tax_code
- >>> credit_note_base_code = TaxCode(name='credit note base')
- >>> credit_note_base_code.save()
- >>> tax.credit_note_base_code = credit_note_base_code
- >>> credit_note_tax_code = TaxCode(name='credit note tax')
- >>> credit_note_tax_code.save()
- >>> tax.credit_note_tax_code = credit_note_tax_code
+ >>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax.save()
+ >>> invoice_base_code = tax.invoice_base_code
+ >>> invoice_tax_code = tax.invoice_tax_code
+ >>> credit_note_base_code = tax.credit_note_base_code
+ >>> credit_note_tax_code = tax.credit_note_tax_code
Create party::
@@ -175,13 +97,11 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
- >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Term')
- >>> payment_term_line = PaymentTermLine(type='percent', days=20,
- ... percentage=Decimal(50))
- >>> payment_term.lines.append(payment_term_line)
- >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
- >>> payment_term.lines.append(payment_term_line)
+ >>> line = payment_term.lines.new(type='percent', percentage=Decimal(50))
+ >>> delta = line.relativedeltas.new(days=20)
+ >>> line = payment_term.lines.new(type='remainder')
+ >>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
>>> party.customer_payment_term = payment_term
>>> party.save()
diff --git a/tests/scenario_monthly_natural_days_contract.rst b/tests/scenario_monthly_natural_days_contract.rst
index 4069b16..963fd32 100644
--- a/tests/scenario_monthly_natural_days_contract.rst
+++ b/tests/scenario_monthly_natural_days_contract.rst
@@ -16,6 +16,12 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
+ >>> 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, set_tax_code
+ >>> from.trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
@@ -25,126 +31,42 @@ Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
-Install account_invoice::
+Install contract::
- >>> Module = Model.get('ir.module.module')
+ >>> Module = Model.get('ir.module')
>>> contract_module, = Module.find([('name', '=', 'contract')])
>>> Module.install([contract_module.id], config.context)
- >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
+ >>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company::
- >>> Currency = Model.get('currency.currency')
- >>> CurrencyRate = Model.get('currency.currency.rate')
- >>> currencies = Currency.find([('code', '=', 'USD')])
- >>> if not currencies:
- ... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
- ... rounding=Decimal('0.01'), mon_grouping='[]',
- ... mon_decimal_point='.')
- ... currency.save()
- ... CurrencyRate(date=today + relativedelta(month=1, day=1),
- ... rate=Decimal('1.0'), currency=currency).save()
- ... else:
- ... currency, = currencies
- >>> Company = Model.get('company.company')
- >>> Party = Model.get('party.party')
- >>> company_config = Wizard('company.company.config')
- >>> company_config.execute('company')
- >>> company = company_config.form
- >>> party = Party(name='Dunder Mifflin')
- >>> party.save()
- >>> company.party = party
- >>> company.currency = currency
- >>> company_config.execute('add')
- >>> company, = Company.find([])
-
-Reload the context::
-
- >>> User = Model.get('res.user')
- >>> config._context = User.get_preferences(True, config.context)
+ >>> _ = create_company()
+ >>> company = get_company()
Create fiscal year::
- >>> FiscalYear = Model.get('account.fiscalyear')
- >>> Sequence = Model.get('ir.sequence')
- >>> SequenceStrict = Model.get('ir.sequence.strict')
- >>> fiscalyear = FiscalYear(name=str(today.year))
- >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
- >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
- >>> fiscalyear.company = company
- >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
- ... company=company)
- >>> post_move_seq.save()
- >>> fiscalyear.post_move_sequence = post_move_seq
- >>> invoice_seq = SequenceStrict(name=str(today.year),
- ... code='account.invoice', company=company)
- >>> invoice_seq.save()
- >>> fiscalyear.out_invoice_sequence = invoice_seq
- >>> fiscalyear.in_invoice_sequence = invoice_seq
- >>> fiscalyear.out_credit_note_sequence = invoice_seq
- >>> fiscalyear.in_credit_note_sequence = invoice_seq
- >>> fiscalyear.save()
- >>> FiscalYear.create_period([fiscalyear.id], config.context)
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+ >>> period = fiscalyear.periods[0]
Create chart of accounts::
- >>> AccountTemplate = Model.get('account.account.template')
- >>> Account = Model.get('account.account')
- >>> account_template, = AccountTemplate.find([('parent', '=', None)])
- >>> create_chart = Wizard('account.create_chart')
- >>> create_chart.execute('account')
- >>> create_chart.form.account_template = account_template
- >>> create_chart.form.company = company
- >>> create_chart.execute('create_account')
- >>> receivable, = Account.find([
- ... ('kind', '=', 'receivable'),
- ... ('company', '=', company.id),
- ... ])
- >>> payable, = Account.find([
- ... ('kind', '=', 'payable'),
- ... ('company', '=', company.id),
- ... ])
- >>> revenue, = Account.find([
- ... ('kind', '=', 'revenue'),
- ... ('company', '=', company.id),
- ... ])
- >>> expense, = Account.find([
- ... ('kind', '=', 'expense'),
- ... ('company', '=', company.id),
- ... ])
- >>> account_tax, = Account.find([
- ... ('kind', '=', 'other'),
- ... ('company', '=', company.id),
- ... ('name', '=', 'Main Tax'),
- ... ])
- >>> create_chart.form.account_receivable = receivable
- >>> create_chart.form.account_payable = payable
- >>> create_chart.execute('create_properties')
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> receivable = accounts['receivable']
+ >>> revenue = accounts['revenue']
+ >>> expense = accounts['expense']
+ >>> account_tax = accounts['tax']
Create tax::
- >>> TaxCode = Model.get('account.tax.code')
- >>> Tax = Model.get('account.tax')
- >>> tax = Tax()
- >>> tax.name = 'Tax'
- >>> tax.description = 'Tax'
- >>> tax.type = 'percentage'
- >>> tax.rate = Decimal('.10')
- >>> tax.invoice_account = account_tax
- >>> tax.credit_note_account = account_tax
- >>> invoice_base_code = TaxCode(name='invoice base')
- >>> invoice_base_code.save()
- >>> tax.invoice_base_code = invoice_base_code
- >>> invoice_tax_code = TaxCode(name='invoice tax')
- >>> invoice_tax_code.save()
- >>> tax.invoice_tax_code = invoice_tax_code
- >>> credit_note_base_code = TaxCode(name='credit note base')
- >>> credit_note_base_code.save()
- >>> tax.credit_note_base_code = credit_note_base_code
- >>> credit_note_tax_code = TaxCode(name='credit note tax')
- >>> credit_note_tax_code.save()
- >>> tax.credit_note_tax_code = credit_note_tax_code
+ >>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax.save()
+ >>> invoice_base_code = tax.invoice_base_code
+ >>> invoice_tax_code = tax.invoice_tax_code
+ >>> credit_note_base_code = tax.credit_note_base_code
+ >>> credit_note_tax_code = tax.credit_note_tax_code
Create party::
@@ -175,13 +97,11 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
- >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Term')
- >>> payment_term_line = PaymentTermLine(type='percent', days=20,
- ... percentage=Decimal(50))
- >>> payment_term.lines.append(payment_term_line)
- >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
- >>> payment_term.lines.append(payment_term_line)
+ >>> line = payment_term.lines.new(type='percent', percentage=Decimal(50))
+ >>> delta = line.relativedeltas.new(days=20)
+ >>> line = payment_term.lines.new(type='remainder')
+ >>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
>>> party.customer_payment_term = payment_term
>>> party.save()
diff --git a/tests/scenario_monthly_start_in_month_contract.rst b/tests/scenario_monthly_start_in_month_contract.rst
index 1b076db..f6f8f1e 100644
--- a/tests/scenario_monthly_start_in_month_contract.rst
+++ b/tests/scenario_monthly_start_in_month_contract.rst
@@ -16,6 +16,12 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
+ >>> 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, set_tax_code
+ >>> from.trytond.modules.account_invoice.tests.tools import \
+ ... set_fiscalyear_invoice_sequences
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
@@ -25,126 +31,42 @@ Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
-Install account_invoice::
+Install contract::
- >>> Module = Model.get('ir.module.module')
+ >>> Module = Model.get('ir.module')
>>> contract_module, = Module.find([('name', '=', 'contract')])
>>> Module.install([contract_module.id], config.context)
- >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
+ >>> Wizard('ir.module.install_upgrade').execute('upgrade')
Create company::
- >>> Currency = Model.get('currency.currency')
- >>> CurrencyRate = Model.get('currency.currency.rate')
- >>> currencies = Currency.find([('code', '=', 'USD')])
- >>> if not currencies:
- ... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
- ... rounding=Decimal('0.01'), mon_grouping='[]',
- ... mon_decimal_point='.')
- ... currency.save()
- ... CurrencyRate(date=today + relativedelta(month=1, day=1),
- ... rate=Decimal('1.0'), currency=currency).save()
- ... else:
- ... currency, = currencies
- >>> Company = Model.get('company.company')
- >>> Party = Model.get('party.party')
- >>> company_config = Wizard('company.company.config')
- >>> company_config.execute('company')
- >>> company = company_config.form
- >>> party = Party(name='Dunder Mifflin')
- >>> party.save()
- >>> company.party = party
- >>> company.currency = currency
- >>> company_config.execute('add')
- >>> company, = Company.find([])
-
-Reload the context::
-
- >>> User = Model.get('res.user')
- >>> config._context = User.get_preferences(True, config.context)
+ >>> _ = create_company()
+ >>> company = get_company()
Create fiscal year::
- >>> FiscalYear = Model.get('account.fiscalyear')
- >>> Sequence = Model.get('ir.sequence')
- >>> SequenceStrict = Model.get('ir.sequence.strict')
- >>> fiscalyear = FiscalYear(name=str(today.year))
- >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
- >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
- >>> fiscalyear.company = company
- >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
- ... company=company)
- >>> post_move_seq.save()
- >>> fiscalyear.post_move_sequence = post_move_seq
- >>> invoice_seq = SequenceStrict(name=str(today.year),
- ... code='account.invoice', company=company)
- >>> invoice_seq.save()
- >>> fiscalyear.out_invoice_sequence = invoice_seq
- >>> fiscalyear.in_invoice_sequence = invoice_seq
- >>> fiscalyear.out_credit_note_sequence = invoice_seq
- >>> fiscalyear.in_credit_note_sequence = invoice_seq
- >>> fiscalyear.save()
- >>> FiscalYear.create_period([fiscalyear.id], config.context)
+ >>> fiscalyear = set_fiscalyear_invoice_sequences(
+ ... create_fiscalyear(company))
+ >>> fiscalyear.click('create_period')
+ >>> period = fiscalyear.periods[0]
Create chart of accounts::
- >>> AccountTemplate = Model.get('account.account.template')
- >>> Account = Model.get('account.account')
- >>> account_template, = AccountTemplate.find([('parent', '=', None)])
- >>> create_chart = Wizard('account.create_chart')
- >>> create_chart.execute('account')
- >>> create_chart.form.account_template = account_template
- >>> create_chart.form.company = company
- >>> create_chart.execute('create_account')
- >>> receivable, = Account.find([
- ... ('kind', '=', 'receivable'),
- ... ('company', '=', company.id),
- ... ])
- >>> payable, = Account.find([
- ... ('kind', '=', 'payable'),
- ... ('company', '=', company.id),
- ... ])
- >>> revenue, = Account.find([
- ... ('kind', '=', 'revenue'),
- ... ('company', '=', company.id),
- ... ])
- >>> expense, = Account.find([
- ... ('kind', '=', 'expense'),
- ... ('company', '=', company.id),
- ... ])
- >>> account_tax, = Account.find([
- ... ('kind', '=', 'other'),
- ... ('company', '=', company.id),
- ... ('name', '=', 'Main Tax'),
- ... ])
- >>> create_chart.form.account_receivable = receivable
- >>> create_chart.form.account_payable = payable
- >>> create_chart.execute('create_properties')
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> receivable = accounts['receivable']
+ >>> revenue = accounts['revenue']
+ >>> expense = accounts['expense']
+ >>> account_tax = accounts['tax']
Create tax::
- >>> TaxCode = Model.get('account.tax.code')
- >>> Tax = Model.get('account.tax')
- >>> tax = Tax()
- >>> tax.name = 'Tax'
- >>> tax.description = 'Tax'
- >>> tax.type = 'percentage'
- >>> tax.rate = Decimal('.10')
- >>> tax.invoice_account = account_tax
- >>> tax.credit_note_account = account_tax
- >>> invoice_base_code = TaxCode(name='invoice base')
- >>> invoice_base_code.save()
- >>> tax.invoice_base_code = invoice_base_code
- >>> invoice_tax_code = TaxCode(name='invoice tax')
- >>> invoice_tax_code.save()
- >>> tax.invoice_tax_code = invoice_tax_code
- >>> credit_note_base_code = TaxCode(name='credit note base')
- >>> credit_note_base_code.save()
- >>> tax.credit_note_base_code = credit_note_base_code
- >>> credit_note_tax_code = TaxCode(name='credit note tax')
- >>> credit_note_tax_code.save()
- >>> tax.credit_note_tax_code = credit_note_tax_code
+ >>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax.save()
+ >>> invoice_base_code = tax.invoice_base_code
+ >>> invoice_tax_code = tax.invoice_tax_code
+ >>> credit_note_base_code = tax.credit_note_base_code
+ >>> credit_note_tax_code = tax.credit_note_tax_code
Create party::
@@ -152,7 +74,6 @@ Create party::
>>> party = Party(name='Party')
>>> party.save()
-
Configure unit to accept decimals::
>>> ProductUom = Model.get('product.uom')
@@ -182,13 +103,11 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
- >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Term')
- >>> payment_term_line = PaymentTermLine(type='percent', days=20,
- ... percentage=Decimal(50))
- >>> payment_term.lines.append(payment_term_line)
- >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
- >>> payment_term.lines.append(payment_term_line)
+ >>> line = payment_term.lines.new(type='percent', percentage=Decimal(50))
+ >>> delta = line.relativedeltas.new(days=20)
+ >>> line = payment_term.lines.new(type='remainder')
+ >>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
>>> party.customer_payment_term = payment_term
>>> party.save()
diff --git a/tests/test_contract.py b/tests/test_contract.py
index 0d5564d..4991f04 100644
--- a/tests/test_contract.py
+++ b/tests/test_contract.py
@@ -3,23 +3,13 @@
import unittest
import doctest
import trytond.tests.test_tryton
-from trytond.tests.test_tryton import test_view, test_depends
+from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
-class TestContractCase(unittest.TestCase):
+class TestContractCase(ModuleTestCase):
'Test Contract module'
-
- def setUp(self):
- trytond.tests.test_tryton.install_module('contract')
-
- def test0005views(self):
- 'Test views'
- test_view('contract')
-
- def test0006depends(self):
- 'Test depends'
- test_depends()
+ module = 'contract'
def suite():
diff --git a/tryton.cfg b/tryton.cfg
index 140fb86..f7c091c 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -1,5 +1,5 @@
[tryton]
-version=3.4.0
+version=3.8.0
depends:
account_invoice
xml:
diff --git a/view/credit_start_form.xml b/view/credit_start_form.xml
index 8afa895..6a77b27 100644
--- a/view/credit_start_form.xml
+++ b/view/credit_start_form.xml
@@ -5,10 +5,10 @@
+ xfill="0" states=""/>
+ xexpand="1"/>