summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-10-24 17:07:43 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-10-24 17:07:43 +0700
commitda1ba5223456e4c39d11a5af67968dda6d569c6b (patch)
tree310eaa29f5982767e6685c2ca263f24fba72645e /indoteknik_api/models
parent646f9557c101bd6b8ed81fc46130e9761957b5c1 (diff)
parent1934b5ca55840deb2a4369ef6ab0affd86e2ba8f (diff)
Merge commit '1934b5ca55840deb2a4369ef6ab0affd86e2ba8f'
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/__init__.py1
-rw-r--r--indoteknik_api/models/blog_post.py44
-rw-r--r--indoteknik_api/models/product_template.py8
3 files changed, 49 insertions, 4 deletions
diff --git a/indoteknik_api/models/__init__.py b/indoteknik_api/models/__init__.py
index 06f1e1da..de2a2804 100644
--- a/indoteknik_api/models/__init__.py
+++ b/indoteknik_api/models/__init__.py
@@ -1,2 +1,3 @@
+from . import blog_post
from . import product_pricelist
from . import product_template
diff --git a/indoteknik_api/models/blog_post.py b/indoteknik_api/models/blog_post.py
new file mode 100644
index 00000000..2a82c23c
--- /dev/null
+++ b/indoteknik_api/models/blog_post.py
@@ -0,0 +1,44 @@
+from odoo import models
+from pytz import timezone
+
+
+class BlogPost(models.Model):
+ _inherit = 'blog.post'
+
+ def api_single_response(self, blog, with_detail=False):
+ base_url = self.env['ir.config_parameter'].get_param('web.base.url')
+ data = {
+ 'id': blog.id,
+ 'thumbnail': base_url + 'api/image/blog.post/thumbnail/' + str(blog.id) if blog.thumbnail else '',
+ 'title': blog.name,
+ 'category': {},
+ 'author': {},
+ 'post_date': blog.post_date.astimezone(timezone('Asia/Jakarta')).strftime('%d/%m/%Y') or '',
+ }
+ if blog.blog_id:
+ data['category'] = {
+ 'id': blog.blog_id.id,
+ 'name': blog.blog_id.name,
+ }
+ if blog.author_id:
+ data['author'] = {
+ 'id': blog.author_id.id,
+ 'name': blog.author_id.name
+ }
+ if with_detail:
+ data_with_detail = {
+ 'meta': {
+ 'title': blog.website_meta_title,
+ 'description': blog.website_meta_description,
+ 'keywords': blog.website_meta_keywords
+ },
+ 'tags': [],
+ 'content': blog.content,
+ }
+ for tag in blog.tag_ids:
+ data_with_detail['tags'].append({
+ 'id': tag.id,
+ 'name': tag.name,
+ })
+ data.update(data_with_detail)
+ return data \ No newline at end of file
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py
index 477be2f3..e99b2c2d 100644
--- a/indoteknik_api/models/product_template.py
+++ b/indoteknik_api/models/product_template.py
@@ -1,4 +1,4 @@
-from odoo import models, fields
+from odoo import models
class ProductTemplate(models.Model):
@@ -21,13 +21,13 @@ class ProductTemplate(models.Model):
'categories': self.api_categories(product_template),
}
if with_detail:
- detail_data = {
+ data_with_detail = {
'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '',
'variants': [],
'description': product_template.website_description or '',
}
for variant in product_template.product_variant_ids:
- detail_data['variants'].append({
+ data_with_detail['variants'].append({
'id': variant.id,
'code': variant.default_code or '',
'name': variant.display_name,
@@ -36,7 +36,7 @@ class ProductTemplate(models.Model):
'weight': variant.weight,
'attributes': [x.name for x in variant.product_template_attribute_value_ids]
})
- data.update(detail_data)
+ data.update(data_with_detail)
return data
def api_manufacture(self, product_template):