add report account payable receivable

This commit is contained in:
wilsongomez 2022-02-18 18:15:16 -05:00
parent 2b2e1ef5c1
commit 824a4da0b2
1 changed files with 40 additions and 20 deletions

View File

@ -11,7 +11,8 @@ from trytond.pool import Pool
from trytond.wizard import Wizard, StateView, Button, StateReport
from trytond.report import Report
from decimal import Decimal
import copy
PRIMOS = [71, 67, 59, 53, 47, 43, 41, 37, 29, 23, 19, 17, 13, 7, 3]
# from trytond.i18n import gettext
@ -120,12 +121,13 @@ class AccountReceivablePayableReport(Report):
kind = cls.get_kind(type_, _type)
debit_kind = cls.get_kind(debit_type, _type)
columns = [
line.party.as_('party'),
party.id_number.as_('id_number'),
party.name.as_('name'),
party.type_document.as_('type_document'),
party.type_person.as_('type_person'),
move.company.as_('company'),
account.code.as_('Cuenta'),
party.type_document.as_('Tipo Documento'),
party.id_number.as_('Documento'),
party.name.as_('Nombre'),
party.type_person.as_('Tipo Persona'),
party.ciiu_code.as_('Codigo CIIU'),
move.company.as_('Compañia'),
Sum((line.debit - line.credit)).as_('balance'),
]
@ -180,18 +182,14 @@ class AccountReceivablePayableReport(Report):
| (reconciliation.date > date))
& (move.date <= date)
& (account.company == company_id),
group_by=(line.party, move.company, party.id_number,
group_by=(move.company, party.id_number,
party.name,
party.ciiu_code,
account.code,
party.type_document,
party.type_person),
having=((Sum(line.debit) - Sum(line.credit)) != 0))
# & line_query,
# & ((line.reconciliation == Null)
# | (reconciliation.date > date))
# ).join(debit_type, 'LEFT',
# condition=account.debit_type == debit_type.id
@classmethod
def get_terms(cls, terms):
terms_dict = {}
@ -239,29 +237,51 @@ class AccountReceivablePayableReport(Report):
@classmethod
def get_values(cls, query, records):
def get_check_digit(value, type_doc):
if type_doc != '31':
return None
value = value.replace(".", "")
if not value.isdigit():
return None
c = 0
p = len(PRIMOS) - 1
for n in reversed(value):
c += int(n) * PRIMOS[p]
p -= 1
dv = c % 11
if dv > 1:
dv = 11 - dv
return dv
cursor = Transaction().connection.cursor()
cursor.execute(*query)
columns = list(cursor.description)
columns = list(cursor.description)[:-2]
result = cursor.fetchall()
records_append = records.append
for row in result:
row_dict = {}
amount = row[-1]
type_doc = row[1]
for i, col in enumerate(columns):
row_dict[col.name] = row[i]
if i == 2:
row_dict['DV'] = get_check_digit(row[i], type_doc)
if amount:
terms_ = []
for k in row_dict.keys():
if k.startswith('term') and row_dict[k] > 0:
terms_.append(k)
if terms_:
for k in reversed(terms_):
for k in terms_[::-1]:
value = row_dict[k]
if value >= amount:
if value < amount:
amount -= row_dict[k]
row_dict[k] = 0
elif value >= amount:
row_dict[k] = value - amount
break
elif value < amount:
row_dict[k] = 0
amount -= row_dict[k]
records_append(row_dict)
return records