|
@@ -58,11 +58,50 @@ class AccountVoucher(models.Model):
|
|
|
account_voucher = self.create(values)
|
|
|
account_voucher.action_move_line_create()
|
|
|
|
|
|
+ # Si no tiene deuda actualizar la factura a pagada
|
|
|
if invoice.residual <= 0:
|
|
|
invoice.write({
|
|
|
'state': 'paid'
|
|
|
})
|
|
|
|
|
|
+ # Usuario id
|
|
|
+ user = self.env.user
|
|
|
+
|
|
|
+ # Fecha del servidor
|
|
|
+ today = fields.Date.context_today(self)
|
|
|
+
|
|
|
+ # Consultar Caja Abierta, Método de Pagos, Fecha de Hoy
|
|
|
+ bank_statement = self.env['account.bank.statement'].search([('state', '=', 'open'), ('journal_id', '=', [journal.id]), ('date', '=', today)])
|
|
|
+
|
|
|
+ # Crea caja si no tiene caja con el método de pago y la fecha de hoy
|
|
|
+ if not bank_statement:
|
|
|
+ bank = {
|
|
|
+ 'journal_id': journal.id,
|
|
|
+ 'period_id': int(period.id),
|
|
|
+ 'date': today,
|
|
|
+ 'user_id': user.id
|
|
|
+ }
|
|
|
+ bank_statement = bank_statement.create(bank)
|
|
|
+
|
|
|
+ # Crea la linea en la caja del pago realizado
|
|
|
+ line = {
|
|
|
+ 'statement_id': bank_statement.id,
|
|
|
+ 'name': account_voucher.reference,
|
|
|
+ 'partner_id': account_voucher.partner_id.id,
|
|
|
+ 'amount': account_voucher.amount,
|
|
|
+ 'voucher_id': account_voucher.id,
|
|
|
+ 'journal_id': account_voucher.journal_id.id,
|
|
|
+ 'account_id': account_voucher.account_id.id,
|
|
|
+ 'journal_entry_id': account_voucher.move_id.id,
|
|
|
+ 'currency_id': account_voucher.currency_id.id,
|
|
|
+ 'ref': 'NP'
|
|
|
+ }
|
|
|
+ statement_line = self.env['account.bank.statement.line'].create(line)
|
|
|
+
|
|
|
+ # Actualizar La caja en Estado Abierto
|
|
|
+ bank_statement.write({'state': 'open'})
|
|
|
+
|
|
|
+ # Retorna el ticket de pagos
|
|
|
return {
|
|
|
'action_id': self.env['ir.actions.report.xml'].search([('report_name', '=', 'voucher_print.report_voucher')]).id,
|
|
|
'voucher_id': account_voucher.id
|