@@ -1,3 +1,4 @@
|
||||
* Fill analytic lines when defer invoice
|
||||
|
||||
Version 6.8.0 - 2023-05-01
|
||||
--------------------------
|
||||
|
||||
@@ -15,6 +15,10 @@ def register():
|
||||
asset.Asset,
|
||||
module='analytic_invoice', type_='model',
|
||||
depends=['account_asset'])
|
||||
Pool.register(
|
||||
invoice.InvoiceDeferred,
|
||||
module='analytic_invoice', type_='model',
|
||||
depends=['account_invoice_defer'])
|
||||
Pool.register(
|
||||
asset.UpdateAsset,
|
||||
module='analytic_invoice', type_='wizard',
|
||||
|
||||
@@ -53,6 +53,23 @@ class InvoiceLine(AnalyticMixin, metaclass=PoolMeta):
|
||||
return lines
|
||||
|
||||
|
||||
class InvoiceDeferred(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice.deferred'
|
||||
|
||||
def get_move(self, period=None):
|
||||
move = super().get_move(period=period)
|
||||
if self.invoice_line.analytic_accounts:
|
||||
for line in move.lines:
|
||||
if line.account.type.statement != 'income':
|
||||
continue
|
||||
analytic_lines = []
|
||||
for entry in self.invoice_line.analytic_accounts:
|
||||
analytic_lines.extend(
|
||||
entry.get_analytic_lines(line, move.date))
|
||||
line.analytic_lines = analytic_lines
|
||||
return move
|
||||
|
||||
|
||||
class AnalyticAccountEntry(metaclass=PoolMeta):
|
||||
__name__ = 'analytic.account.entry'
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ for dep in info.get('depends', []):
|
||||
requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [get_require_version('proteus')]
|
||||
for dep in ['account_asset']:
|
||||
for dep in ['account_asset', 'account_invoice_defer']:
|
||||
tests_require.append(get_require_version('trytond_%s' % dep))
|
||||
|
||||
setup(name=name,
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
===============================
|
||||
Analytic Invoice Defer Scenario
|
||||
===============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
>>> from trytond.modules.company.tests.tools import (
|
||||
... create_company, get_company)
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_fiscalyear, create_chart, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.account_invoice_defer.tests.tools import (
|
||||
... add_deferred_accounts)
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(['analytic_invoice', 'account_invoice_defer'])
|
||||
|
||||
>>> 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 company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(company, today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = add_deferred_accounts(get_accounts(company))
|
||||
|
||||
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([])
|
||||
>>> deferral.invoice_line == invoice_line
|
||||
True
|
||||
>>> deferral.amount
|
||||
Decimal('1000.00')
|
||||
>>> deferral.start_date == invoice_line.defer_from
|
||||
True
|
||||
>>> deferral.end_date == invoice_line.defer_to
|
||||
True
|
||||
>>> 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')
|
||||
@@ -7,7 +7,7 @@ from trytond.tests.test_tryton import ModuleTestCase
|
||||
class AnalyticInvoiceTestCase(ModuleTestCase):
|
||||
'Test AnalyticInvoice module'
|
||||
module = 'analytic_invoice'
|
||||
extras = ['account_asset']
|
||||
extras = ['account_asset', 'account_invoice_defer']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
@@ -5,6 +5,7 @@ depends:
|
||||
analytic_account
|
||||
extras_depend:
|
||||
account_asset
|
||||
account_invoice_defer
|
||||
xml:
|
||||
invoice.xml
|
||||
asset.xml
|
||||
|
||||
Reference in New Issue
Block a user