changeset 4a26449fbf23 in modules/account_es:default
details: 
https://hg.tryton.org/modules/account_es?cmd=changeset;node=4a26449fbf23
description:
        Add amount to compensate from previous periods in 303 report

        issue7837
        review68351002
diffstat:

 CHANGELOG                               |    1 +
 reporting_tax.py                        |   21 ++++-
 tests/303_compensate.txt                |    1 +
 tests/scenario_reporting_compensate.rst |  154 ++++++++++++++++++++++++++++++++
 tests/test_account_es.py                |    4 +
 5 files changed, 180 insertions(+), 1 deletions(-)

diffs (227 lines):

diff -r 2bf5c75d0833 -r 4a26449fbf23 CHANGELOG
--- a/CHANGELOG Thu Mar 28 12:07:16 2019 +0100
+++ b/CHANGELOG Sat Mar 30 10:13:51 2019 +0100
@@ -1,3 +1,4 @@
+* Add amount to compensate from previous periods in 303 report
 * Update model 303 to new format
 
 Version 5.0.0 - 2018-10-01
diff -r 2bf5c75d0833 -r 4a26449fbf23 reporting_tax.py
--- a/reporting_tax.py  Thu Mar 28 12:07:16 2019 +0100
+++ b/reporting_tax.py  Sat Mar 30 10:13:51 2019 +0100
@@ -234,7 +234,9 @@
     def get_context(cls, records, data):
         pool = Pool()
         Period = pool.get('account.period')
+        Account = pool.get('account.account')
         TaxCodeLine = pool.get('account.tax.code.line')
+        transaction = Transaction()
         context = super().get_context(records, data)
         amounts = context['amounts']
 
@@ -261,12 +263,29 @@
             code = str(int(line.code.code) - 1).rjust(2, '0')
             amounts[code] = float(line.tax.rate * Decimal(100))
 
-        for code in ['46', '64', '66', '69', '71', '88']:
+        amount_to_compensate = Decimal(0)
+        fiscalyear = periods[0].fiscalyear
+        start_periods = Period.search([
+                ('fiscalyear', '=', fiscalyear.id),
+                ('end_date', '<=', start_date),
+                ])
+        with transaction.set_context({
+                    'fiscalyear': fiscalyear.id,
+                    'periods': [p.id for p in start_periods],
+                    }):
+            for account in Account.search([
+                        ('company', '=', fiscalyear.company.id),
+                        ('code', 'like', '4700%'),
+                        ]):
+                amount_to_compensate += account.balance
+
+        for code in ['46', '64', '66', '67', '69', '71', '88']:
             assert code not in amounts, (
                 "computed code %s already defined" % code)
         amounts['46'] = amounts['27'] - amounts['45']
         amounts['64'] = amounts['46'] + amounts['58'] + amounts['76']
         amounts['66'] = amounts['64'] * Decimal(amounts['65']) / Decimal(100.0)
+        amounts['67'] = amount_to_compensate
         amounts['69'] = (amounts['66'] + amounts['77'] - amounts['67']
             + amounts['68'])
         amounts['71'] = (amounts['69'] - amounts['70'])
diff -r 2bf5c75d0833 -r 4a26449fbf23 tests/303_compensate.txt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/303_compensate.txt  Sat Mar 30 10:13:51 2019 +0100
@@ -0,0 +1,1 @@
+<T30302018020000><AUX>                                                         
                                                                                
                                                                                
                                                                                
   </AUX><T30301000> CB01000009DUNDER MIFFLIN                                   
                               2018022322         
2222000000000000000000040000000000000000000000000000000000000100000000000000000000000000000000050000210000000000000001050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000001050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010500220
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                               
</T30301000><T30303000>00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000105010000000000000000000001050000000000000000000000000000000400000000000000000000N000000000000295000000000000000000N0000000000002950
                                                            0    0    0    0    
