209 lines
6.6 KiB
ReStructuredText
209 lines
6.6 KiB
ReStructuredText
===================================
|
|
Account Es Reagyp AEAT SII Scenario
|
|
===================================
|
|
|
|
Imports::
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import config, 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, create_tax, create_tax_code
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences
|
|
>>> today = datetime.date.today()
|
|
|
|
Install modules::
|
|
|
|
>>> config = activate_modules(['aeat_sii'])
|
|
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
|
... create_fiscalyear(company))
|
|
>>> fiscalyear.click('create_period')
|
|
>>> Period = Model.get('account.period')
|
|
>>> period, = Period.find([
|
|
... ('start_date', '>=', today.replace(day=1)),
|
|
... ('end_date', '<=', today.replace(day=1) + relativedelta(months=+1)),
|
|
... ], limit=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_normal'),
|
|
... ], 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 party::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> party = Party(name='Party')
|
|
>>> party.save()
|
|
|
|
>>> TaxRule = Model.get('account.tax.rule')
|
|
>>> tax_rule, = TaxRule.find([
|
|
... ('company', '=', company.id),
|
|
... ('kind', '=', 'purchase'),
|
|
... ('name', 'ilike', '%especial agr%'),
|
|
... ])
|
|
>>> party_reagyp = Party(name='Party REAGYP')
|
|
>>> party_reagyp.supplier_tax_rule = tax_rule
|
|
>>> party_reagyp.save()
|
|
|
|
|
|
Create account category::
|
|
|
|
>>> Tax = Model.get('account.tax')
|
|
>>> customer_tax, = Tax.find([
|
|
... ('company', '=', company.id),
|
|
... ('description', 'like', '%IVA 21%'),
|
|
... ('group.kind', '=', 'sale'),
|
|
... ], limit=1)
|
|
>>> supplier_tax, = Tax.find([
|
|
... ('company', '=', company.id),
|
|
... ('description', 'like', '%IVA 21%'),
|
|
... ('group.kind', '=', 'purchase'),
|
|
... ], limit=1)
|
|
>>> 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.supplier_taxes.append(supplier_tax)
|
|
>>> account_category.save()
|
|
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> product = Product()
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'service'
|
|
>>> template.list_price = Decimal('40')
|
|
>>> template.cost_price = Decimal('25')
|
|
>>> template.account_category = account_category
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
|
|
|
|
Create invoices::
|
|
|
|
>>> Invoice = Model.get('account.invoice')
|
|
>>> invoice = Invoice(type='in')
|
|
>>> invoice.party = party
|
|
>>> invoice.invoice_date = period.start_date
|
|
>>> invoice.accounting_date = period.start_date
|
|
>>> line = invoice.lines.new()
|
|
>>> line.product = product
|
|
>>> line.quantity = 5
|
|
>>> line.unit_price = Decimal('40')
|
|
>>> invoice.sii_book_key = 'R'
|
|
>>> invoice.save()
|
|
>>> invoice.click('post')
|
|
>>> invoice.state
|
|
'posted'
|
|
>>> bool(invoice.is_reagyp)
|
|
False
|
|
|
|
>>> invoice2 = Invoice(type='in')
|
|
>>> invoice2.party = party_reagyp
|
|
>>> invoice2.invoice_date = period.start_date
|
|
>>> invoice2.accounting_date = period.start_date
|
|
>>> line = invoice2.lines.new()
|
|
>>> line.product = product
|
|
>>> line.quantity = 5
|
|
>>> line.unit_price = Decimal('40')
|
|
>>> invoice2.sii_book_key = 'R'
|
|
>>> invoice2.save()
|
|
>>> invoice2.click('post')
|
|
>>> invoice2.state
|
|
'posted'
|
|
>>> bool(invoice2.is_reagyp)
|
|
True
|
|
|
|
Check invoices references::
|
|
|
|
>>> invoice.click('post')
|
|
>>> invoice.reference == invoice.number
|
|
False
|
|
>>> invoice2.click('post')
|
|
>>> invoice2.reference == invoice2.number
|
|
True
|
|
|
|
Create AEAT Report::
|
|
|
|
>>> AEATReport = Model.get('aeat.sii.report')
|
|
>>> Conf = Model.get('account.configuration')
|
|
>>> conf = Conf(1)
|
|
>>> report = AEATReport()
|
|
>>> report.fiscalyear = fiscalyear
|
|
>>> report.period = period
|
|
>>> report.operation_type = 'A0'
|
|
>>> report.book = 'R'
|
|
>>> report.company_vat = '123456789'
|
|
>>> report.save()
|
|
>>> report.state
|
|
'draft'
|
|
>>> report.click('load_invoices')
|
|
>>> len(report.lines)
|
|
2
|
|
>>> line1, line2 = report.lines
|
|
>>> report.lines.remove(line1)
|
|
>>> report.lines.remove(line2)
|
|
>>> report.save()
|
|
>>> conf.sii_reagyp_invoice_paid = True
|
|
>>> conf.save()
|
|
>>> report.click('load_invoices')
|
|
>>> len(report.lines)
|
|
1
|
|
>>> line = report.lines.new()
|
|
>>> line.invoice = invoice2
|
|
>>> report.save()
|
|
>>> report.reload()
|
|
>>> len(report.lines)
|
|
2
|
|
>>> report.click('confirm')
|
|
Traceback (most recent call last):
|
|
...
|
|
trytond.exceptions.UserWarning: There are unpaid invoices with REAGYP taxes in SII Book to confirm:
|
|
2 [2]. - |