diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-22 14:49:25 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-22 14:49:25 +0700 |
| commit | da0a75bc6b7166e297bcaf175c15089e95dbbf2e (patch) | |
| tree | 156cfb319848cd2b2964f83b3cb185e8f920f7b2 | |
| parent | 6850fd6f86a0fbba3156e59f9ac5836052f019ce (diff) | |
| parent | 0face879a802bf1a15d1065d59db64f723b4e8d3 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
15 files changed, 121 insertions, 37 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 907c8288..5948a277 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -52,6 +52,9 @@ class Cart(controller.Controller): if not user_id: return self.response(code=400, description='user_id is required') + if not product_id and not program_line_id: + return self.response(code=400, description='product_id or program_line_id is required') + website_user_cart = request.env['website.user.cart'] # Remove previous 'buy' entries for the user @@ -68,32 +71,33 @@ class Cart(controller.Controller): cart = website_user_cart.search(query, limit=1) data_to_update = { + 'user_id': user_id, 'qty': qty, 'is_selected': is_selected, 'program_line_id': program_line_id, - 'product_id': product_id + 'product_id': product_id, + 'source': source or False } - if program_line_id: - data_to_update['product_id'] = False - - if source: - data_to_update['source'] = source - - result = {} if cart: - # Update existing cart entry cart.write(data_to_update) - result['id'] = cart.id else: - # Create a new cart entry if it doesn't exist - create = website_user_cart.create({ - 'user_id': user_id, - **data_to_update - }) - result['id'] = create.id + cart = website_user_cart.create(data_to_update) - return self.response(result) + return self.response({ + 'id': cart.id, + 'product': { + 'id': cart.product_id.id, + 'name': cart.product_id.name + } if cart.product_id else None, + 'program_line': { + 'id': cart.program_line_id.id, + 'name': cart.program_line_id.name + } if cart.program_line_id else None, + 'qty': cart.qty, + 'is_selected': cart.is_selected, + 'source': cart.source + }) @http.route(PREFIX_USER + 'cart', auth='public', methods=['DELETE', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 3c056ecd..53f118ec 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -1,31 +1,39 @@ -from .. import controller +from bs4 import BeautifulSoup from odoo import http from odoo.http import request -from bs4 import BeautifulSoup + +from .. import controller class Voucher(controller.Controller): - prefix = '/api/v1/' + PREFIX_API = '/api/v1/' + + @http.route(PREFIX_API + 'voucher', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_vouchers(self, **kw): + vouchers = request.env['voucher'].get_active_voucher([('visibility', 'in', ['public'])]) + vouchers = vouchers.res_format() + return self.response(vouchers) - @http.route(prefix + 'user/<user_id>/voucher', auth='public', methods=['GET', 'OPTIONS']) + @http.route(PREFIX_API + 'user/<user_id>/voucher', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized(private=True, private_key='user_id') - def get_vouchers(self, **kw): + def get_vouchers_by_user_id(self, **kw): cart = request.env['website.user.cart'] code = kw.get('code') user_id = int(kw.get('user_id', 0)) source = kw.get('source') visibility = ['public'] - parameter = [] + domain = [] if code: visibility.append('private') - parameter += [('code', '=', code)] + domain += [('code', '=', code)] user_pricelist = request.env.context.get('user_pricelist') if user_pricelist: - parameter += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] + domain += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] - parameter += [('visibility', 'in', visibility)] - vouchers = request.env['voucher'].get_active_voucher(parameter) + domain += [('visibility', 'in', visibility)] + vouchers = request.env['voucher'].get_active_voucher(domain) checkout = cart.get_user_checkout(user_id, source=source) products = checkout['products'] @@ -35,6 +43,7 @@ class Voucher(controller.Controller): order_line = [] for product in products: + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': request.env['product.product'].browse(product['id']), 'price': product['price']['price'], diff --git a/indoteknik_api/models/product_pricelist.py b/indoteknik_api/models/product_pricelist.py index f05fa82d..0d4247c8 100644 --- a/indoteknik_api/models/product_pricelist.py +++ b/indoteknik_api/models/product_pricelist.py @@ -92,7 +92,7 @@ class ProductPricelist(models.Model): ('is_flash_sale', '=', True), ('start_date', '<=', current_time), ('end_date', '>=', current_time) - ], limit=1) + ], limit=1, order='start_date asc') return pricelist def is_flash_sale_product(self, product_id: int): diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index c2170579..1f1c2138 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -77,6 +77,7 @@ 'views/brand_vendor.xml', 'views/promotion/promotion_program.xml', 'views/promotion/promotion_program_line.xml', + 'views/promotion/promotion_product.xml', 'views/requisition.xml', 'views/landedcost.xml', 'views/product_sla.xml', diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index a9db212f..7eb65e9f 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -122,7 +122,7 @@ class AccountMove(models.Model): sum_qty_invoice = sum_qty_order = 0 for line in purchase_order.order_line: sum_qty_invoice += line.qty_invoiced - sum_qty_order += line.product_uom_qty + sum_qty_order += line.product_qty if sum_qty_invoice > sum_qty_order: raise UserError('Error Qty Invoice akan lebih besar dari Qty Order jika lanjut Posting') diff --git a/indoteknik_custom/models/promotion/promotion_free_product.py b/indoteknik_custom/models/promotion/promotion_free_product.py index c5055562..e91d5137 100644 --- a/indoteknik_custom/models/promotion/promotion_free_product.py +++ b/indoteknik_custom/models/promotion/promotion_free_product.py @@ -17,6 +17,10 @@ class PromotionFreeProduct(models.Model): weight = rec.product_id.weight or 0 result.append({ 'id': rec.product_id.id, + 'parent': { + 'id': rec.product_id.product_tmpl_id.id, + 'name': rec.product_id.product_tmpl_id.name, + }, 'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id), 'display_name': rec.product_id.display_name, 'name': rec.product_id.name, diff --git a/indoteknik_custom/models/promotion/promotion_product.py b/indoteknik_custom/models/promotion/promotion_product.py index 2fad0f0d..ae26e888 100644 --- a/indoteknik_custom/models/promotion/promotion_product.py +++ b/indoteknik_custom/models/promotion/promotion_product.py @@ -17,6 +17,10 @@ class PromotionProduct(models.Model): weight = rec.product_id.weight or 0 result.append({ 'id': rec.product_id.id, + 'parent': { + 'id': rec.product_id.product_tmpl_id.id, + 'name': rec.product_id.product_tmpl_id.name, + }, 'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id), 'display_name': rec.product_id.display_name, 'name': rec.product_id.name, diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 18a7e184..ce46d2e7 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -30,6 +30,7 @@ class PromotionProgramLine(models.Model): discount_amount = fields.Float('Discount Amount') order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions') + active = fields.Boolean(default=True) def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') @@ -74,6 +75,9 @@ class PromotionProgramLine(models.Model): } def _get_remaining_time(self): + if not self.program_id.end_time: + return 0 + calculate_time = self.program_id.end_time - datetime.now() return round(calculate_time.total_seconds()) @@ -93,9 +97,7 @@ class PromotionProgramLine(models.Model): free_products = self.free_product_ids.formats(purchase_qty=qty) merged_products = products + free_products - weight = 0 - if not any(x['package_weight'] == 0 for x in merged_products): - weight = sum(x['package_weight'] for x in merged_products) + weight = sum(x['package_weight'] for x in merged_products) # Sum of products and free products in 1 package quantity products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in products) diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py index 07274295..02ad5bb8 100644 --- a/indoteknik_custom/models/solr/apache_solr_queue.py +++ b/indoteknik_custom/models/solr/apache_solr_queue.py @@ -18,6 +18,7 @@ class ApacheSolrQueue(models.Model): ('not_found', 'Record not found') ], 'Execute Status') execute_date = fields.Datetime('Execute Date') + description = fields.Text('Description') def _compute_display_name(self): for rec in self: @@ -38,6 +39,16 @@ class ApacheSolrQueue(models.Model): if elapsed_time > max_exec_time: break rec.execute_queue() + + def open_target_record(self): + return { + 'name': '', + 'view_mode': 'form', + 'res_model': self.res_model, + 'target': 'current', + 'type': 'ir.actions.act_window', + 'res_id': self.res_id + } def execute_queue(self): for rec in self: @@ -57,7 +68,8 @@ class ApacheSolrQueue(models.Model): rec.execute_status = 'success' else: rec.execute_status = 'not_found' - except: + except Exception as e: + rec.description = e rec.execute_status = 'failed' rec.execute_date = datetime.utcnow() self.env.cr.commit() diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 5a74df8c..c14f6b98 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -59,7 +59,7 @@ class ProductProduct(models.Model): 'template_id_i': variant.product_tmpl_id.id, 'image_s': ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id), 'stock_total_f': variant.qty_stock_vendor, - 'weight_f': variant.product_tmpl_id.weight, + 'weight_f': variant.weight, 'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0, 'manufacture_name_s': variant.product_tmpl_id.x_manufacture.x_name or '', 'manufacture_name': variant.product_tmpl_id.x_manufacture.x_name or '', diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 6e182324..30ce16c9 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -39,9 +39,8 @@ class PromotionProgramLine(models.Model): document.update({ 'id': rec.id, - 'program_id_i': rec.program_id.id, + 'program_id_i': rec.program_id.id or 0, 'name_s': rec.name, - 'image_s': self.env['ir.attachment'].api_image(self._name, 'image', rec.id) if rec.image else '', 'type_value_s': promotion_type['value'], 'type_label_s': promotion_type['label'], 'package_limit_i': rec.package_limit, @@ -53,6 +52,7 @@ class PromotionProgramLine(models.Model): 'free_product_ids': [x.product_id.id for x in rec.free_product_ids], 'free_products_s': json.dumps(free_products), 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), + 'active': rec.active }) self.solr().add([document]) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 4f167b6d..e302cc5a 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -52,7 +52,7 @@ access_procurement_monitoring_detail,access.procurement.monitoring.detail,model_ access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1 access_brand_vendor,access.brand.vendor,model_brand_vendor,,1,1,1,1 access_promotion_program,access.promotion.program,model_promotion_program,,1,1,1,1 -access_promotion_program_line,access.promotion.program.line,model_promotion_program_line,,1,1,1,1 +access_promotion_program_line,access.promotion.program.line,model_promotion_program_line,,1,1,1,0 access_promotion_product,access.promotion.product,model_promotion_product,,1,1,1,1 access_promotion_free_product,access.promotion.free_product,model_promotion_free_product,,1,1,1,1 access_promotion_keyword,access.promotion.keyword,model_promotion_keyword,,1,1,1,1 diff --git a/indoteknik_custom/views/apache_solr_queue.xml b/indoteknik_custom/views/apache_solr_queue.xml index 13869b4c..7577e569 100644 --- a/indoteknik_custom/views/apache_solr_queue.xml +++ b/indoteknik_custom/views/apache_solr_queue.xml @@ -4,6 +4,8 @@ <field name="model">apache.solr.queue</field> <field name="arch" type="xml"> <tree editable="top" default_order="create_date desc"> + <button type="object" name="open_target_record" class="fa fa-external-link" /> + <field name="id" readonly="1" /> <field name="display_name" readonly="1" /> <field name="res_model" readonly="1" /> <field name="res_id" readonly="1" /> diff --git a/indoteknik_custom/views/promotion/promotion_product.xml b/indoteknik_custom/views/promotion/promotion_product.xml new file mode 100644 index 00000000..eac42a45 --- /dev/null +++ b/indoteknik_custom/views/promotion/promotion_product.xml @@ -0,0 +1,45 @@ +<odoo> + <record id="promotion_product_tree" model="ir.ui.view"> + <field name="name">Promotion Product Tree</field> + <field name="model">promotion.product</field> + <field name="arch" type="xml"> + <tree> + <field name="product_id" /> + <field name="qty" /> + </tree> + </field> + </record> + + <record id="promotion_product_form" model="ir.ui.view"> + <field name="name">Promotion Product Form</field> + <field name="model">promotion.product</field> + <field name="arch" type="xml"> + <form> + <sheet> + <group> + <group> + <field name="program_line_id" /> + <field name="product_id" /> + <field name="qty" /> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <record id="promotion_product_action" model="ir.actions.act_window"> + <field name="name">Promotion Product</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">promotion.product</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem + id="menu_promotion_product" + name="Product" + parent="indoteknik_custom.menu_promotion_program_parent" + sequence="3" + action="promotion_product_action" + /> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index 346a08c9..280bdfba 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -21,6 +21,7 @@ <sheet> <group> <group> + <field name="program_id" /> <field name="name" /> <field name="promotion_type" /> </group> |
