diff --git a/odex25_donation/affiliate_management/controllers/main.py b/odex25_donation/affiliate_management/controllers/main.py
index cdc0b7410..8d5ee2212 100644
--- a/odex25_donation/affiliate_management/controllers/main.py
+++ b/odex25_donation/affiliate_management/controllers/main.py
@@ -15,13 +15,44 @@
#################################################################################
import datetime
from odoo.addons.website_sale.controllers.main import WebsiteSale
+from odoo.addons.website_sale.controllers.main import Website
from odoo import http
from odoo.http import request
from odoo import fields
import logging
_logger = logging.getLogger(__name__)
-
+class Website(Website):
+
+ @http.route()
+ def index(self, **kw):
+ enable_ppc = request.env['res.config.settings'].sudo().website_constant().get('enable_ppc')
+ aff_key = request.httprequest.args.get('aff_key')
+ if aff_key and enable_ppc:
+ partner_id = request.env['res.partner'].sudo().search([('res_affiliate_key', '=', aff_key), ('is_affiliate', '=', True)])
+ vals = {
+ 'affiliate_method': 'ppc',
+ 'affiliate_key': aff_key,
+ 'affiliate_partner_id': partner_id.id,
+ 'url': request.httprequest.full_path,
+ 'ip_address': request.httprequest.environ['REMOTE_ADDR'],
+ 'type_id': 0,
+ 'convert_date': fields.datetime.now(),
+ 'affiliate_program_id': partner_id.affiliate_program_id.id,
+ 'affiliate_type': 'general'
+ }
+ if (len(partner_id) == 1):
+ check_unique_ppc = request.env['res.config.settings'].sudo().website_constant().get('unique_ppc_traffic')
+ if check_unique_ppc:
+ domain = [('affiliate_type', '=', 'general'), ('affiliate_method', '=', 'ppc'), ('affiliate_key', '=', aff_key), ('ip_address', '=', request.httprequest.environ['REMOTE_ADDR'])]
+ visit = request.env['affiliate.visit'].sudo().search(domain)
+ if not visit:
+ request.env['affiliate.visit'].sudo().create(vals)
+ else:
+ request.env['affiliate.visit'].sudo().create(vals)
+
+ return super().index(**kw)
+
class WebsiteSale(WebsiteSale):
def create_aff_visit_entry(self, vals):
diff --git a/odex25_donation/affiliate_management/models/affiliate_visit.py b/odex25_donation/affiliate_management/models/affiliate_visit.py
index 1b4cc509c..1b2bb1c7d 100644
--- a/odex25_donation/affiliate_management/models/affiliate_visit.py
+++ b/odex25_donation/affiliate_management/models/affiliate_visit.py
@@ -33,12 +33,14 @@ class AffiliateVisit(models.Model):
for record in self:
if record.affiliate_type == 'product':
record.type_name = record.env['product.template'].browse([record.type_id]).name
- if record.affiliate_type == 'category':
+ elif record.affiliate_type == 'category':
record.type_name = record.env['product.public.category'].browse([record.type_id]).name
+ else:
+ record.type_name = ''
affiliate_method = fields.Selection([("ppc", "Pay Per Click"), ("pps", "Pay Per Sale")], string="Order Report", readonly='True',
states={'draft': [('readonly', False)]}, help="state of traffic either ppc or pps")
- affiliate_type = fields.Selection([("product", "Product"), ("category", "Category")], string="Affiliate Type", readonly='True',
+ affiliate_type = fields.Selection([("product", "Product"), ("category", "Category"), ("general", "General")], string="Affiliate Type", readonly='True',
states={'draft': [('readonly', False)]}, help="whether the ppc or pps is on product or category")
type_id = fields.Integer(string='Type Id', readonly='True', states={'draft': [('readonly', False)]}, help="Id of product template on which ppc or pps traffic create")
type_name = fields.Char(string='Type Name', readonly='True', states={'draft': [('readonly', False)]}, compute='_calc_type_name', help="Name of the product")
diff --git a/odex25_donation/affiliate_management/models/res_partner_inherit.py b/odex25_donation/affiliate_management/models/res_partner_inherit.py
index 363dbf3e4..67eba9716 100644
--- a/odex25_donation/affiliate_management/models/res_partner_inherit.py
+++ b/odex25_donation/affiliate_management/models/res_partner_inherit.py
@@ -28,6 +28,8 @@ class ResPartnerInherit(models.Model):
affiliate_program_id = fields.Many2one("affiliate.program", string="Program", groups="affiliate_management.affiliate_security_user_group")
pending_amt = fields.Float(compute='_compute_pending_amt', string='Pending Amount')
approved_amt = fields.Float(compute='_compute_approved_amt', string='Approved Amount')
+ affiliate_id = fields.Many2one('res.partner', domain=[('is_affiliate', '=', True)])
+ affiliate_key = fields.Char(related="affiliate_id.res_affiliate_key", help="The key of the affiliate how invited this partner to the platform")
def toggle_active(self):
for o in self:
@@ -63,6 +65,6 @@ class ResPartnerInherit(models.Model):
for vals in vals_list:
if vals.get('is_affiliate'):
vals.update({
- 'affiliate_program_id': affiliate_program_id
+ 'affiliate_program_id': affiliate_program_id.id
})
return super().create(vals_list)
diff --git a/odex25_donation/affiliate_management/views/affiliate_manager_view.xml b/odex25_donation/affiliate_management/views/affiliate_manager_view.xml
index 8ebbaef3a..133f93c65 100644
--- a/odex25_donation/affiliate_management/views/affiliate_manager_view.xml
+++ b/odex25_donation/affiliate_management/views/affiliate_manager_view.xml
@@ -100,26 +100,28 @@
-
-
+
-
-
-
+
+
+
+
+
+
@@ -291,23 +293,27 @@
groups="base.group_system,affiliate_management.affiliate_security_manager_group"
colspan='4' />
+ col='4' readonly="1" attrs="{'invisible': [('is_affiliate', '=', False)]}"/>
-
-
+
+
+
+
+
+
diff --git a/odex25_donation/ensan_sale_management/models/res_partner.py b/odex25_donation/ensan_sale_management/models/res_partner.py
index 39b35ab32..49734b587 100644
--- a/odex25_donation/ensan_sale_management/models/res_partner.py
+++ b/odex25_donation/ensan_sale_management/models/res_partner.py
@@ -4,8 +4,6 @@ from odoo import models, fields, api
class ResPartner(models.Model):
_inherit = 'res.partner'
- affiliate_id = fields.Many2one('res.partner', domain=[('is_affiliate', '=', True)])
-
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)