from odoo import models, fields, api
|
|
from odoo.exceptions import UserError, ValidationError, Warning
|
|
from psycopg2 import sql, DatabaseError
|
|
|
|
from werkzeug import utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class partner(models.Model):
|
|
_inherit = 'res.partner'
|
|
|
|
# @api.depends('qualifier_ids.partner_id')
|
|
# def _compute_text_qualifier_count(self):
|
|
# # The current user may not have access rights for donations
|
|
# for partner in self:
|
|
# try:
|
|
# partner.text_qualifier_count = len(partner.qualifier_ids)
|
|
# except Exception:
|
|
# partner.text_qualifier_count = 0
|
|
|
|
# @api.depends('qualifier_ids.partner_id')
|
|
# def _compute_bool_qualifier_count(self):
|
|
# # The current user may not have access rights for donations
|
|
# for partner in self:
|
|
# try:
|
|
|
|
# for qualifier_id in partner.qualifier_ids:
|
|
|
|
# partner.bool_qualifier_count =self.env['opendons_qualifier.partnerqualifier'].search([(partner.qual_i
|
|
# except Exception:
|
|
# partner.bool_qualifier_count = 0
|
|
|
|
def _compute_address_count(self):
|
|
# The current user may not have access rights for donations
|
|
for partner in self:
|
|
try:
|
|
partner.address_count = len(partner.address_ids)
|
|
except Exception:
|
|
partner.address_count = 0
|
|
|
|
def _compute_email_count(self):
|
|
# The current user may not have access rights for donations
|
|
for partner in self:
|
|
try:
|
|
partner.email_count = len(partner.email_ids)
|
|
except Exception:
|
|
partner.email_count = 0
|
|
|
|
def _compute_phone_count(self):
|
|
# The current user may not have access rights for donations
|
|
for partner in self:
|
|
try:
|
|
partner.phone_count = len(partner.phone_ids)
|
|
except Exception:
|
|
partner.phone_count = 0
|
|
|
|
def _compute_relationshipPartner_count(self):
|
|
# The current user may not have access rights for donations
|
|
for partner in self:
|
|
try:
|
|
partner.relationshipPartner_count = len(partner.relationshipPartner_ids)
|
|
except Exception:
|
|
partner.relationshipPartner_count = 0
|
|
|
|
def _compute_recurring_donation_count(self):
|
|
# The current user may not have access rights for donations
|
|
for partner in self:
|
|
try:
|
|
partner.recurring_donation_count=self.env['donation.donation'].search_count(['&',('recurring_template','!=',''),('partner_id','=',int(partner.id))])
|
|
|
|
except Exception:
|
|
partner.recurring_donation_count = 0
|
|
|
|
qualifier_ids = fields.One2many(
|
|
'opendons_qualifier.partnerqualifier',
|
|
'partner_id',
|
|
string='Qualifier',
|
|
readonly=True
|
|
)
|
|
# text_qualifier_count = fields.Integer(
|
|
# compute='_compute_text_qualifier_count',
|
|
# string="# of Qualifiers",
|
|
# readonly=True
|
|
# )
|
|
# bool_qualifier_count = fields.Integer(
|
|
# compute='_compute_bool_qualifier_count',
|
|
# string="# of Qualifiers",
|
|
# readonly=True
|
|
# )
|
|
|
|
address_ids = fields.One2many(
|
|
'opendons.partneraddress',
|
|
'partner_id',
|
|
string='Address',
|
|
readonly=True
|
|
)
|
|
|
|
# request_ids = fields.One2many(
|
|
# 'opendons.request',
|
|
# 'partner_ids',
|
|
# string='Request',
|
|
# readonly=True
|
|
# )
|
|
request_ids = fields.Many2many('opendons.request', 'request_partner_rel', 'partner_id', 'request_id', string='requests')
|
|
operation_ids = fields.Many2many('opendons.operation', 'operation_partner_rel', 'partner_id', 'operation_id', string='operations')
|
|
operation_excl_ids = fields.Many2many('opendons.operation', 'operation_excl_partner_rel', 'partner_id', 'operation_id', string='excluded operations')
|
|
segment_ids = fields.Many2many('opendons.segment', 'segment_partner_rel', 'partner_id', 'segment_id', string='segments')
|
|
|
|
|
|
address_count = fields.Integer(
|
|
compute='_compute_address_count',
|
|
string="# of Addresses",
|
|
readonly=True
|
|
)
|
|
relationshipPartner_ids = fields.One2many(
|
|
'opendons_relationship.partner',
|
|
'partner_id',
|
|
string='Relationship',
|
|
readonly=True
|
|
)
|
|
relationshipPartner_count = fields.Integer(
|
|
compute='_compute_relationshipPartner_count',
|
|
string="# of Relationship",
|
|
readonly=True
|
|
)
|
|
email_ids = fields.One2many(
|
|
'opendons.partneremail',
|
|
'partner_id',
|
|
string='Email',
|
|
readonly=True
|
|
)
|
|
email_count = fields.Integer(
|
|
compute='_compute_email_count',
|
|
string="# of email",
|
|
readonly=True
|
|
)
|
|
phone_ids = fields.One2many(
|
|
'opendons.partnerphone',
|
|
'partner_id',
|
|
string='Phone',
|
|
readonly=True
|
|
)
|
|
phone_count = fields.Integer(
|
|
compute='_compute_phone_count',
|
|
string="# of phone",
|
|
readonly=True
|
|
)
|
|
recurring_donation_count = fields.Integer(
|
|
compute='_compute_recurring_donation_count',
|
|
string="# of recurring donation",
|
|
readonly=True
|
|
)
|
|
|
|
key=fields.Integer(
|
|
#compute='_compute_key',
|
|
string="Key",
|
|
#store=True,
|
|
readonly=True
|
|
|
|
)
|
|
firstname=fields.Char(string="First name")
|
|
npai_count=fields.Integer(String="NPAI count", readonly=True)
|
|
source=fields.Char(String="source")
|
|
|
|
def _compute_key(self):
|
|
for rec in self:
|
|
rec.key=int(rec.id)*40456
|
|
|
|
def _compute_all_key(self):
|
|
|
|
#for rec in self.env:
|
|
#rec.write({'key':3})
|
|
#raise Warning(rec.id)
|
|
for rec in self.env['res.partner'].search([]):
|
|
rec.key=2
|
|
#raise Warning(len())
|
|
|
|
@api.onchange('street')
|
|
def _onchange_street(self):
|
|
for rec in self:
|
|
rec.npai_count=0
|
|
return
|