Skip to content

Commit

Permalink
[IMP] adapt to new libro iva digital
Browse files Browse the repository at this point in the history
  • Loading branch information
jjscarafia committed Dec 21, 2020
1 parent 6ccca1f commit 32ad108
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion l10n_ar_account_vat_ledger_citi/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Argentinian CITI Reports",
'version': '11.0.1.7.0',
'version': '11.0.1.8.0',
'category': 'Localization/Argentina',
'sequence': 14,
'author': 'ADHOC SA,Moldeo Interactive,Odoo Community Association (OCA)',
Expand Down
57 changes: 46 additions & 11 deletions l10n_ar_account_vat_ledger_citi/models/account_vat_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class AccountVatLedger(models.Model):
_inherit = "account.vat.ledger"

txt_type = fields.Selection([('citi', 'Citi'), ('iva_digital', 'IVA Digital')], required=True, default='citi')
citi_skip_invoice_tests = fields.Boolean(
string='Skip invoice tests?',
help='If you skip invoice tests probably you will have errors when '
Expand All @@ -37,6 +38,10 @@ class AccountVatLedger(models.Model):
'REGINFO_CV_CBTE',
readonly=True,
)
REGINFO_CV_CBTE_IMPORTACIONES = fields.Text(
'REGINFO_CV_CBTE_IMPORTACIONES',
readonly=True,
)
REGINFO_CV_CABECERA = fields.Text(
'REGINFO_CV_CABECERA',
readonly=True,
Expand All @@ -51,6 +56,16 @@ class AccountVatLedger(models.Model):
readonly=True,
compute='_compute_files',
)
impo_vouchers_file = fields.Binary(
_('Import Vouchers File'),
compute='_compute_files',
readonly=True
)
impo_vouchers_filename = fields.Char(
_('Import Vouchers Filename'),
readonly=True,
compute='_compute_files',
)
aliquots_file = fields.Binary(
_('Aliquots File'),
compute='_compute_files',
Expand Down Expand Up @@ -119,6 +134,7 @@ def format_amount(self, amount, padding=15, decimals=2, invoice=False):
@api.multi
@api.depends(
'REGINFO_CV_CBTE',
'REGINFO_CV_CBTE_IMPORTACIONES',
'REGINFO_CV_ALICUOTAS',
'type',
# 'period_id.name'
Expand Down Expand Up @@ -152,6 +168,14 @@ def _compute_files(self):
)
self.vouchers_file = base64.encodestring(
self.REGINFO_CV_CBTE.encode('ISO-8859-1'))
if self.REGINFO_CV_CBTE_IMPORTACIONES:
self.impo_vouchers_filename = _('Import Vouchers_%s_%s.txt') % (
self.type,
self.date_to,
# self.period_id.name
)
self.impo_vouchers_file = base64.encodestring(
self.REGINFO_CV_CBTE_IMPORTACIONES.encode('ISO-8859-1'))

@api.multi
def compute_citi_data(self):
Expand All @@ -171,7 +195,11 @@ def compute_citi_data(self):
lines += v
self.REGINFO_CV_COMPRAS_IMPORTACIONES = '\r\n'.join(lines)
alicuotas.update(impo_alicuotas)
self.get_REGINFO_CV_CBTE(alicuotas)
if self.txt_type == 'citi':
self.get_REGINFO_CV_CBTE(alicuotas)
else:
self.get_REGINFO_CV_CBTE(alicuotas, invoice_type='impo')
self.get_REGINFO_CV_CBTE(alicuotas, invoice_type='not_impo')

@api.model
def get_partner_document_code(self, partner):
Expand Down Expand Up @@ -217,11 +245,18 @@ def _check_citi_skip_lines(self):
repr(e)))

@api.multi
def get_citi_invoices(self, return_skiped=False):
def get_citi_invoices(self, return_skiped=False, invoice_type='all'):
self.ensure_one()
invoices = self.env['account.invoice'].search([
domain = [
('document_type_id.export_to_citi', '=', True),
('id', 'in', self.invoice_ids.ids)], order='date_invoice asc')
('id', 'in', self.invoice_ids.ids)]

if invoice_type == 'impo':
domain.append(('document_type_id.code', '=', '66'))
elif invoice_type == 'not_impo':
domain.append(('document_type_id.code', '!=', '66'))

invoices = self.env['account.invoice'].search(domain, order='date_invoice asc')
if self.citi_skip_lines:
skip_lines = literal_eval(self.citi_skip_lines)
if isinstance(skip_lines, int):
Expand All @@ -235,10 +270,10 @@ def get_citi_invoices(self, return_skiped=False):
return invoices

@api.multi
def get_REGINFO_CV_CBTE(self, alicuotas):
def get_REGINFO_CV_CBTE(self, alicuotas, invoice_type='all'):
self.ensure_one()
res = []
invoices = self.get_citi_invoices()
invoices = self.get_citi_invoices(invoice_type=invoice_type)
if not self.citi_skip_invoice_tests:
invoices.check_argentinian_invoice_taxes()
if self.type == 'purchase':
Expand Down Expand Up @@ -483,7 +518,10 @@ def get_REGINFO_CV_CBTE(self, alicuotas):
self.format_amount(0, invoice=inv),
]
res.append(''.join(row))
self.REGINFO_CV_CBTE = '\r\n'.join(res)
if invoice_type == 'impo':
self.REGINFO_CV_CBTE_IMPORTACIONES = '\r\n'.join(res)
else:
self.REGINFO_CV_CBTE = '\r\n'.join(res)

@api.multi
def get_tax_row(self, invoice, base, code, tax_amount, impo=False):
Expand Down Expand Up @@ -568,10 +606,7 @@ def get_REGINFO_CV_ALICUOTAS(self, impo=False):
# si no hay alicuotas, sumamos una de esta con 0, 0, 0 en detalle
# usamos mapped por si hay afip codes duplicados (ej. manual y
# auto)
if impo:
invoices = self.get_citi_invoices().filtered(lambda r: r.document_type_id.code == '66')
else:
invoices = self.get_citi_invoices().filtered(lambda r: r.document_type_id.code != '66')
invoices = self.get_citi_invoices(invoice_type='impo' if impo else 'not_impo')
for inv in invoices:
lines = []
is_zero = inv.currency_id.is_zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<field name="aliquots_filename" invisible="1"/>
<field name="import_aliquots_filename" invisible="1"/>
<group>
<field name="txt_type"/>
<field name="citi_skip_invoice_tests"/>
<label for="citi_skip_lines"/>
<div>
Expand Down

0 comments on commit 32ad108

Please sign in to comment.