summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-12 11:02:57 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-12 11:02:57 +0700
commit8b3d929a7cae089ac12d9752d3f97793dbe084d5 (patch)
tree236f442c309560222940f15b7b6a42e05f6d2b80
parent19bbd3203d41d9f52206d7ceaa96480a19566197 (diff)
add new product rest api
-rw-r--r--indoteknik_api/controllers/api_v1/product.py25
-rwxr-xr-xindoteknik_custom/models/x_manufactures.py2
-rwxr-xr-xindoteknik_custom/views/x_manufactures.xml16
3 files changed, 40 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 2e978679..28a63ed5 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -6,7 +6,30 @@ import ast
class Product(controller.Controller):
prefix = '/api/v1/'
-
+
+ @http.route(prefix + 'new_product', auth='public', methods=['GET', 'OPTIONS'])
+ def get_new_product(self):
+ if not self.authenticate():
+ return self.response(code=401, description='Unauthorized')
+ base_url = request.env['ir.config_parameter'].get_param('web.base.url')
+ query = [('show_as_new_product', '=', True)]
+ brands = request.env['x_manufactures'].search(query, order='sequence')
+ data = []
+ for brand in brands:
+ query_products = [
+ ('is_new_product', '=', True),
+ ('x_manufacture', '=', brand.id),
+ ]
+ products = request.env['product.template'].search(query_products, order='name')
+ data.append({
+ 'manufacture_id': brand.id,
+ 'sequence': brand.sequence,
+ 'name': brand.x_name,
+ 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '',
+ 'products': [request.env['product.template'].api_single_response(x) for x in products]
+ })
+ return self.response(data)
+
@http.route(prefix + 'product', auth='public', methods=['GET', 'OPTIONS'])
def get_product(self, **kw):
if not self.authenticate():
diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py
index 1d215cf8..e6842797 100755
--- a/indoteknik_custom/models/x_manufactures.py
+++ b/indoteknik_custom/models/x_manufactures.py
@@ -42,6 +42,8 @@ class XManufactures(models.Model):
('reset', 'Reset'),
('done', 'Done')
], string="Cache Reset")
+ sequence = fields.Integer(string='Sequence', help='Urutan tampil di homepage jika show as new product')
+ show_as_new_product = fields.Boolean(string='Show as New Product', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru')
def cache_reset(self):
manufactures = self.env['x_manufactures'].search([
diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml
index d122c6c1..c7cedd9c 100755
--- a/indoteknik_custom/views/x_manufactures.xml
+++ b/indoteknik_custom/views/x_manufactures.xml
@@ -16,13 +16,14 @@
<field name="model">x_manufactures</field>
<field name="arch" type="xml">
<tree>
- <field name="id"/>
<field name="x_name"/>
<field name="x_negara_asal"/>
<field name="x_short_desc"/>
<field name="x_manufacture_level"/>
<field name="x_manufacture_service_center"/>
<field name="cache_reset_status"/>
+ <field name="show_as_new_product"/>
+ <field name="sequence"/>
</tree>
</field>
</record>
@@ -42,6 +43,8 @@
<field name="x_manufacture_level"/>
<field name="x_produk_aksesoris_sparepart"/>
<field name="cache_reset_status"/>
+ <field name="show_as_new_product"/>
+ <field name="sequence"/>
</group>
<group>
<field name="x_logo_manufacture" widget="image"/>
@@ -54,7 +57,16 @@
<field name="x_description"/>
</page>
<page string="Relasi Produk">
- <field name="x_manufacture_product"/>
+ <field name="x_manufacture_product" widget="section_and_note_one2many" mode="tree,kanban">
+ <tree string="Products" editable="bottom">
+ <field name="default_code"/>
+ <field name="name"/>
+ <field name="create_date"/>
+ <field name="solr_flag"/>
+ <field name="product_rating"/>
+ <field name="is_new_product"/>
+ </tree>
+ </field>
</page>
<page string="Relasi Banner">
<field name="x_manufactures_banners"/>