[IMP] affiliate_management: register click event on home , add affiliate in partner view
This commit is contained in:
parent
ae6e31ac16
commit
97700beac8
|
|
@ -15,12 +15,43 @@
|
|||
#################################################################################
|
||||
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):
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -100,26 +100,28 @@
|
|||
<field name="is_affiliate" string="Is a Affiliate"
|
||||
groups="base.group_system,affiliate_management.affiliate_security_manager_group"
|
||||
colspan='4' />
|
||||
<field name="affiliate_program_id" colspan="4"
|
||||
widget="selection" col='4' readonly="1" />
|
||||
<field name="res_affiliate_key" string="Affiliate Key"
|
||||
readonly="1"
|
||||
attrs="{'invisible':[('res_affiliate_key','=',False)]}"
|
||||
<field name="affiliate_program_id" colspan="4" widget="selection"
|
||||
col='4' readonly="1" attrs="{'invisible': [('is_affiliate', '=', False)]}"/>
|
||||
<field name="res_affiliate_key" string="Affiliate Key" readonly="1"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','=',False)]}"
|
||||
colspan="4" />
|
||||
<field name="res_affiliate_key" string="Affiliate Key"
|
||||
readonly="1"
|
||||
attrs="{'invisible':[('res_affiliate_key','!=',False)]}"
|
||||
<field name="res_affiliate_key" string="Affiliate Key" readonly="1"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','!=',False)]}"
|
||||
colspan="3" />
|
||||
<button
|
||||
name="generate_key"
|
||||
type="object"
|
||||
string="generate"
|
||||
attrs="{'invisible':[('res_affiliate_key','!=',False)]}"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','!=',False)]}"
|
||||
class="oe_link oe_edit_only oe_inline" colspan='1'
|
||||
groups="base.group_system,affiliate_management.affiliate_security_manager_group"
|
||||
/>
|
||||
<field name="pending_amt" colspan="4" />
|
||||
<field name="approved_amt" colspan="4" />
|
||||
<field name="pending_amt" attrs="{'invisible': [('is_affiliate', '=', False)]}" colspan="4" />
|
||||
<field name="approved_amt" attrs="{'invisible': [('is_affiliate', '=', False)]}" colspan="4" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="affiliate_id" readonly="True"/>
|
||||
<field name="affiliate_key" readonly="True"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
|
@ -291,23 +293,27 @@
|
|||
groups="base.group_system,affiliate_management.affiliate_security_manager_group"
|
||||
colspan='4' />
|
||||
<field name="affiliate_program_id" colspan="4" widget="selection"
|
||||
col='4' readonly="1" />
|
||||
col='4' readonly="1" attrs="{'invisible': [('is_affiliate', '=', False)]}"/>
|
||||
<field name="res_affiliate_key" string="Affiliate Key" readonly="1"
|
||||
attrs="{'invisible':[('res_affiliate_key','=',False)]}"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','=',False)]}"
|
||||
colspan="4" />
|
||||
<field name="res_affiliate_key" string="Affiliate Key" readonly="1"
|
||||
attrs="{'invisible':[('res_affiliate_key','!=',False)]}"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','!=',False)]}"
|
||||
colspan="3" />
|
||||
<button
|
||||
name="generate_key"
|
||||
type="object"
|
||||
string="generate"
|
||||
attrs="{'invisible':[('res_affiliate_key','!=',False)]}"
|
||||
attrs="{'invisible':['|', ('is_affiliate', '=', False), ('res_affiliate_key','!=',False)]}"
|
||||
class="oe_link oe_edit_only oe_inline" colspan='1'
|
||||
groups="base.group_system,affiliate_management.affiliate_security_manager_group"
|
||||
/>
|
||||
<field name="pending_amt" colspan="4" />
|
||||
<field name="approved_amt" colspan="4" />
|
||||
<field name="pending_amt" attrs="{'invisible': [('is_affiliate', '=', False)]}" colspan="4" />
|
||||
<field name="approved_amt" attrs="{'invisible': [('is_affiliate', '=', False)]}" colspan="4" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="affiliate_id" readonly="True"/>
|
||||
<field name="affiliate_key" readonly="True"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue