Browse Source

Jan 02 [UPDT] : Updated 'website_seo_kit'

pull/309/head
AjmalCybro 4 months ago
parent
commit
9c41f79182
  1. 2
      website_seo_kit/__manifest__.py
  2. 39
      website_seo_kit/models/generate_seo.py

2
website_seo_kit/__manifest__.py

@ -21,7 +21,7 @@
############################################################################ ############################################################################
{ {
'name': "Website SEO Kit", 'name': "Website SEO Kit",
'version': '17.0.1.0.0', 'version': '17.0.1.0.1',
'summary': """This module help to generate seo content""", 'summary': """This module help to generate seo content""",
'description': """Website seo kit used for automatically generate meta titles, 'description': """Website seo kit used for automatically generate meta titles,
descriptions, and keywords for each product and product category""", descriptions, and keywords for each product and product category""",

39
website_seo_kit/models/generate_seo.py

@ -19,6 +19,8 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################ ############################################################################
import re
from odoo import api, fields, models from odoo import api, fields, models
@ -67,10 +69,11 @@ class GenerateSeo(models.Model):
[('models', '=', 'product_category')])] [('models', '=', 'product_category')])]
def action_save_seo_info(self): def action_save_seo_info(self):
"""Save the seo content""" """Save the SEO content"""
self.state = 'activated' self.state = 'activated'
for record in self.search([('id', '!=', self.id)]): for record in self.search([('id', '!=', self.id)]):
record.state = 'deactivated' record.state = 'deactivated'
if self.model_name == 'product': if self.model_name == 'product':
if self.meta_title_ids: if self.meta_title_ids:
products = self.env['product.template'].search_read( products = self.env['product.template'].search_read(
@ -79,9 +82,8 @@ class GenerateSeo(models.Model):
for product in products: for product in products:
sep = self.attribute_separator sep = self.attribute_separator
string = str(sep).join( string = str(sep).join(
str(product[x]) for x in product.keys() if x != 'id') str(product[x]) for x in product.keys() if x != 'id'
string = string.translate({ )
ord(i): None for i in "<p>(),'</p>"})
values = { values = {
'string': string, 'string': string,
'id': product['id'] 'id': product['id']
@ -99,9 +101,8 @@ class GenerateSeo(models.Model):
for product in products: for product in products:
sep = self.attribute_separator sep = self.attribute_separator
string = str(sep).join( string = str(sep).join(
str(product[x]) for x in product.keys() if x != 'id') str(product[x]) for x in product.keys() if x != 'id'
string = string.translate( )
{ord(i): None for i in "<p>(),'</p>"})
values = { values = {
'string': string, 'string': string,
'id': product['id'] 'id': product['id']
@ -116,12 +117,10 @@ class GenerateSeo(models.Model):
'tag': 'display_notification', 'tag': 'display_notification',
'target': 'new', 'target': 'new',
'params': { 'params': {
'message': ("Successfully " 'message': "Successfully generated the SEO for all products",
"generated the seo for all products"),
'type': 'success', 'type': 'success',
'sticky': False, 'sticky': False,
'next': {'type': 'ir.actions.act_window_close'}, 'next': {'type': 'ir.actions.act_window_close'},
} }
} }
@ -134,15 +133,13 @@ class GenerateSeo(models.Model):
for product in products: for product in products:
sep = self.attribute_separator sep = self.attribute_separator
string = str(sep).join( string = str(sep).join(
str(product[x]) for x in product.keys() if x != 'id') str(product[x]) for x in product.keys() if x != 'id'
string = string.translate( )
{ord(i): None for i in "<p>(),'</p>"})
values = { values = {
'string': string, 'string': string,
'id': product['id'] 'id': product['id']
} }
pro = self.env['product.public.category'].browse( pro = self.env['product.public.category'].browse(values['id'])
values['id'])
for rec in pro: for rec in pro:
rec.write({ rec.write({
'website_meta_title': values['string'], 'website_meta_title': values['string'],
@ -157,15 +154,13 @@ class GenerateSeo(models.Model):
for product in products: for product in products:
sep = self.attribute_separator sep = self.attribute_separator
string = str(sep).join( string = str(sep).join(
str(product[x]) for x in product.keys() if x != 'id') str(product[x]) for x in product.keys() if x != 'id'
string = string.translate( )
{ord(i): None for i in "<p>(),'</p>"})
values = { values = {
'string': string, 'string': string,
'id': product['id'] 'id': product['id']
} }
pro = self.env[ pro = self.env['product.public.category'].browse(values['id'])
'product.public.category'].browse(values['id'])
pro.write({ pro.write({
'website_meta_description': values['string'], 'website_meta_description': values['string'],
}) })
@ -175,9 +170,7 @@ class GenerateSeo(models.Model):
'tag': 'display_notification', 'tag': 'display_notification',
'target': 'new', 'target': 'new',
'params': { 'params': {
'message': 'message': "Successfully created the SEO only for product groups with auto SEO enabled.",
("Successfully created the SEO only for product"
" groups with auto SEO enabled."),
'type': 'success', 'type': 'success',
'sticky': False, 'sticky': False,
'next': {'type': 'ir.actions.act_window_close'}, 'next': {'type': 'ir.actions.act_window_close'},

Loading…
Cancel
Save