first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,125 @@
=========================
Analytic Invoice Scenario
=========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.account_invoice.tests.tools import (
... create_payment_term, set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('analytic_invoice', create_company, create_chart)
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
Create analytic accounts::
>>> AnalyticAccount = Model.get('analytic_account.account')
>>> root = AnalyticAccount(type='root', name='Root')
>>> root.save()
>>> analytic_account = AnalyticAccount(root=root, parent=root,
... name='Analytic')
>>> analytic_account.save()
Create party::
>>> Party = Model.get('party.party')
>>> party = Party(name='Party')
>>> party.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = expense
>>> account_category.account_revenue = revenue
>>> account_category.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::
>>> payment_term = create_payment_term()
>>> payment_term.save()
Create invoice with analytic accounts::
>>> Invoice = Model.get('account.invoice')
>>> invoice = Invoice()
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> line = invoice.lines.new()
>>> entry, = line.analytic_accounts
>>> assertEqual(entry.root, root)
>>> entry.account = analytic_account
>>> line.product = product
>>> line.quantity = 5
>>> line.unit_price = Decimal('40')
>>> invoice.click('post')
>>> invoice.state
'posted'
>>> analytic_account.reload()
>>> analytic_account.credit
Decimal('200.00')
>>> analytic_account.debit
Decimal('0.00')
Create invoice with an empty analytic account::
>>> invoice = Invoice()
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> line = invoice.lines.new()
>>> entry, = line.analytic_accounts
>>> line.product = product
>>> line.quantity = 1
>>> line.unit_price = Decimal('40')
>>> invoice.click('post')
>>> invoice.state
'posted'
>>> analytic_account.reload()
>>> analytic_account.credit
Decimal('200.00')
>>> analytic_account.debit
Decimal('0.00')
Credit invoice with refund::
>>> credit = Wizard('account.invoice.credit', [invoice])
>>> credit.form.with_refund = True
>>> credit.execute('credit')
>>> invoice.reload()
>>> invoice.state
'cancelled'

View File

@@ -0,0 +1,150 @@
=====================================
Analytic Invoice with Assets Scenario
=====================================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from dateutil.relativedelta import relativedelta
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.account_asset.tests.tools import add_asset_accounts
>>> from trytond.modules.account_invoice.tests.tools import (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
>>> next_month = today + relativedelta(day=1, month=1)
>>> next_next_month = next_month + relativedelta(months=1)
Activate modules::
>>> config = activate_modules(
... ['analytic_invoice', 'account_asset'],
... create_company, create_chart)
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear(today=(today, next_next_month)))
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = add_asset_accounts(get_accounts())
>>> revenue = accounts['revenue']
>>> asset_account = accounts['asset']
>>> expense = accounts['expense']
>>> depreciation_account = accounts['depreciation']
Create analytic accounts::
>>> AnalyticAccount = Model.get('analytic_account.account')
>>> root = AnalyticAccount(type='root', name='Root')
>>> root.save()
>>> analytic_account = AnalyticAccount(root=root, parent=root,
... name='Analytic')
>>> analytic_account.save()
Create supplier::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = expense
>>> account_category.account_revenue = revenue
>>> account_category.account_asset = asset_account
>>> account_category.account_depreciation = depreciation_account
>>> account_category.save()
Create an asset::
>>> ProductUom = Model.get('product.uom')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> ProductTemplate = Model.get('product.template')
>>> asset_template = ProductTemplate()
>>> asset_template.name = 'Asset'
>>> asset_template.type = 'assets'
>>> asset_template.default_uom = unit
>>> asset_template.list_price = Decimal('1000')
>>> asset_template.account_category = account_category
>>> asset_template.depreciable = True
>>> asset_template.depreciation_duration = 10
>>> asset_template.save()
>>> asset_product, = asset_template.products
Buy an asset::
>>> Invoice = Model.get('account.invoice')
>>> InvoiceLine = Model.get('account.invoice.line')
>>> supplier_invoice = Invoice(type='in')
>>> supplier_invoice.party = supplier
>>> invoice_line = supplier_invoice.lines.new()
>>> invoice_line.product = asset_product
>>> invoice_line.quantity = 1
>>> invoice_line.unit_price = Decimal('1000')
>>> entry, = invoice_line.analytic_accounts
>>> entry.account = analytic_account
>>> supplier_invoice.invoice_date = next_month
>>> supplier_invoice.click('post')
>>> supplier_invoice.state
'posted'
>>> invoice_line, = supplier_invoice.lines
>>> analytic_account.debit
Decimal('0.00')
>>> analytic_account.credit
Decimal('0.00')
Depreciate the asset::
>>> Asset = Model.get('account.asset')
>>> asset = Asset()
>>> asset.product = asset_product
>>> asset.supplier_invoice_line = invoice_line
>>> asset.residual_value = Decimal(0)
>>> asset.click('create_lines')
>>> asset.click('run')
Create Moves for 1 month::
>>> create_moves = Wizard('account.asset.create_moves')
>>> create_moves.form.date = next_next_month
>>> create_moves.execute('create_moves')
>>> analytic_account.reload()
>>> analytic_account.debit
Decimal('100.00')
>>> analytic_account.credit
Decimal('0.00')
Update the asset::
>>> update = Wizard('account.asset.update', [asset])
>>> update.form.value = Decimal('950.00')
>>> update.execute('update_asset')
>>> update.form.date = update.form.next_depreciation_date
>>> update.execute('create_move')
>>> analytic_account.reload()
>>> analytic_account.debit
Decimal('150.00')
>>> analytic_account.credit
Decimal('0.00')
Close the asset::
>>> asset.click('close')
>>> analytic_account.reload()
>>> analytic_account.debit
Decimal('1000.00')
>>> analytic_account.credit
Decimal('0.00')

View File

@@ -0,0 +1,120 @@
===============================
Analytic Invoice Defer Scenario
===============================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.account_invoice.tests.tools import (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.account_invoice_defer.tests.tools import (
... add_deferred_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules(
... ['analytic_invoice', 'account_invoice_defer'],
... create_company, create_chart)
>>> AnalyticAccount = Model.get('analytic_account.account')
>>> Invoice = Model.get('account.invoice')
>>> InvoiceDeferred = Model.get('account.invoice.deferred')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductUom = Model.get('product.uom')
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear(today=today))
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = add_deferred_accounts(get_accounts())
Create analytic accounts::
>>> root = AnalyticAccount(type='root', name='Root')
>>> root.save()
>>> analytic_account = AnalyticAccount(
... root=root, parent=root, name="Analytic")
>>> analytic_account.save()
Create party::
>>> party = Party(name="Insurer")
>>> party.save()
Create account category::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = accounts['expense']
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.save()
Create product::
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> ProductTemplate = Model.get('product.template')
>>> template = ProductTemplate()
>>> template.name = "Insurance"
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.list_price = Decimal('1000')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create invoice::
>>> invoice = Invoice(type='in')
>>> invoice.party = party
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> line.unit_price = Decimal('1000')
>>> line.defer_from = period.start_date
>>> line.defer_to = line.defer_from + dt.timedelta(days=499)
>>> entry, = line.analytic_accounts
>>> entry.account = analytic_account
>>> invoice.invoice_date = today
>>> invoice.click('post')
>>> invoice.state
'posted'
>>> invoice_line, = invoice.lines
>>> analytic_account.reload()
>>> analytic_account.debit, analytic_account.credit
(Decimal('1000.00'), Decimal('0.00'))
Check invoice deferred and run it::
>>> deferral, = InvoiceDeferred.find([])
>>> assertEqual(deferral.invoice_line, invoice_line)
>>> deferral.amount
Decimal('1000.00')
>>> assertEqual(deferral.start_date, invoice_line.defer_from)
>>> assertEqual(deferral.end_date, invoice_line.defer_to)
>>> deferral.click('run')
>>> deferral.state
'running'
>>> len(deferral.moves)
13
>>> analytic_account.reload()
>>> analytic_account.debit in {Decimal('1730'), Decimal('1732')}
True
>>> analytic_account.credit
Decimal('1000.00')

View File

@@ -0,0 +1,13 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import ModuleTestCase
class AnalyticInvoiceTestCase(ModuleTestCase):
'Test AnalyticInvoice module'
module = 'analytic_invoice'
extras = ['account_asset', 'account_invoice_defer']
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)