Set CompAux in starting balance of FEC

issue6949
review36101002
This commit is contained in:
Cédric Krier committed 2018-04-09 10:38:24 +02:00
1 parent e415c3d9f4
commit abfe3cf255
5 files changed
+92 -20

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Set CompAux in starting balance of FEC
* Update chart to new tax code definition
* Allow to export FEC on draft fiscalyear
+49 -15
View File
@@ -5,6 +5,8 @@ import sys
from io import BytesIO, StringIO
from sql import Table
from sql.aggregate import Sum
from sql.conditionals import Coalesce
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
@@ -185,33 +187,65 @@ class AccountFrFEC(Wizard):
def get_start_balance(self):
pool = Pool()
Account = pool.get('account.account')
Move = pool.get('account.move')
Line = pool.get('account.move.line')
FiscalYear = pool.get('account.fiscalyear')
Period = pool.get('account.period')
Party = pool.get('party.party')
account = Account.__table__()
move = Move.__table__()
line = Line.__table__()
period = Period.__table__()
party = Party.__table__()
cursor = Transaction().connection.cursor()
format_date = self.get_format_date()
format_number = self.get_format_number()
with Transaction().set_context(
periods=[-1],
fiscalyear=self.start.fiscalyear.id,
posted=True,
cumulate=True):
accounts = Account.search([])
company = self.start.fiscalyear.company
fiscalyears = FiscalYear.search([
('end_date', '<', self.start.fiscalyear.start_date),
('company', '=', company.id),
])
fiscalyear_ids = map(int, fiscalyears)
for account in accounts:
if account.credit == account.debit:
query = (account
.join(line, condition=line.account == account.id)
.join(move, condition=line.move == move.id)
.join(period, condition=move.period == period.id)
.join(party, 'LEFT', condition=line.party == party.id)
.select(
account.id,
account.code,
account.name,
party.code,
party.name,
Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
where=(account.company == company.id)
& (move.state == 'posted')
& (line.state != 'draft')
& period.fiscalyear.in_(fiscalyear_ids),
group_by=[
account.id, account.code, account.name,
party.code, party.name]))
cursor.execute(*query)
for row in cursor:
_, code, name, party_code, party_name, balance = row
if not balance:
continue
if account.debit > account.credit:
debit, credit = account.debit - account.credit, 0
if balance > 0:
debit, credit = balance, 0
else:
debit, credit = 0, account.debit - account.credit
debit, credit = 0, balance
yield [
self.start.deferral_journal.code
or self.start.deferral_journal.name,
self.start.deferral_journal.name,
self.start.deferral_post_number,
format_date(self.start.fiscalyear.start_date),
account.code,
account.name,
'',
'',
code,
name,
party_code or '',
party_name or '',
'-',
format_date(self.start.fiscalyear.start_date),
'-',
+3 -2
View File
@@ -53,7 +53,7 @@ for dep in info.get('depends', []):
requires.append(get_require_version('trytond_%s' % dep))
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('proteus')]
tests_require = [get_require_version('proteus'), 'python-dateutil']
dependency_links = []
if minor_version % 2:
dependency_links.append('https://trydevpi.tryton.org/')
@@ -74,7 +74,8 @@ setup(name=name,
],
package_data={
'trytond.modules.account_fr': (info.get('xml', [])
+ ['tryton.cfg', 'view/*.xml', 'locale/*.po', 'tests/*.rst']),
+ ['tryton.cfg', 'view/*.xml', 'locale/*.po', 'tests/*.rst',
'tests/FEC.csv']),
},
classifiers=[
'Development Status :: 5 - Production/Stable',
+5
View File
@@ -0,0 +1,5 @@
JournalCode JournalLib EcritureNum EcritureDate CompteNum CompteLib CompAuxNum CompAuxLib PieceRef PieceDate EcritureLib Debit Credit EcritureLet DateLet ValidDate Montantdevise Idevise
Deferral Deferral 0 20180101 797 Transferts de charges exceptionnelles - 20180101 - 0,00 -5,00 20180101
Deferral Deferral 0 20180101 4967 Autres comptes débiteurs 2 Party - 20180101 - 5,00 0,00 20180101
REV Revenue 1 20180101 797 Transferts de charges exceptionnelles - 20180101 - 0,00 10,00 20180101
REV Revenue 1 20180101 4967 Autres comptes débiteurs 2 Party - 20180101 - 10,00 0,00 20180101
1 JournalCode JournalLib EcritureNum EcritureDate CompteNum CompteLib CompAuxNum CompAuxLib PieceRef PieceDate EcritureLib Debit Credit EcritureLet DateLet ValidDate Montantdevise Idevise
2 Deferral Deferral 0 20180101 797 Transferts de charges exceptionnelles - 20180101 - 0,00 -5,00 20180101
3 Deferral Deferral 0 20180101 4967 Autres comptes débiteurs 2 Party - 20180101 - 5,00 0,00 20180101
4 REV Revenue 1 20180101 797 Transferts de charges exceptionnelles - 20180101 - 0,00 10,00 20180101
5 REV Revenue 1 20180101 4967 Autres comptes débiteurs 2 Party - 20180101 - 10,00 0,00 20180101
+34 -3
View File
@@ -5,7 +5,10 @@ FEC Scenario
Imports::
>>> import datetime
>>> import os
>>> import io
>>> from decimal import Decimal
>>> from dateutil.relativedelta import relativedelta
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
@@ -14,6 +17,8 @@ Imports::
>>> from trytond.modules.account_fr.tests.tools import create_chart, \
... get_accounts
>>> today = datetime.date(2018, 1, 1)
Install account_fr::
>>> config = activate_modules('account_fr')
@@ -25,9 +30,16 @@ Create company::
>>> company.party.siren = '820043784'
>>> company.party.save()
Create last year fiscal year::
>>> fiscalyear_previous = create_fiscalyear(
... company, today=today - relativedelta(years=1))
>>> fiscalyear_previous.click('create_period')
>>> period_previous = fiscalyear_previous.periods[0]
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear = create_fiscalyear(company, today=today)
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
@@ -46,7 +58,7 @@ Create parties::
>>> party = Party(name='Party')
>>> party.save()
Create a moves::
Create some moves::
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
@@ -56,6 +68,22 @@ Create a moves::
>>> journal_cash, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> move = Move()
>>> move.period = period_previous
>>> move.journal = journal_revenue
>>> move.date = period_previous.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(5)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(5)
>>> line.party = party
>>> move.post_date = period_previous.start_date
>>> move.post_number = '1'
>>> move.click('post')
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
@@ -67,6 +95,8 @@ Create a moves::
>>> line.account = receivable
>>> line.debit = Decimal(10)
>>> line.party = party
>>> move.post_date = period.start_date
>>> move.post_number = '1'
>>> move.click('post')
Generate FEC::
@@ -80,5 +110,6 @@ Generate FEC::
>>> FEC.form.deferral_journal = deferral_journal
>>> FEC.execute('generate')
>>> FEC.form.filename
>>> bool(FEC.form.file)
>>> file = os.path.join(os.path.dirname(__file__), 'FEC.csv')
>>> FEC.form.file.decode('utf-8') == io.open(file, mode='rb').read().decode('utf-8')
True