Migrate to version 3.8

(grafted from 9830fd31f3bea55c474e7c36f2a65ff10b4c436f)
This commit is contained in:
Sergi Almacellas Abellana 2015-12-10 22:47:07 +01:00
parent df798989ca
commit b5216120fa
13 changed files with 183 additions and 584 deletions

View File

@ -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

View File

@ -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):

View File

@ -54,14 +54,14 @@
id="act_contract_domain_draft">
<field name="name">Draft</field>
<field name="sequence" eval="10"/>
<field name="domain">[('state', '=', 'draft')]</field>
<field name="domain" eval="[('state', '=', 'draft')]" pyson="1"/>
<field name="act_window" ref="act_contract"/>
</record>
<record model="ir.action.act_window.domain"
id="act_contract_domain_validated">
<field name="name">Validated</field>
<field name="sequence" eval="20"/>
<field name="domain">[('state', '=', 'validated')]</field>
<field name="domain" eval="[('state', '=', 'validated')]" pyson="1"/>
<field name="act_window" ref="act_contract"/>
</record>
<record model="ir.action.act_window.domain"
@ -113,7 +113,8 @@
id="act_contract_consumption_domain_to_invoiced">
<field name="name">To Invoice</field>
<field name="sequence" eval="10"/>
<field name="domain">[('invoice_lines', '=', None)]</field>
<field name="domain" eval="[('invoice_lines', '=', None)]"
pyson="1"/>
<field name="act_window" ref="act_contract_consumption"/>
</record>
<record model="ir.action.act_window.domain"
@ -125,7 +126,8 @@
<record model="ir.action.act_window" id="act_invoices">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="domain">[('lines.origin.id', 'in', Eval('active_ids'), Eval('active_model'))]</field>
<field name="domain" eval="[('lines.origin.id', 'in', Eval('active_ids'), Eval('active_model'))]"
pyson="1"/>
</record>
<record model="ir.action.keyword" id="act_invoices_keyword1">
<field name="keyword">form_relate</field>
@ -135,7 +137,8 @@
<record model="ir.action.act_window" id="act_consumption_contracts">
<field name="name">Consumptions</field>
<field name="res_model">contract.consumption</field>
<field name="domain">[('contract', 'in', Eval('active_ids'))]</field>
<field name="domain" eval="[('contract', 'in', Eval('active_ids'))]"
pyson="1"/>
</record>
<record model="ir.action.keyword" id="act_consumption_contracts_keyword1">
<field name="keyword">form_relate</field>
@ -145,7 +148,8 @@
<record model="ir.action.act_window" id="act_consumption_contract_line">
<field name="name">Consumptions</field>
<field name="res_model">contract.consumption</field>
<field name="domain">[('contract_line', 'in', Eval('active_ids'))]</field>
<field name="domain" eval="[('contract_line', 'in', Eval('active_ids'))]"
pyson="1"/>
</record>
<record model="ir.action.keyword"
id="act_consumption_contract_line_keyword1">

View File

@ -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'

View File

@ -11,7 +11,8 @@
<record model="ir.action.act_window" id="act_open_contract">
<field name="name">Contracts</field>
<field name="res_model">contract</field>
<field name="domain">[('party', 'in', Eval('active_ids'))]</field>
<field name="domain" eval="[('party', 'in', Eval('active_ids'))]"
pyson="1"/>
</record>
<record model="ir.action.keyword"
id="act_open_contract_keyword1">

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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():

View File

@ -1,5 +1,5 @@
[tryton]
version=3.4.0
version=3.8.0
depends:
account_invoice
xml:

View File

@ -5,10 +5,10 @@
<xpath expr="/form" position="inside">
<group col="2" name="from_contract" string="" colspan="2">
<image name="tryton-dialog-warning" xexpand="0"
xfill="0" states="{'invisible': ~Bool(Eval('from_contract'))}"/>
xfill="0" states=""/>
<label string="Those/this invoice(s) have been generated from contracts, are you sure you want to credit them?"
id="credit_contract" colspan="2" yalign="0.0" xalign="0.0"
xexpand="1" states="{'invisible': ~Bool(Eval('from_contract'))}"/>
xexpand="1"/>
<label name="reinvoice_contract"/>
<field name="reinvoice_contract"/>
</group>