|
|
@ -1,5 +1,5 @@ |
|
|
|
from odoo import models, fields, api |
|
|
|
from odoo.exceptions import UserError, ValidationError |
|
|
|
from odoo.exceptions import UserError, ValidationError,Warning |
|
|
|
from psycopg2 import sql, DatabaseError |
|
|
|
|
|
|
|
from werkzeug import utils |
|
|
@ -27,8 +27,8 @@ class opendons_payment_batch(models.Model): |
|
|
|
'Product', |
|
|
|
required=True, |
|
|
|
domain=[('donation', '=', True)], |
|
|
|
ondelete='restrict', |
|
|
|
store=False |
|
|
|
ondelete='restrict' |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -89,7 +89,7 @@ class opendons_payment_batch(models.Model): |
|
|
|
donation_amount = fields.Monetary( |
|
|
|
'Donation amount', |
|
|
|
currency_field='currency_id', |
|
|
|
store=False, |
|
|
|
|
|
|
|
) |
|
|
|
# payment_lines = fields.One2many( |
|
|
|
# 'opendons_payment_batch.lines', |
|
|
@ -107,37 +107,62 @@ class opendons_payment_batch(models.Model): |
|
|
|
def _onchange_payment_input(self): |
|
|
|
|
|
|
|
if self.payment_input: |
|
|
|
|
|
|
|
|
|
|
|
inpt=self.payment_input.split(';') |
|
|
|
if len(inpt)!=4:raise ValidationError('input string not valid') |
|
|
|
partner_id=int(inpt[0]) |
|
|
|
key=inpt[1] |
|
|
|
operation_id=int(inpt[2]) |
|
|
|
segment_id=int(inpt[3]) |
|
|
|
|
|
|
|
partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)]) |
|
|
|
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))]) |
|
|
|
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))]) |
|
|
|
|
|
|
|
if not partner : ValidationError('partner not found') |
|
|
|
if not operation : ValidationError('operation not found') |
|
|
|
if not segment : ValidationError('segment not found') |
|
|
|
|
|
|
|
|
|
|
|
self.partner_id=partner_id |
|
|
|
self.operation_id=operation_id |
|
|
|
self.segment_id=segment_id |
|
|
|
res=self.action_ajouter_payment() |
|
|
|
|
|
|
|
#si le QRCODE a déjà été utilisé, message d'avertissement |
|
|
|
qrcode_exist=self.env['opendons.payment_batch_qrcode'].search([('qrcode','=',self.payment_input)]) |
|
|
|
if qrcode_exist : raise Warning('qrcode already used') |
|
|
|
|
|
|
|
if self.input_mode=='loyalty': |
|
|
|
|
|
|
|
inpt=self.payment_input.split(';') |
|
|
|
if len(inpt)!=4:raise ValidationError('input string not valid') |
|
|
|
partner_id=int(inpt[0]) |
|
|
|
key=inpt[1] |
|
|
|
operation_id=int(inpt[2]) |
|
|
|
segment_id=int(inpt[3]) |
|
|
|
|
|
|
|
partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)]) |
|
|
|
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))]) |
|
|
|
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))]) |
|
|
|
|
|
|
|
if not partner : ValidationError('partner not found') |
|
|
|
if not operation : ValidationError('operation not found') |
|
|
|
if not segment : ValidationError('segment not found') |
|
|
|
|
|
|
|
|
|
|
|
self.partner_id=partner_id |
|
|
|
self.operation_id=operation_id |
|
|
|
self.segment_id=segment_id |
|
|
|
res=self.action_ajouter_payment() |
|
|
|
|
|
|
|
|
|
|
|
if self.input_mode=='prospect': |
|
|
|
inpt=self.payment_input.split(';') |
|
|
|
if len(inpt)!=4:raise ValidationError('input string not valid') |
|
|
|
partner_string=int(inpt[0]) |
|
|
|
key=inpt[1] |
|
|
|
operation_id=int(inpt[2]) |
|
|
|
segment_id=int(inpt[3]) |
|
|
|
|
|
|
|
#partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)]) |
|
|
|
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))]) |
|
|
|
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))]) |
|
|
|
|
|
|
|
#if not partner : ValidationError('partner not found') |
|
|
|
if not operation : ValidationError('operation not found') |
|
|
|
if not segment : ValidationError('segment not found') |
|
|
|
|
|
|
|
#self.partner_id=partner_id |
|
|
|
self.operation_id=operation_id |
|
|
|
self.segment_id=segment_id |
|
|
|
#res=self.action_ajouter_payment() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def action_ajouter_payment(self): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vals={} |
|
|
|
vals['payment_batch_id']=self.id |
|
|
|
vals['payment_mode_id']=int(self.payment_mode_id) |
|
|
@ -154,14 +179,26 @@ class opendons_payment_batch(models.Model): |
|
|
|
vals['donation_id']=donation.id |
|
|
|
vals['currency_id']=self.currency_id |
|
|
|
#vals['company_currency_id']=self.company_currency_id |
|
|
|
vals['product_id']=int(self.product_id) |
|
|
|
vals['product_id']=self.product_id.id |
|
|
|
vals['quantity']=1 |
|
|
|
vals['unit_price']=self.donation_amount |
|
|
|
donation_line=self.env['donation.line'].create(vals) |
|
|
|
|
|
|
|
donation.validate() |
|
|
|
vals={} |
|
|
|
|
|
|
|
vals['qrcode']=self.payment_input |
|
|
|
self.env['opendons.payment_batch_qrcode'].create(vals) |
|
|
|
|
|
|
|
self.payment_input=False |
|
|
|
self.partner_id=False |
|
|
|
self.operation_id=False |
|
|
|
self.segment_id=False |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
class opendons_payment_batch_qrcode(models.Model): |
|
|
|
_name = 'opendons.payment_batch_qrcode' |
|
|
|
_description = 'store qrcode to avoid duplicate entries' |
|
|
|
|
|
|
|
|
|
|
|
qrcode=fields.Char('qrcode') |