Skip to content

Commit 3be1f82

Browse files
committed
[IMP] estate: added a bridge module for WhatsApp to send message.
Features added: 1) User can create their WhatsApp templates. 2) A WhatsApp message will be sent to the buyer when the property is sold.
1 parent bf9f725 commit 3be1f82

File tree

8 files changed

+102
-0
lines changed

8 files changed

+102
-0
lines changed

estate_whatsapp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

estate_whatsapp/__manifest__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "ESTATE WHATSAPP",
3+
"version": "1.0",
4+
"category": "Real Estate/Brokerage",
5+
"website": "https://www.odoo.com",
6+
"depends": ["base", "whatsapp", "estate"],
7+
"data": ["views/estate_whatsapp_config.xml", "views/estate_menus.xml"],
8+
"installable": True,
9+
"application": True,
10+
"license": "AGPL-3",
11+
"author": "Odoo",
12+
}

estate_whatsapp/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import estate_property
2+
from . import res_config_settings
3+
from . import res_company
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from odoo import models, fields
2+
3+
4+
class EstateProperty(models.Model):
5+
_inherit = "estate.property"
6+
7+
def action_change_state(self):
8+
param_value = self.env.context.get("param_name", "default_value")
9+
10+
if param_value == "sold":
11+
12+
self.state = "sold"
13+
whatsapp_composer = (
14+
self.env["whatsapp.composer"]
15+
.with_context({"active_id": self.id})
16+
.create(
17+
{
18+
"wa_template_id": self.env.company.wa_sale_template_id.id,
19+
"res_model": "estate.property",
20+
}
21+
)
22+
)
23+
whatsapp_composer.sudo()._send_whatsapp_template(force_send_by_cron=True)
24+
25+
else:
26+
return super().action_change_state()

estate_whatsapp/models/res_company.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
from odoo import models, fields
3+
4+
5+
class ResCompany(models.Model):
6+
_inherit = "res.company"
7+
8+
wa_sale_template_id = fields.Many2one('whatsapp.template',string='WhatsApp Template', domain=[('model', '=', 'estate.property'), ('status', '=', 'approved')])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from odoo import fields, models
2+
3+
4+
class ResConfigSettings(models.TransientModel):
5+
_inherit = "res.config.settings"
6+
7+
# def _default_company(self):
8+
# return self.env['res.company'].company_id, limit=1)
9+
10+
company_id = fields.Many2one(
11+
'res.company',
12+
string="company",
13+
ondelete='cascade')
14+
wa_sale_template_id = fields.Many2one(related='company_id.wa_sale_template_id', readonly=False, store=True)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<data>
4+
<menuitem id="estate_property_whatsapp" name="Configuration" parent="estate.estate_property_root">
5+
<menuitem id="estate_property_configuration_menu_action" action="estate_whatsapp_model_action"/>
6+
</menuitem>
7+
</data>
8+
</odoo>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="estate_whatsapp_model_action" model="ir.actions.act_window">
4+
<field name="name">Settings</field>
5+
<field name="path">whatsapp_settings</field>
6+
<field name="res_model">res.config.settings</field>
7+
<field name="view_mode">form</field>
8+
<field name="target">inline</field>
9+
<field name="context">{'module' : 'estate_whatsapp', 'bin_size': False}</field>
10+
</record>
11+
<record id="res_config_settings_view_form" model="ir.ui.view">
12+
<field name="name">res.config.settings.view.form.inherit.estate</field>
13+
<field name="model">res.config.settings</field>
14+
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
15+
<field name="arch" type="xml">
16+
<xpath expr="//form" position="inside">
17+
<app data-string="Estate" string="Estate" name="estate_whatsapp">
18+
<div id="Whatsapp template">
19+
<block title="Templates" name="template_setting_container">
20+
<div class="mt16">
21+
<label for="wa_sale_template_id" class="o_light_label mr8"/>
22+
<field name="wa_sale_template_id" class="oe_inline"/>
23+
</div>
24+
</block>
25+
</div>
26+
</app>
27+
</xpath>
28+
</field>
29+
</record>
30+
</odoo>

0 commit comments

Comments
 (0)