143 lines
5.2 KiB
Python
143 lines
5.2 KiB
Python
|
# The COPYRIGHT file at the top level of this repository contains the full
|
||
|
# copyright notices and license terms.
|
||
|
from trytond.model import ModelView, fields
|
||
|
from trytond.wizard import Wizard, StateView, Button, StateReport
|
||
|
from trytond.report import Report
|
||
|
from trytond.pool import Pool, PoolMeta
|
||
|
from trytond.transaction import Transaction
|
||
|
from trytond.pyson import Eval
|
||
|
from trytond.exceptions import UserError
|
||
|
|
||
|
__all__ = ['BalancePartyStart', 'PrintBalanceParty', 'BalanceParty']
|
||
|
|
||
|
class BalanceInvoicePartyStart(ModelView):
|
||
|
'Balance Party Start'
|
||
|
__name__ = 'account_co_reports.print_balance_invoice_party.start'
|
||
|
|
||
|
party = fields.Many2One('party.party', 'Party', required=True)
|
||
|
start_period = fields.Many2One('account.period', 'Start Period',
|
||
|
domain=[
|
||
|
('start_date', '<=', (Eval('end_period'), 'start_date')),
|
||
|
], depends=['fiscalyear', 'end_period'])
|
||
|
end_period = fields.Many2One('account.period', 'End Period',
|
||
|
domain=[
|
||
|
('start_date', '>=', (Eval('start_period'), 'start_date'))
|
||
|
],
|
||
|
depends=['start_period'])
|
||
|
company = fields.Many2One('company.company', 'Company', required=True)
|
||
|
party_type = fields.Selection([('out', 'Customer'),
|
||
|
('in', 'Supplier')], "Party Type", required=True)
|
||
|
|
||
|
@staticmethod
|
||
|
def default_company():
|
||
|
return Transaction().context.get('company')
|
||
|
|
||
|
class PrintBalanceInvoiceParty(Wizard):
|
||
|
'Print Balance Invoice Party'
|
||
|
__name__ = 'account_co_reports.print_balance_invoice_party'
|
||
|
|
||
|
start = StateView('account_co_reports.print_balance_invoice_party.start',
|
||
|
'account_co_reports.print_balance_invoice_party_start_view_form', [
|
||
|
Button('Cancel', 'end', 'tryton-cancel'),
|
||
|
Button('Print', 'print_', 'tryton-print', default=True),
|
||
|
])
|
||
|
|
||
|
print_ = StateReport('account_co_reports.balance_invoice_party')
|
||
|
|
||
|
def do_print_(self, action):
|
||
|
party = None
|
||
|
party_type = None
|
||
|
|
||
|
if self.start.party:
|
||
|
party = self.start.party.id
|
||
|
if self.start.party_type:
|
||
|
party_type = self.start.party_type
|
||
|
|
||
|
data = {
|
||
|
'company': self.start.company.id,
|
||
|
'party': party,
|
||
|
'party_type': party_type
|
||
|
}
|
||
|
return action, data
|
||
|
|
||
|
def transition_print_(self):
|
||
|
return 'end'
|
||
|
|
||
|
|
||
|
class BalanceInvoiceParty(Report):
|
||
|
__name__ = 'account_co_reports.balance_invoice_party'
|
||
|
|
||
|
@classmethod
|
||
|
def get_context(cls, records, header, data):
|
||
|
report_context = super(BalanceInvoiceParty, cls).get_context(records, header, data)
|
||
|
pool = Pool()
|
||
|
Company = pool.get('company.company')
|
||
|
Period = pool.get('account.period')
|
||
|
Invoice = pool.get('account.invoice')
|
||
|
Party = pool.get('party.party')
|
||
|
start_period = None
|
||
|
end_period = None
|
||
|
party = None
|
||
|
company = Company(data['company'])
|
||
|
dom_invoice = [('state', 'in', ["posted", "paid"])]
|
||
|
|
||
|
if data.get('party'):
|
||
|
party = data['party']
|
||
|
dom_invoice.append(('party', '=', party))
|
||
|
|
||
|
if data.get('party_type') == 'in':
|
||
|
dom_invoice.append(('type', '=', "in"))
|
||
|
elif data.get('party_type') == 'out':
|
||
|
dom_invoice.append(('type', '=', "out"))
|
||
|
else:
|
||
|
dom_invoice.append(('type', 'in', ["out", "in"]))
|
||
|
|
||
|
party_type = data.get('party_type')
|
||
|
|
||
|
if data.get('start_period'):
|
||
|
start_period = Period(data['start_period'])
|
||
|
dom_invoice.append(('invoice_date', '>=', start_period.start_date))
|
||
|
if data.get('end_period'):
|
||
|
end_period = Period(data['end_period'])
|
||
|
dom_invoice.append(('invoice_date', '<=', end_period.start_date))
|
||
|
|
||
|
invoices = Invoice.search(dom_invoice,
|
||
|
order=[('invoice_date', 'DESC'),
|
||
|
('id', 'DESC')],)
|
||
|
|
||
|
res = {}
|
||
|
dict_location = {}
|
||
|
|
||
|
id_ = party
|
||
|
party_ = Party.search(['id', '=', party])[0]
|
||
|
name = party_.rec_name
|
||
|
|
||
|
try:
|
||
|
if party_.identifiers:
|
||
|
id_number = party_.identifiers[0].code
|
||
|
else:
|
||
|
id_number = ''
|
||
|
except IndexError:
|
||
|
pass
|
||
|
|
||
|
res[id_] = {'name': name,
|
||
|
'id_number': id_number,
|
||
|
'party': party_
|
||
|
}
|
||
|
|
||
|
if invoices:
|
||
|
res[id_]['invoices'] = invoices
|
||
|
else:
|
||
|
if party_type == 'in':
|
||
|
raise UserError(str("Este Tercero no Cuenta Con Facturas de Proveedor."))
|
||
|
else:
|
||
|
raise UserError(str("Este Tercero no Cuenta Con Facturas de Cliente."))
|
||
|
|
||
|
report_context['records'] = res.values()
|
||
|
report_context['start_period'] = start_period.name if start_period else '*'
|
||
|
report_context['end_period'] = end_period.name if end_period else '*'
|
||
|
report_context['company'] = company
|
||
|
report_context['party_type'] = party_type
|
||
|
|
||
|
return report_context
|