from odoo import models, fields, api
|
|
from odoo.exceptions import UserError, ValidationError, Warning
|
|
from psycopg2 import sql, DatabaseError
|
|
import logging
|
|
from werkzeug import utils
|
|
import re
|
|
_logger = logging.getLogger(__name__)
|
|
import json
|
|
|
|
class AccountMove(models.Model):
|
|
_inherit = 'account.move'
|
|
|
|
description=fields.Char(compute='_compute_description')
|
|
transaction_date=fields.Datetime(compute='_compute_transaction_date')
|
|
transaction_amount=fields.Float(compute='_compute_transaction_amount')
|
|
systempay_ref=fields.Text(compute='_compute_systempay_ref')
|
|
date_compta=fields.Datetime('date import',default=False)
|
|
date_compta_end_of_stay=fields.Datetime('date import',default=False)
|
|
date_compta_out_refund=fields.Datetime('date import',default=False)
|
|
out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]")
|
|
payment_ids=fields.Many2many('account.payment',compute='_compute_payment_ids')
|
|
|
|
def _compute_payment_ids(self):
|
|
|
|
payments=self.env['account.payment'].sudo().search([])
|
|
|
|
for rec in self:
|
|
rec.payment_ids=False
|
|
for p in payments:
|
|
for recon in p.reconciled_invoice_ids:
|
|
if recon.id==rec.id:
|
|
rec.write({'payment_ids':[(4,p.id)]})
|
|
|
|
|
|
|
|
|
|
def _compute_description(self):
|
|
|
|
for a in self:
|
|
|
|
a.description=''
|
|
for line in a.line_ids:
|
|
a.description=line.product_id.name
|
|
break
|
|
|
|
def _compute_transaction_date(self):
|
|
|
|
for a in self:
|
|
a.transaction_date=False
|
|
for t in a.transaction_ids:
|
|
a.transaction_date=t.date
|
|
break
|
|
|
|
def _compute_transaction_amount(self):
|
|
|
|
for a in self:
|
|
a.transaction_amount=False
|
|
for t in a.transaction_ids:
|
|
a.transaction_amount=t.amount
|
|
break
|
|
|
|
def _compute_systempay_ref(self):
|
|
|
|
for a in self:
|
|
a.systempay_ref=False
|
|
for t in a.transaction_ids:
|
|
if t.systempay_raw_data:
|
|
raw=t.systempay_raw_data.split(",")
|
|
for r in raw:
|
|
r_s=r.split(":")
|
|
#_logger.error('vads:'+r_s[0])
|
|
if r_s[0]==" 'vads_order_id'":
|
|
a.systempay_ref=r_s[1].replace("'","")
|
|
break
|
|
def button_event_registration(self):
|
|
reg=self.env['event.registration'].search(['|','|','|',('invoice_id','=',self.id),\
|
|
('down_payment_invoice_id','=',self.id),\
|
|
('balance_invoice_id','=',self.id),\
|
|
('end_of_stay_invoice_id','=',self.id)])
|
|
|
|
if reg :
|
|
event_id=reg.event_id
|
|
action=self.env.ref('event.action_registration').read()[0]
|
|
|
|
action.update({
|
|
'view_mode': 'form',
|
|
'res_id': reg.id,
|
|
'view_type':'form',
|
|
"views": [[False, "form"]],
|
|
|
|
|
|
})
|
|
return action
|
|
|