0    0     
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                               
</T30303000></T30302018020000>
diff -r 2bf5c75d0833 -r 4a26449fbf23 tests/scenario_reporting_compensate.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_reporting_compensate.rst   Sat Mar 30 10:13:51 2019 +0100
@@ -0,0 +1,154 @@
+=========================================
+Account ES Compensated Reporting Scenario
+=========================================
+
+Imports::
+
+    >>> import datetime
+    >>> from decimal import Decimal
+    >>> from proteus import Model, Wizard
+    >>> from trytond.tests.tools import activate_modules
+    >>> from trytond.tools import file_open
+    >>> from trytond.modules.company.tests.tools import create_company, \
+    ...     get_company
+    >>> from trytond.modules.account.tests.tools import create_fiscalyear
+    >>> from trytond.modules.account_invoice.tests.tools import \
+    ...     set_fiscalyear_invoice_sequences
+    >>> today = datetime.date.today()
+
+Install account_es::
+
+    >>> config = activate_modules(['account_es', 'account_invoice'])
+
+Create company::
+
+    >>> _ = create_company()
+    >>> company = get_company()
+    >>> tax_identifier = company.party.identifiers.new()
+    >>> tax_identifier.type = 'eu_vat'
+    >>> tax_identifier.code = 'ESB01000009'
+    >>> company.party.save()
+
+Create fiscal year::
+
+    >>> fiscalyear = set_fiscalyear_invoice_sequences(
+    ...     create_fiscalyear(company, datetime.date(2018, 1, 1)))
+    >>> fiscalyear.click('create_period')
+    >>> previous_period = fiscalyear.periods[0]
+    >>> period = fiscalyear.periods[1]
+
+Create chart of accounts::
+
+    >>> AccountTemplate = Model.get('account.account.template')
+    >>> Account = Model.get('account.account')
+    >>> ModelData = Model.get('ir.model.data')
+    >>> data, = ModelData.find([
+    ...        ('module', '=', 'account_es'),
+    ...        ('fs_id', '=', 'pgc_0_pyme'),
+    ...        ], limit=1)
+    >>> account_template = AccountTemplate(data.db_id)
+    >>> 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')
+    >>> accounts = {}
+    >>> for kind in ['receivable', 'payable', 'revenue', 'expense']:
+    ...     accounts[kind], = Account.find([
+    ...        ('type.%s' % kind , '=', True),
+    ...        ('company', '=', company.id),
+    ...        ], limit=1)
+    >>> expense = accounts['expense']
+    >>> revenue = accounts['revenue']
+    >>> create_chart.form.account_receivable = accounts['receivable']
+    >>> create_chart.form.account_payable = accounts['payable']
+    >>> create_chart.execute('create_properties')
+
+Create parties::
+
+    >>> Party = Model.get('party.party')
+    >>> party = Party(name='Party')
+    >>> party.save()
+
+Create account category::
+
+    >>> Tax = Model.get('account.tax')
+    >>> customer_tax, = Tax.find([
+    ...     ('company', '=', company.id),
+    ...     ('name', '=', 'IVA 21%'),
+    ...     ])
+    >>> 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.customer_taxes.append(customer_tax)
+    >>> 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 invoice::
+
+    >>> Invoice = Model.get('account.invoice')
+    >>> invoice = Invoice()
+    >>> invoice.party = party
+    >>> invoice.invoice_date = period.start_date
+    >>> line = invoice.lines.new()
+    >>> line.product = product
+    >>> line.quantity = 1
+    >>> line.unit_price = Decimal('50')
+    >>> invoice.click('post')
+    >>> invoice.total_amount
+    Decimal('60.50')
+
+Create previous period compensation move::
+
+    >>> Journal = Model.get('account.journal')
+    >>> Move = Model.get('account.move')
+    >>> journal_cash, = Journal.find([
+    ...         ('code', '=', 'CASH'),
+    ...         ])
+    >>> compensation_account, = Account.find([
+    ...         ('company', '=', company.id),
+    ...         ('code', '=', '4700'),
+    ...         ])
+    >>> move = Move()
+    >>> move.period = previous_period
+    >>> move.journal = journal_cash
+    >>> move.date = previous_period.start_date
+    >>> line = move.lines.new()
+    >>> line.account = expense
+    >>> line.credit = Decimal(40)
+    >>> line = move.lines.new()
+    >>> line.account = compensation_account
+    >>> line.debit = Decimal(40)
+    >>> move.click('post')
+
+
+Generate aeat 303 report::
+
+    >>> Period = Model.get('account.period')
+    >>> aeat = Wizard('account.reporting.aeat')
+    >>> aeat.form.report = '303'
+    >>> aeat.form.periods.append(Period(period.id))
+    >>> aeat.execute('choice')
+    >>> extension, content, _, name = aeat.actions[0]
+    >>> extension
+    'txt'
+    >>> with file_open('account_es/tests/303_compensate.txt') as f:
+    ...     content == f.read()
+    True
+    >>> name
+    'AEAT Model 303'
diff -r 2bf5c75d0833 -r 4a26449fbf23 tests/test_account_es.py
--- a/tests/test_account_es.py  Thu Mar 28 12:07:16 2019 +0100
+++ b/tests/test_account_es.py  Sat Mar 30 10:13:51 2019 +0100
@@ -22,4 +22,8 @@
             tearDown=doctest_teardown, encoding='utf-8',
             checker=doctest_checker,
             optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+    suite.addTests(doctest.DocFileSuite('scenario_reporting_compensate.rst',
+            tearDown=doctest_teardown, encoding='utf-8',
+            checker=doctest_checker,
+            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
     return suite

Reply via email to