summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-07-27 04:18:27 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-07-27 04:18:27 +0000
commite64105b97b5da3218e3dfbe5db4456b31f08ca73 (patch)
tree332eadffa49d97696aa53dc9c10bfd1cc0537e74
parent591617f043789ef66a76b7e97e6886b3412369e4 (diff)
parent421ff67560201e8155d03cbe4ff7029cd6b667a4 (diff)
Merged in production (pull request #74)
Production
-rw-r--r--indoteknik_api/controllers/api_v1/product.py21
-rw-r--r--indoteknik_api/models/product_product.py11
-rwxr-xr-xindoteknik_custom/models/product_template.py35
-rwxr-xr-xindoteknik_custom/models/sale_order.py3
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py39
-rw-r--r--indoteknik_custom/views/account_move.xml11
-rwxr-xr-xindoteknik_custom/views/sale_order.xml6
7 files changed, 82 insertions, 44 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 7ec6459b..e08ec97b 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -29,6 +29,12 @@ class Product(controller.Controller):
qty = 0
sla_date = '-'
+ # Qty Stock Vendor
+ qty_vendor = stock_vendor.quantity
+ qty_vendor -= int(qty_vendor * 0.1)
+ qty_vendor = math.ceil(float(qty_vendor))
+ total_excell = qty_vendor
+
is_altama_product = product.x_manufacture.id in [10,122,89]
if is_altama_product:
try:
@@ -37,11 +43,7 @@ class Product(controller.Controller):
qty_altama -= int(qty_altama * 0.1)
qty_altama = math.ceil(float(qty_altama))
total_adem = qty_altama
- # Qty Stock Vendor
- qty_vendor = stock_vendor.quantity
- qty_vendor -= int(qty_vendor * 0.1)
- qty_vendor = math.ceil(float(qty_vendor))
- total_excell = qty_vendor
+
if qty_available > 0:
qty = qty_available + total_adem + total_excell
sla_date = '1 Hari'
@@ -53,8 +55,13 @@ class Product(controller.Controller):
except:
print('error')
else:
- qty = qty_available
- sla_date = product_sla.sla or '-'
+ if qty_available > 0:
+ qty = qty_available
+ sla_date = product_sla.sla or '-'
+ elif qty_vendor > 0:
+ qty = total_excell
+ sla_date = '2-4 Hari'
+
data = {
'qty': qty,
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 334b58c5..fb485bae 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -31,6 +31,8 @@ class ProductProduct(models.Model):
def v2_api_single_response(self, product_product):
product_template = product_product.product_tmpl_id
+ stock = product_product.qty_stock_vendor
+ stock = 1 if stock == 0 else stock
data = {
'id': product_product.id,
'parent': {
@@ -41,7 +43,7 @@ class ProductProduct(models.Model):
'code': product_product.default_code or '',
'name': product_product.display_name,
'price': product_product.calculate_website_price(),
- 'stock': product_product.qty_stock_vendor,
+ 'stock': stock,
'weight': product_product.weight,
'attributes': [x.name for x in product_product.product_template_attribute_value_ids],
'manufacture' : self.api_manufacture(product_product)
@@ -82,6 +84,13 @@ class ProductProduct(models.Model):
if price[discount_key] > 0: discount_percentage = price[discount_key]
if price[price_key] > 0: price_discount = price[price_key]
+ flashsale = self._get_flashsale_price()
+ flashsale_price = flashsale['flashsale_price']
+ flashsale_discount = flashsale['flashsale_discount']
+ if flashsale_price > 0 and flashsale_price < price_discount:
+ price_discount = flashsale_price
+ discount_percentage = flashsale_discount
+
return {
'price': self._get_website_price_exclude_tax(),
'discount_percentage': discount_percentage,
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 7abdf1c1..933c4676 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -156,32 +156,35 @@ class ProductTemplate(models.Model):
template.have_promotion_program = False
@api.model
- def _calculate_rating_product(self):
- #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]]
+ def _calculate_rating_product(self, limit=1000, expiry_days=30, ids=False):
current_time = datetime.now()
- delta_time = current_time - timedelta(days=30)
+ current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S')
- current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
- delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = current_time - timedelta(days=expiry_days)
+ delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S')
- products = self.env['product.template'].search([
+ query = [
'&','&',
('type', '=', 'product'),
- ('active', '=', True),
- '|',
- ('last_calculate_rating', '=', False),
- ('last_calculate_rating', '<', delta_time),
- # ('id', '=', 22798),
- ], limit=500)
+ ('active', '=', True)
+ ]
+ if not ids:
+ query += [
+ '|',
+ ('last_calculate_rating', '=', False),
+ ('last_calculate_rating', '<', delta_time_str)
+ ]
+ else:
+ query += [('id', 'in', ids)]
+
+ products = self.env['product.template'].search(query, limit=limit)
for product in products:
- # print("Calculate Rating Product ", product)
_logger.info("Calculate Rating Product %s" % product.id)
- # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1)
rate = 0
if product.web_price:
rate += 1
- if product.have_promotion_program: #have discount from pricelist
+ if product.have_promotion_program:
rate += 1
if product.image_128:
rate += 5
@@ -190,7 +193,7 @@ class ProductTemplate(models.Model):
if product.product_variant_id.qty_stock_vendor > 0:
rate += 1
product.product_rating = rate
- product.last_calculate_rating = current_time
+ product.last_calculate_rating = current_time_str
def _get_stock_website(self):
qty = self._get_stock_altama()
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 552f1b0a..12043996 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -327,7 +327,6 @@ class SaleOrder(models.Model):
order.is_warning = False
def sale_order_approve(self):
- # raise UserError("Bisa langsung Confirm")
self.check_due()
for order in self:
@@ -357,6 +356,8 @@ class SaleOrder(models.Model):
if not order.carrier_id:
raise UserError("Shipping Method harus diisi")
for line in order.order_line:
+ if line.product_id.id == 385544:
+ raise UserError('Produk Sementara Tidak Bisa Di Confirm atau Ask Approval')
if not line.product_id or line.product_id.type == 'service':
continue
# must add product can sell validation
diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index ef801ca5..9630e3ab 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -130,15 +130,15 @@ class UserActivityLog(models.Model):
current_time = datetime.now()
delta_time = current_time - timedelta(days=7)
- # current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
activity_logs = self.env['user.activity.log'].search([
- ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
+ ('url', 'ilike', 'https://indoteknik.com%/shop/product/%'),
('create_date', '>', delta_time),
('url', 'not ilike', 'shopping'),
- ], limit=1000)
- for activity_log in activity_logs:
+ ], limit=2000, order='create_date DESC')
+
+ for activity_log in activity_logs:
_logger.info(activity_log.url)
strip_index = i = 0
for c in activity_log.url:
@@ -152,34 +152,37 @@ class UserActivityLog(models.Model):
if any(ch.isalpha() for ch in product_id):
continue
template = self.env['product.template'].search([
- ('id', '=', product_id)
+ ('id', '=', int(product_id))
], limit=1)
- template.search_rank_weekly = int(template.search_rank_weekly) + int(1)
- template.solr_flag = 2
+ if template:
+ template.search_rank_weekly += 1
+ template.solr_flag = 2
def update_rank_search(self):
activity_logs = self.env['user.activity.log'].search([
- ('url', 'ilike', '%/shop/product/%'),
- ('update_product', '=', False),
- # ('url', 'not ilike', '%/shop/product/%google-ads-shopping'),
- # ('id', '=', 211957)
- ], limit=1000)
+ ('url', 'ilike', '%/shop/product/%'),
+ ('update_product', '!=', True),
+ ], limit=1000, order='create_date DESC')
- for activity_log in activity_logs:
+ for activity_log in activity_logs:
_logger.info(activity_log.url)
strip_index = i = 0
for c in activity_log.url:
if c == '-':
strip_index = i
i += 1
- _logger.info(activity_log.url[strip_index+1:len(activity_log.url)])
- product_id = activity_log.url[strip_index+1:len(activity_log.url)]
+ _logger.info(activity_log.url[strip_index + 1:len(activity_log.url)])
+ product_id = activity_log.url[strip_index + 1:len(activity_log.url)]
if '#' in product_id:
continue
if any(ch.isalpha() for ch in product_id):
continue
template = self.env['product.template'].search([
- ('id', '=', product_id)
+ ('id', '=', int(product_id))
], limit=1)
- template.search_rank = int(template.search_rank) + int(1)
- activity_log.update_product = True
+ if template:
+ template.search_rank += 1
+ activity_log.update_product = True
+
+
+
diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml
index 26168561..11558bf4 100644
--- a/indoteknik_custom/views/account_move.xml
+++ b/indoteknik_custom/views/account_move.xml
@@ -59,6 +59,17 @@
</field>
</record>
+ <record id="account_move_in_invoice_tree_inherit" model="ir.ui.view">
+ <field name="name">Account Move</field>
+ <field name="model">account.move</field>
+ <field name="inherit_id" ref="account.view_in_invoice_tree"/>
+ <field name="arch" type="xml">
+ <field name="payment_state" position="after">
+ <field name="payment_schedule" optional="hide"/>
+ </field>
+ </field>
+ </record>
+
<record id="account_move_inherit_purchase_inherit" model="ir.ui.view">
<field name="name">Account Move</field>
<field name="model">account.move</field>
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 4570f43b..ae16f649 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -41,7 +41,7 @@
<field name="carrier_id" required="1"/>
<field name="delivery_service_type" readonly="1"/>
</field>
- <field name="source_id" position="after">
+ <field name="medium_id" position="after">
<field name="date_doc_kirim" readonly="1"/>
<field name="notification" readonly="1"/>
</field>
@@ -56,6 +56,10 @@
}
</attribute>
</xpath>
+ <field name="source_id" position="attributes">
+ <attribute name="domain">[('id', 'in', [32, 59, 60, 61])]</attribute>
+ <attribute name="required">1</attribute>
+ </field>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_total']" position="after">
<field name="vendor_id" attrs="{'readonly': [('parent.approval_status', '=', 'approved')]}"/>
<field name="purchase_price" attrs="