Skip to content

Commit

Permalink
fixup! fixup! saved
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Nov 24, 2023
1 parent a00181c commit 854ae7a
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 54 deletions.
6 changes: 6 additions & 0 deletions setup/tg_website_sale_affiliate/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
2 changes: 1 addition & 1 deletion tg_website_sale_affiliate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "14.0.0.1.0",
"author": "IT-Projects LLC, Eugene Molotov",
"support": "[email protected]",
"website": "https://www.it-projects.info",
"website": "https://github.com/it-projects-llc/tg-addons",
"license": "LGPL-3",
"depends": [
"website_sale_affiliate",
Expand Down
6 changes: 4 additions & 2 deletions tg_website_sale_affiliate/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo.http import request, route
from odoo.http import request

from odoo.addons.website_sale_affiliate.controllers.main import WebsiteSale as Base

Expand All @@ -10,7 +10,9 @@ def _store_affiliate_info(self, **kwargs):
if not aff_request_id:
return

aff_request = request.env.user.sudo().env["sale.affiliate.request"].browse(aff_request_id)
aff_request = (
request.env.user.sudo().env["sale.affiliate.request"].browse(aff_request_id)
)
affiliate = aff_request.affiliate_id
pricelist = affiliate.pricelist_id

Expand Down
32 changes: 17 additions & 15 deletions tg_website_sale_affiliate/data/mail_template_data.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="1">
<record id="send_invitation_mail_template" model="mail.template">
<field name="name">Affiliate: send invitation</field>
<field name="model_id" ref="website_sale_affiliate.model_sale_affiliate" />
<field name="subject">Affiliate Invitation</field>
<field name="email_from">"${object.company_id.name | safe}" &lt;${(object.company_id.email or user.email) | safe}&gt;</field>
<field name="email_to">${object.partner_id.email_formatted | safe}</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="body_html" type="html">
<p>Hello, ${object.name}! You affiliate link: <a href="${object.referal_link}">${object.referal_link}</a></p>
</field>
</record>
</data>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="send_invitation_mail_template" model="mail.template">
<field name="name">Affiliate: send invitation</field>
<field name="model_id" ref="website_sale_affiliate.model_sale_affiliate" />
<field name="subject">Affiliate Invitation</field>
<field
name="email_from"
>"${object.company_id.name | safe}" &lt;${(object.company_id.email or user.email) | safe}&gt;</field>
<field name="email_to">${object.partner_id.email_formatted | safe}</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="body_html" type="html">
<p>Hello, ${object.name}! You affiliate link: <a
href="${object.referal_link}"
>${object.referal_link}</a></p>
</field>
</record>
</odoo>
9 changes: 4 additions & 5 deletions tg_website_sale_affiliate/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ class Partner(models.Model):

def action_show_affiliates(self):
affiliates = self.mapped("affiliates")
action = self.env["ir.actions.actions"]._for_xml_id("website_sale_affiliate.sale_affiliate_action")
action = self.env["ir.actions.actions"]._for_xml_id(
"website_sale_affiliate.sale_affiliate_action"
)
if len(affiliates) == 1:
action.update(
views=[(False, "form")],
res_id = affiliates.id
)
action.update(views=[(False, "form")], res_id=affiliates.id)
else:
action["domain"] = [("id", "in", affiliates.ids)]

Expand Down
33 changes: 20 additions & 13 deletions tg_website_sale_affiliate/models/sale_affiliate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from odoo import api, fields, models
from odoo.tools import defaultdict
from urllib.parse import urljoin

from odoo import api, fields, models


class SaleAffiliate(models.Model):
_inherit = ["sale.affiliate", "mail.thread"]
Expand All @@ -12,24 +12,27 @@ class SaleAffiliate(models.Model):

partner_id = fields.Many2one("res.partner")
code_promo_program_id = fields.Many2one(
'coupon.program',
"coupon.program",
string="Promo Program",
domain="[('promo_code_usage', '=', 'code_needed'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]",
domain="[('promo_code_usage', '=', 'code_needed'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", # noqa: E950
copy=False,
)
order_count = fields.Integer(compute="_compute_order_count")
referal_link = fields.Char(compute="_compute_referal_link")

def _get_order_dict(self):
self.env.cr.execute("""
self.env.cr.execute(
"""
SELECT sar.affiliate_id, array_agg(so.id)
FROM sale_affiliate_request sar
LEFT JOIN sale_order so ON so.affiliate_request_id = sar.id
WHERE sar.affiliate_id IN %s
GROUP BY sar.affiliate_id
""", [tuple(self.ids)])
""",
[tuple(self.ids)],
)

return dict((row[0], row[1]) for row in self.env.cr.fetchall())
return {row[0]: row[1] for row in self.env.cr.fetchall()}

def _compute_order_count(self):
r = self._get_order_dict()
Expand All @@ -39,15 +42,17 @@ def _compute_order_count(self):

def _compute_referal_link(self):
for record in self:
record.referal_link = urljoin(record.get_base_url(), f"/events?aff_ref={record.id}")
record.referal_link = urljoin(
record.get_base_url(), f"/events?aff_ref={record.id}"
)

def action_show_orders(self):
order_dict = self._get_order_dict()
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_quotations")
action['domain'] = [('id', 'in', order_dict.get(self.id) or [])]
action['context'] = {
'create': False,
'edit': False,
action["domain"] = [("id", "in", order_dict.get(self.id) or [])]
action["context"] = {
"create": False,
"edit": False,
}
return action

Expand All @@ -56,7 +61,9 @@ def _subscribe_partner(self):
record.message_subscribe(partner_ids=record.partner_id.ids)

def _send_invitation(self):
template = self.env.ref("tg_website_sale_affiliate.send_invitation_mail_template")
template = self.env.ref(
"tg_website_sale_affiliate.send_invitation_mail_template"
)
template.send_mail(self.id, force_send=True, raise_exception=True)

@api.model_create_multi
Expand Down
2 changes: 1 addition & 1 deletion tg_website_sale_affiliate/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models
from odoo import models


class SaleOrder(models.Model):
Expand Down
16 changes: 12 additions & 4 deletions tg_website_sale_affiliate/views/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="partner_view_form" model="ir.ui.view">
<field name="name">res.partner.form.tg.affiliate</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="action_show_affiliates"
icon="fa-handshake-o">
<field string="Affliaites" name="affiliate_count" widget="statinfo"/>
<button
class="oe_stat_button"
type="object"
name="action_show_affiliates"
icon="fa-handshake-o"
>
<field
string="Affliaites"
name="affiliate_count"
widget="statinfo"
/>
</button>
</div>
</field>
Expand Down
33 changes: 20 additions & 13 deletions tg_website_sale_affiliate/views/sale_affiliate_views.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="sale_affiliate_view_form" model="ir.ui.view">
<field name="name">sale.affiliate.form.tg</field>
<field name="model">sale.affiliate</field>
<field name="inherit_id" ref="website_sale_affiliate.sale_affiliate_view_form" />
<field
name="inherit_id"
ref="website_sale_affiliate.sale_affiliate_view_form"
/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="action_show_orders"
type="object"
class="oe_stat_button"
icon="fa-usd"
>
<field string="Sales" name="order_count" widget="statinfo"/>
<button
name="action_show_orders"
type="object"
class="oe_stat_button"
icon="fa-usd"
>
<field string="Sales" name="order_count" widget="statinfo" />
</button>
</xpath>
<xpath expr="//field[@name='partner_id']" position="attributes">
Expand All @@ -23,18 +27,21 @@
</xpath>
<xpath expr="//sheet" position="after">
<div class="oe_chatter">
<field name="message_follower_ids"/>
<field name="message_ids"/>
<field name="message_follower_ids" />
<field name="message_ids" />
</div>
</xpath>
</field>
</record>

<record id="action_send_password_reset_instructions" model="ir.actions.server">
<field name="name">Send invitation</field>
<field name="model_id" ref="website_sale_affiliate.model_sale_affiliate"/>
<field name="groups_id" eval="[(4, ref('base.group_erp_manager'))]"/>
<field name="binding_model_id" ref="website_sale_affiliate.model_sale_affiliate" />
<field name="model_id" ref="website_sale_affiliate.model_sale_affiliate" />
<field name="groups_id" eval="[(4, ref('base.group_erp_manager'))]" />
<field
name="binding_model_id"
ref="website_sale_affiliate.model_sale_affiliate"
/>
<field name="state">code</field>
<field name="code">records._send_invitation()</field>
</record>
Expand Down

0 comments on commit 854ae7a

Please sign in to comment.