summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-07 16:45:26 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-07 16:45:26 +0700
commitfd6af0fbd83042c8471c3c58ff459f52bed45938 (patch)
tree6347ce189fddfb37e2ab0d0c14751075ba2ca870
parentdd8f35133c24f84896a90dda343978d893ce5c4c (diff)
parent6290e0e7a935c5084459843f8ba345ab9528d44c (diff)
Merge branch 'master' of bitbucket.org:altafixco/indoteknik-addons
-rwxr-xr-xindoteknik_custom/models/product_template.py68
-rwxr-xr-xindoteknik_custom/views/product_template.xml11
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
3 files changed, 77 insertions, 4 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index c1761f08..a51f0600 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1,4 +1,5 @@
-from odoo import fields, models
+from odoo import fields, models, api
+from datetime import datetime, timedelta
class ProductTemplate(models.Model):
@@ -22,19 +23,80 @@ class ProductTemplate(models.Model):
digits='Product Price', inverse='_set_product_lst_price',
help="Web Price with pricelist_id = 1")
qty_stock_vendor = fields.Float('QTY Stock Vendor', compute='_compute_qty_stock_vendor')
-
+ have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?")
+ product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website")
+ last_calculate_rating = fields.Datetime("Last Calculate Rating")
+ web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku')
+
def _compute_qty_stock_vendor(self):
for product_template in self:
product_template.qty_stock_vendor = 0
for product_variant in product_template.product_variant_ids:
product_template.qty_stock_vendor += product_variant.qty_stock_vendor
-
+
def _compute_web_price(self):
for template in self:
product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)],limit=1)
product_pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 1),('product_id', '=', product.id)],limit=1)
template.web_price = product_pricelist_item.fixed_price
+ def _have_promotion_program(self):
+ for template in self:
+ domain = [
+ ('rule_products_domain', 'ilike', template.x_manufacture.x_name),
+ ('active', '=', True)
+ ]
+ coupon_program = self.env['coupon.program'].search(domain, limit=1)
+ if coupon_program:
+ template.have_promotion_program = True
+ else:
+ template.have_promotion_program = False
+
+ @api.model
+ def _calculate_rating_product(self):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=30)
+
+ current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+
+ products = self.env['product.template'].search([
+ ('type', '=', 'product'),
+ ('active', '=', True),
+ ('last_calculate_rating', '!=', False),
+ ], limit=5000)
+ for product in products:
+ print("Calculate Rating Product ", product)
+ rate = 0
+ if product.web_price:
+ rate += 1
+ product.web_price_sorting = product.web_price
+ if product.have_promotion_program:
+ rate += 1
+ if product.image_128:
+ rate += 1
+ product.product_rating = rate
+ product.last_calculate_rating = current_time
+
+ products = self.env['product.template'].search([
+ ('type', '=', 'product'),
+ ('active', '=', True),
+ ('last_calculate_rating', '<', delta_time),
+ ], limit=5000)
+ for product in products:
+ print("Calculate Rating Product OutOfDate", product)
+ rate = 0
+ if product.web_price:
+ rate += 1
+ product.web_price_sorting = product.web_price
+ if product.have_promotion_program:
+ rate += 1
+ if product.image_128:
+ rate += 1
+ product.product_rating = rate
+ product.last_calculate_rating = current_time
+
+
class ProductProduct(models.Model):
_inherit = "product.product"
web_price = fields.Float(
diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml
index 78aac34a..d4fa8d57 100755
--- a/indoteknik_custom/views/product_template.xml
+++ b/indoteknik_custom/views/product_template.xml
@@ -36,5 +36,16 @@
</xpath>
</field>
</record>
+ <record id="product_template_product_form_inherit" model="ir.ui.view">
+ <field name="name">Product Template</field>
+ <field name="model">product.template</field>
+ <field name="inherit_id" ref="website_sale.product_template_form_view"/>
+ <field name="arch" type="xml">
+ <field name="website_ribbon_id" position="after">
+ <field name="last_calculate_rating" attrs="{'readonly': [('type', '=', 'product')]}"/>
+ <field name="product_rating" attrs="{'readonly': [('type', '=', 'product')]}"/>
+ </field>
+ </field>
+ </record>
</data>
</odoo> \ No newline at end of file
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index f83b2a6b..47f9b4a4 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -25,7 +25,7 @@
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_total']" position="after">
<field name="vendor_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
<field name="purchase_price" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
- <field name="purchase_tax_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}"/>
+ <field name="purchase_tax_id" attrs="{'readonly': [('parent.state', 'not in', ['draft', 'sent', 'sale'])]}" domain="[('type_tax_use','=','purchase')]"/>
<field name="item_percent_margin"/>
</xpath>
<field name="amount_total" position="after">