Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Sale UX block ip @ create sale order
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import website | ||
from . import sale_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
ip_address = fields.Char('ip_address', index=True, copy=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from odoo import fields, models | ||
from odoo.http import request | ||
from odoo.exceptions import UserError | ||
|
||
from datetime import datetime, timedelta | ||
|
||
class Website(models.Model): | ||
_inherit = 'website' | ||
|
||
def _prepare_sale_order_values(self, partner, pricelist): | ||
|
||
values = super()._prepare_sale_order_values(partner, pricelist) | ||
ban_duration = int(self.env['ir.config_parameter'].sudo().get_param('website.order_banned_minutes', '30')) | ||
|
||
values['ip_address'] = request.httprequest.environ['REMOTE_ADDR'] | ||
from_time =datetime.now() - timedelta(minutes=ban_duration) | ||
block_count = self.env['website.block_ip'].sudo().search_count([ | ||
('name', '=', values['ip_address']), | ||
('create_date', '>', from_time), | ||
]) | ||
|
||
if block_count > 0: | ||
raise UserError('Your Order blocked') | ||
|
||
|
||
ban_duration = int(self.env['ir.config_parameter'].sudo().get_param('website.order_banned_after', '3')) | ||
|
||
from_time = datetime.now() - timedelta(seconds=60) | ||
order_count = self.env['sale.order'].sudo().search_count([ | ||
('ip_address', '=', values['ip_address']), | ||
('create_date', '>', from_time), | ||
]) | ||
if order_count >= 3: | ||
self.env['website.block_ip'].sudo().create({'name': values['ip_address']}) | ||
self._cr.commit() | ||
raise UserError('Demasiadas ordenes creadas') | ||
|
||
return values | ||
|
||
|
||
class WebsiteBlockIP(models.Model): | ||
|
||
_name = 'website.block_ip' | ||
_description = 'blocked ips' | ||
|
||
name = fields.Char('Ip', index=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"id","name","model_id/id","group_id/id","perm_read","perm_write","perm_create","perm_unlink" | ||
"website_sale_ux.block_ips","Block ips","website_sale_ux.model_website_block_ip","website.group_website_designer","True","True","True","True" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="website_block_ip_view_tree" model="ir.ui.view"> | ||
<field name="name">website.block_ip.view.tree</field> | ||
<field name="model">website.block_ip</field> | ||
<field name="arch" type="xml"> | ||
<tree string=""> | ||
<field name="create_date"/> | ||
<field name="name"/> | ||
</tree> | ||
</field> | ||
</record> | ||
<record id="websit_block_ip_view_search" model="ir.ui.view"> | ||
<field name="name">website.block_ip.view.search</field> | ||
<field name="model">website.block_ip</field> | ||
<field name="arch" type="xml"> | ||
<search string=""> | ||
<field name="name"/> | ||
<filter name="create_date" string="by date" context="{'group_by': 'create_date:hour'}" /> | ||
</search> | ||
</field> | ||
</record> | ||
<record id="website_block_ip_action" model="ir.actions.act_window"> | ||
<field name="name">Action Name</field> | ||
<field name="res_model">website.block_ip</field> | ||
<field name="view_mode">tree</field> | ||
<field name="domain">[]</field> | ||
<field name="context">{}</field> | ||
<field name="help" type="html"> | ||
<p>no blocked ips</p> | ||
</field> | ||
</record> | ||
<menuitem | ||
id="block_ips_menu" | ||
name="Block ips" | ||
action="website_sale_ux.website_block_ip_action" | ||
parent="website_sale.menu_ecommerce_settings" | ||
sequence="90"/> | ||
</odoo> |