summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-10-20 10:17:52 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-10-20 10:17:52 +0700
commitd4be2f65948da27992841f99ffe1ff04b4de0194 (patch)
treee35365b0c47dd5646b8e0033fc2aa74fe835f4a0
parent956a77b7ad29af3620ee37e66c3b13de6a562deb (diff)
parent1e08cea66f4b4b3e4664f09986b1e41d0ba57830 (diff)
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py7
-rw-r--r--indoteknik_api/controllers/api_v1/category.py2
-rw-r--r--indoteknik_api/controllers/api_v1/product.py2
-rw-r--r--indoteknik_custom/models/account_move.py5
-rwxr-xr-xindoteknik_custom/models/purchase_order.py12
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py1
-rw-r--r--indoteknik_custom/models/solr/product_product.py58
-rw-r--r--indoteknik_custom/models/solr/product_template.py87
-rw-r--r--indoteknik_custom/models/stock_picking.py2
-rw-r--r--indoteknik_custom/models/website_user_cart.py9
-rw-r--r--indoteknik_custom/views/account_move.xml8
-rwxr-xr-xindoteknik_custom/views/purchase_order.xml1
-rw-r--r--indoteknik_custom/views/stock_picking.xml1
13 files changed, 105 insertions, 90 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py
index 88fa9f88..8ef2c1c1 100644
--- a/indoteknik_api/controllers/api_v1/cart.py
+++ b/indoteknik_api/controllers/api_v1/cart.py
@@ -14,8 +14,9 @@ class Cart(controller.Controller):
user_id = int(user_id)
limit = int(kw.get('limit', 0))
offset = int(kw.get('offset', 0))
- query = [('user_id', '=', user_id), ('source', '=', 'add_to_cart')]
+ query = [('user_id', '=', user_id)]
carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc')
+ carts.write({'source': 'add_to_cart'})
data = {
'product_total': user_cart.search_count(query),
'products': carts.with_context(price_for="web").get_products()
@@ -26,7 +27,7 @@ class Cart(controller.Controller):
@controller.Controller.must_authorized()
def get_cart_count_by_user_id(self, user_id, **kw):
user_id = int(user_id)
- query = [('user_id', '=', user_id), ('source', '=', 'add_to_cart')]
+ query = [('user_id', '=', user_id)]
carts = request.env['website.user.cart'].search_count(query)
return self.response(carts)
@@ -77,7 +78,7 @@ class Cart(controller.Controller):
data_to_update['source'] = source
result = {}
- if cart and source in (None, 'add_to_cart'):
+ if cart:
# Update existing cart entry
cart.write(data_to_update)
result['id'] = cart.id
diff --git a/indoteknik_api/controllers/api_v1/category.py b/indoteknik_api/controllers/api_v1/category.py
index efa6b033..44a60bc9 100644
--- a/indoteknik_api/controllers/api_v1/category.py
+++ b/indoteknik_api/controllers/api_v1/category.py
@@ -135,4 +135,4 @@ class Category(controller.Controller):
category = category.parent_frontend_id
categories.reverse()
- return self.response(categories) \ No newline at end of file
+ return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')]) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 0c8a286b..1b698f26 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -32,7 +32,7 @@ class Product(controller.Controller):
category = category.parent_frontend_id
categories.reverse()
- return self.response(categories)
+ return self.response(categories, headers=[('Cache-Control', 'max-age=3600, public')])
@http.route(prefix + 'product_variant/<id>/stock', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index 207ccee1..a85e8caa 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -14,6 +14,7 @@ _logger = logging.getLogger(__name__)
class AccountMove(models.Model):
_inherit = 'account.move'
invoice_day_to_due = fields.Integer(string="Day to Due", compute="_compute_invoice_day_to_due")
+ bill_day_to_due = fields.Date(string="Day to Due", compute="_compute_bill_day_to_due")
date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak")
last_log_fp = fields.Char(string="Log Terakhir Faktur Pajak")
# use for industry business
@@ -107,6 +108,10 @@ class AccountMove(models.Model):
invoice_day_to_due = invoice.new_due_date - date.today()
invoice_day_to_due = invoice_day_to_due.days
invoice.invoice_day_to_due = invoice_day_to_due
+
+ def _compute_bill_day_to_due(self):
+ for rec in self:
+ rec.bill_day_to_due = rec.payment_schedule or rec.invoice_date_due
@api.onchange('date_kirim_tukar_faktur')
def change_date_kirim_tukar_faktur(self):
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 5e4617d4..e8cd86fa 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -56,6 +56,14 @@ class PurchaseOrder(models.Model):
def add_product_to_pricelist(self):
for line in self.order_line:
current_time = datetime.utcnow()
+ price_unit = line.price_unit
+ taxes = line.taxes_id
+ for tax in taxes:
+ tax_include = tax.price_include
+ tax_amt = tax.amount
+ if taxes:
+ if not tax_include:
+ price_unit = price_unit + (price_unit * tax_amt / 100)
purchase_pricelist = self.env['purchase.pricelist'].search([
('product_id', '=', line.product_id.id),
@@ -67,7 +75,7 @@ class PurchaseOrder(models.Model):
'vendor_id': line.order_id.partner_id.id,
'product_id': line.product_id.id,
'product_price': 0.00,
- 'system_price': line.price_unit,
+ 'system_price': price_unit,
'system_last_update': current_time,
}])
return True
@@ -75,7 +83,7 @@ class PurchaseOrder(models.Model):
for pricelist in purchase_pricelist:
pricelist.write({
'system_last_update': current_time,
- 'system_price': line.price_unit
+ 'system_price': price_unit
})
def _compute_date_planned(self):
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index 95e85122..2e91bb69 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -30,6 +30,7 @@ class PurchaseOrderLine(models.Model):
suggest = fields.Char(string='Suggest')
price_vendor = fields.Float(string='Price Vendor', compute='compute_price_vendor')
so_line_id = fields.Many2one('sale.order.line', string='ID SO Line')
+ indent = fields.Boolean(string='Indent', help='centang ini jika barang indent')
def compute_price_vendor(self):
for line in self:
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 720be7fa..e1342fc2 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -1,4 +1,4 @@
-from odoo import models, fields
+from odoo import models, fields, api
from datetime import datetime
@@ -63,7 +63,7 @@ class ProductProduct(models.Model):
'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly,
'attributes': [x.name for x in variant.product_template_attribute_value_ids],
'has_product_info_b': True,
- 'publish_b': variant.product_tmpl_id.active and variant.product_tmpl_id.type == 'product',
+ 'publish_b': variant.active and variant.type == 'product',
'qty_sold_f': variant.qty_sold
})
@@ -75,24 +75,12 @@ class ProductProduct(models.Model):
def _sync_price_to_solr(self):
solr_model = self.env['apache.solr']
+ TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']
for variant in self:
- price_excl_after_disc = price_excl = discount = tax = 0
- flashsale_data = {}
+ flashsale_data = variant.with_context(price_for="web")._get_flashsale_price()
- if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc:
- price_excl = variant._get_website_price_exclude_tax()
- price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
- tax = variant._get_website_tax()
- discount = variant._get_website_disc(0)
- flashsale_data = variant.with_context(price_for="web")._get_flashsale_price()
-
- price_excl_v2 = variant._v2_get_website_price_exclude_tax()
- price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax()
- tax_v2 = variant._v2_get_website_tax()
-
- document = solr_model.get_doc('variants', variant.id)
- document.update({
+ flashsale_doc = {
"id": variant.id,
"flashsale_id_i": flashsale_data.get('flashsale_id', 0),
"flashsale_tag_s": flashsale_data.get('flashsale_tag', ''),
@@ -102,25 +90,19 @@ class ProductProduct(models.Model):
"flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0),
"flashsale_discount_f": flashsale_data.get('flashsale_discount', 0),
"flashsale_price_f": flashsale_data.get('flashsale_price', 0),
- "price_f": price_excl,
- "discount_f": discount,
- "price_discount_f": price_excl_after_disc,
- "tax_f": tax,
- "price_v2_f": price_excl_v2,
- "price_discount_v2_f": price_excl_after_disc_v2,
- "tax_v2_f": tax_v2,
- })
-
- for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
+ }
+
+ price_doc = {}
+
+ for tier_number in TIER_NUMBERS:
tier = variant._get_pricelist_tier(tier_number)
- document.update({
- f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0),
- f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0),
- })
-
- # for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
- # tier = tier_data[tier_number]
+ price_doc[f"discount_tier{tier_number}_f"] = tier.get(f'discount_tier{tier_number}', 0)
+ price_doc[f"price_tier{tier_number}_f"] = tier.get(f'price_tier{tier_number}', 0)
+ document = solr_model.get_doc('variants', variant.id)
+ document['id'] = variant.id
+ document.update(flashsale_doc)
+ document.update(price_doc)
document.update({"has_price_info_b": True})
self.solr().add(docs=[document], softCommit=True)
@@ -186,4 +168,10 @@ class ProductProduct(models.Model):
results.append(result)
- return results \ No newline at end of file
+ return results
+
+ @api.constrains('active')
+ def constrains_active(self):
+ for rec in self:
+ rec.product_tmpl_id._create_solr_queue_sync_product_template()
+ \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index cc8d4bf2..aa1708cc 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -97,56 +97,52 @@ class ProductTemplate(models.Model):
def _sync_price_to_solr(self):
solr_model = self.env['apache.solr']
+ TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']
for template in self:
- flashsale_data = {}
- price_excl = price_excl_after_disc = discount = tax = 0
- tier_data = {}
+ cheapest_flashsale = {}
for variant in template.product_variant_ids:
variant_flashsale = variant.with_context(price_for="web")._get_flashsale_price()
variant_flashsale_price = variant_flashsale.get('flashsale_price', 0)
- flashsale_data_price = flashsale_data.get('flashsale_price', 0)
-
- if flashsale_data_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < flashsale_data_price):
- flashsale_data = variant_flashsale
-
- price_excl = variant._get_website_price_exclude_tax()
- price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
- discount = variant._get_website_disc(0)
- tax = variant._get_website_tax()
-
- price_excl_v2 = variant._v2_get_website_price_exclude_tax()
- price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax()
- tax_v2 = variant._v2_get_website_tax()
-
+ cheapest_flashsale_price = cheapest_flashsale.get('flashsale_price', 0)
+
+ if cheapest_flashsale_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < cheapest_flashsale_price):
+ cheapest_flashsale = variant_flashsale
+
+ flashsale_doc = {
+ "flashsale_id_i": cheapest_flashsale.get('flashsale_id', 0),
+ "flashsale_tag_s": cheapest_flashsale.get('flashsale_tag', ''),
+ "flashsale_name_s": cheapest_flashsale.get('flashsale_name', ''),
+ "flashsale_start_date_s": cheapest_flashsale.get('flashsale_start_date', ''),
+ "flashsale_end_date_s": cheapest_flashsale.get('flashsale_end_date', ''),
+ "flashsale_base_price_f": cheapest_flashsale.get('flashsale_base_price', 0),
+ "flashsale_discount_f": cheapest_flashsale.get('flashsale_discount', 0),
+ "flashsale_price_f": cheapest_flashsale.get('flashsale_price', 0)
+ }
+
+ price_doc = {}
+
+ # Loop tier to get each variant price
+ for tier_number in TIER_NUMBERS:
+ for variant in template.product_variant_ids:
+ tier = variant._get_pricelist_tier(tier_number)
+ discount_tier_key = f'discount_tier{tier_number}'
+ price_tier_key = f'price_tier{tier_number}'
+
+ variant_discount = tier.get(discount_tier_key, 0)
+ variant_price = tier.get(price_tier_key, 0)
+
+ price_tier = price_doc.get(f"{price_tier_key}_f", 0)
+ # When price tier is 0 or variant_price less than price tier then use variant price
+ if price_tier == 0 or variant_price < price_tier:
+ price_doc[f"{discount_tier_key}_f"] = variant_discount
+ price_doc[f"{price_tier_key}_f"] = variant_price
+
document = solr_model.get_doc('product', template.id)
- document.update({
- "id": template.id,
- "flashsale_id_i": flashsale_data.get('flashsale_id', 0),
- "flashsale_tag_s": flashsale_data.get('flashsale_tag', ''),
- "flashsale_name_s": flashsale_data.get('flashsale_name', ''),
- "flashsale_start_date_s": flashsale_data.get('flashsale_start_date', ''),
- "flashsale_end_date_s": flashsale_data.get('flashsale_end_date', ''),
- "flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0),
- "flashsale_discount_f": flashsale_data.get('flashsale_discount', 0),
- "flashsale_price_f": flashsale_data.get('flashsale_price', 0),
- "price_f": price_excl,
- "discount_f": discount,
- "price_discount_f": price_excl_after_disc,
- "tax_f": tax,
- "price_v2_f": price_excl_v2,
- "price_discount_v2_f": price_excl_after_disc_v2,
- "tax_v2_f": tax_v2,
- })
-
- for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
- tier = variant._get_pricelist_tier(tier_number)
- document.update({
- f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0),
- f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0),
- })
-
+ document['id'] = template.id
+ document.update(flashsale_doc)
+ document.update(price_doc)
document.update({"has_price_info_b": True})
self.solr().add(docs=[document], softCommit=True)
@@ -221,3 +217,8 @@ class ProductTemplate(models.Model):
results.append(result)
return results
+
+ @api.constrains('active')
+ def constrains_active(self):
+ for rec in self:
+ rec._create_solr_queue_sync_product_template() \ No newline at end of file
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 418649b1..626e842d 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -69,7 +69,7 @@ class StockPicking(models.Model):
('hold', 'Hold by Sales'),
('not_paid', 'Customer belum bayar'),
('partial', 'Kirim Parsial')
- ], string='Note', help='jika field ini diisi maka tidak akan dihitung ke lead time')
+ ], string='Note Logistic', help='jika field ini diisi maka tidak akan dihitung ke lead time')
waybill_id = fields.One2many(comodel_name='airway.bill', inverse_name='do_id', string='Airway Bill')
purchase_representative_id = fields.Many2one('res.users', related='move_lines.purchase_line_id.order_id.user_id', string="Purchase Representative", readonly=True)
carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method')
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 47a695fe..bbc14c88 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -55,11 +55,15 @@ class WebsiteUserCart(models.Model):
def get_product_by_user(self, user_id, selected=False, source=False):
user_id = int(user_id)
- source = source if source else 'add_to_cart'
+
+ if source == 'buy':
+ source = ['buy']
+ else:
+ source = ['add_to_cart', 'buy']
parameters = [
('user_id', '=', user_id),
- ('source', '=', source)
+ ('source', 'in', source)
]
if selected:
@@ -91,6 +95,7 @@ class WebsiteUserCart(models.Model):
tax = round(subtotal * 0.11)
grand_total = subtotal + tax
total_weight = sum(x['weight'] * x['quantity'] for x in products)
+ total_weight = round(total_weight, 2)
result = {
'total_purchase': total_purchase,
'total_discount': total_discount,
diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml
index 2aeffc83..1721abb6 100644
--- a/indoteknik_custom/views/account_move.xml
+++ b/indoteknik_custom/views/account_move.xml
@@ -73,8 +73,12 @@
<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 name="invoice_date_due" position="after">
+ <field name="bill_day_to_due" string="Due Date" widget="remaining_days"/>
+ </field>
+
+ <field name="invoice_date_due" position="attributes">
+ <attribute name="invisible">1</attribute>
</field>
</field>
</record>
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index 1ff14e60..7bf14899 100755
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -65,6 +65,7 @@
</field>
<field name="price_subtotal" position="after">
<field name="so_line_id" attrs="{'readonly': 1}" optional="hide"/>
+ <field name="indent" optional="hide"/>
</field>
<page name="purchase_delivery_invoice" position="after">
<page name="purchase_vendor_bills" string="Vendor Bills" groups="indoteknik_custom.technical_administrator">
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
index 9f03235d..3702dcf8 100644
--- a/indoteknik_custom/views/stock_picking.xml
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -15,6 +15,7 @@
<field name="driver_departure_date" optional="hide"/>
<field name="driver_arrival_date" optional="hide"/>
<field name="note_logistic" optional="hide"/>
+ <field name="note" optional="hide"/>
</field>
<field name="partner_id" position="after">
<field name="purchase_representative_id"/>