__metaclass__ at class level

adapt domain to pyson api
adapt to asset_owner module
adapt tests to new api
This commit is contained in:
??ngel ??lvarez 2016-04-14 13:37:06 +02:00
parent afbc4109a8
commit d467862bf1
5 changed files with 70 additions and 125 deletions

View File

@ -9,9 +9,14 @@ Imports::
>>> from decimal import Decimal
>>> from operator import attrgetter
>>> from proteus import config, Model, Wizard
>>> today = datetime.datetime.combine(datetime.date.today(),
... datetime.datetime.min.time())
>>> tomorrow = datetime.date.today() + relativedelta(days=1)
>>> 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.date.today()
Create database::
@ -20,104 +25,40 @@ Create database::
Install sale::
>>> Module = Model.get('ir.module.module')
>>> Module = Model.get('ir.module')
>>> module, = Module.find([('name', '=', 'asset_work_project')])
>>> Module.install([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='U.S. Dollar', symbol='$', code='USD',
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
... mon_decimal_point='.', mon_thousands_sep=',')
... 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')
Create chart of accounts::
>>> AccountTemplate = Model.get('account.account.template')
>>> Account = Model.get('account.account')
>>> Journal = Model.get('account.journal')
>>> 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),
... ])
>>> create_chart.form.account_receivable = receivable
>>> create_chart.form.account_payable = payable
>>> create_chart.execute('create_properties')
>>> cash, = Account.find([
... ('kind', '=', 'other'),
... ('name', '=', 'Main Cash'),
... ('company', '=', company.id),
... ])
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
>>> cash_journal.credit_account = cash
>>> cash_journal.debit_account = cash
>>> cash_journal.save()
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> payable = accounts['payable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> account_tax = accounts['tax']
Create tax::
>>> 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 parties::
@ -174,29 +115,36 @@ Create product::
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
>>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
>>> payment_term = PaymentTerm(name='Direct')
>>> payment_term_line = PaymentTermLine(type='remainder', days=0)
>>> payment_term.lines.append(payment_term_line)
>>> payment_term = PaymentTerm(name='Term')
>>> line = payment_term.lines.new(type='remainder')
>>> payment_term.save()
Create an asset::
>>> Asset = Model.get('asset')
>>> AssetOwner = Model.get('asset.owner')
>>> asset = Asset()
>>> asset.name = 'Asset'
>>> asset.product = product
>>> asset.owner = customer
>>> owner = AssetOwner()
>>> owner.owner = customer
>>> owner.asset = asset
>>> owner.from_date = today
>>> asset.save()
>>> owner.save()
>>> other_asset = Asset()
>>> other_asset.name = 'Other Asset'
>>> other_asset.product = product
>>> other_asset.owner = customer
>>> other_asset.save()
>>> owner2 = AssetOwner()
>>> owner2.owner = customer
>>> owner2.from_date = today
>>> owner2.asset = other_asset
>>> owner2.save()
Configure shipment work::
>>> Sequence = Model.get('ir.sequence')
>>> StockConfig = Model.get('stock.configuration')
>>> stock_config = StockConfig(1)
>>> shipment_work_sequence, = Sequence.find([
@ -232,18 +180,19 @@ Create a contract::
>>> contract = Contract()
>>> contract.party = customer
>>> contract.start_date = today
>>> contract.first_invoice_date = today
>>> contract.start_period_date = today
>>> contract.freq = 'monthly'
>>> contract.interval = 1
>>> line = contract.lines.new()
>>> line.service = service
>>> line.create_shipment_work = True
>>> line.first_invoice_date = today
>>> line.first_shipment_date = today
>>> line.start_date = today
>>> line.asset = asset
>>> contract.click('validate_contract')
>>> contract.click('confirm')
>>> contract.state
u'validated'
u'confirmed'
>>> contract_line, = contract.lines
A project it's created for the contract::

View File

@ -3,29 +3,21 @@
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 doctest_setup, doctest_teardown
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import (doctest_setup, doctest_teardown,
doctest_checker)
class TestCase(unittest.TestCase):
'Test module'
def setUp(self):
trytond.tests.test_tryton.install_module('asset_work_project')
def test0005views(self):
'Test views'
test_view('asset_work_project')
def test0006depends(self):
'Test depends'
test_depends()
class TestAssetWorkProject(ModuleTestCase):
'Test Asset Work Project'
module = "asset_work_project"
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestAssetWorkProject))
suite.addTests(doctest.DocFileSuite('scenario_asset_work_project.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE,
checker=doctest_checker))
return suite

View File

@ -1,10 +1,10 @@
[tryton]
version=3.4.0
version=3.9.0
depends:
asset_contract
work_project
asset_owner
extras_depend:
asset_zone
asset_owner
xml:
work.xml

15
work.py
View File

@ -7,11 +7,11 @@ from trytond.pyson import Eval, If, Bool
__all___ = ['Project', 'ShipmentWork', 'ContractLine', 'Contract']
__metaclass__ = PoolMeta
class Project:
__name__ = 'work.project'
__metaclass__ = PoolMeta
asset = fields.Many2One('asset', 'Asset', select=True)
contract_lines = fields.One2Many('contract.line', 'project',
@ -37,7 +37,7 @@ class Project:
# If asset_owner module is installed we can add this domain
if hasattr(Asset, 'owner'):
cls.asset.domain = [
('owner', '=', Eval('party')),
('current_owner', '=', Eval('party')),
]
cls.asset.depends.append('party')
@ -78,6 +78,7 @@ class Project:
class ShipmentWork:
__name__ = 'shipment.work'
__metaclass__ = PoolMeta
@classmethod
def __setup__(cls):
@ -90,6 +91,7 @@ class ShipmentWork:
class Contract:
__name__ = 'contract'
__metaclass__ = PoolMeta
projects = fields.Function(fields.One2Many('work.project', None,
'Projects'),
@ -107,8 +109,8 @@ class Contract:
return [('lines.projects',) + tuple(clause[1:])]
@classmethod
def validate_contract(cls, contracts):
super(Contract, cls).validate_contract(contracts)
def confirm(cls, contracts):
super(Contract, cls).confirm(contracts)
ContractLine = Pool().get('contract.line')
lines = []
for contract in contracts:
@ -118,6 +120,7 @@ class Contract:
class ContractLine:
__name__ = 'contract.line'
__metaclass__ = PoolMeta
project = fields.Many2One('work.project', 'Project', select=True,
domain=[
@ -138,7 +141,7 @@ class ContractLine:
if self.project or not self.asset:
return
if not self.asset.owner:
if not self.asset.current_owner:
self.raise_user_error('no_asset_owner', self.asset.rec_name)
project = Project.search([
@ -152,7 +155,7 @@ class ContractLine:
project = Project()
project.company = self.contract.company
project.party = self.asset.owner
project.party = self.asset.current_owner
project.asset = self.asset
project.maintenance = True
project.start_date = self.contract.start_date

View File

@ -17,7 +17,8 @@ copyright notices and license terms. -->
<record model="ir.action.act_window" id="act_project_work_form">
<field name="name">Projects</field>
<field name="res_model">work.project</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_open_projects_keyword1">
<field name="keyword">form_relate</field>