From 95a65f3a543ca628b16acd5bc5e28d50e7cbe24c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 19 Sep 2024 09:16:11 +0700 Subject: push --- indoteknik_custom/models/sale_order.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index bd0fb75e..1e9d3992 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -430,10 +430,22 @@ class SaleOrder(models.Model): # return [('id', 'not in', order_ids)] # return ['&', ('order_line.invoice_lines.move_id.move_type', 'in', ('out_invoice', 'out_refund')), ('order_line.invoice_lines.move_id', operator, value)] - @api.onchange('partner_shipping_id') - def onchange_partner_shipping(self): - self.real_shipping_id = self.partner_shipping_id - self.real_invoice_id = self.partner_invoice_id + + def check_data_real_delivery_address(self): + real_delivery_address = self.real_shipping_id + + if not real_delivery_address.state_id: + raise UserError('State Real Delivery Address harus diisi') + if not real_delivery_address.zip: + raise UserError('Zip code Real Delivery Address harus diisi') + if not real_delivery_address.mobile: + raise UserError('Mobile Real Delivery Address harus diisi') + if not real_delivery_address.phone: + raise UserError('Phone Real Delivery Address harus diisi') + if not real_delivery_address.kecamatan_id: + raise UserError('Kecamatan Real Delivery Address harus diisi') + if not real_delivery_address.kelurahan_id: + raise UserError('Kelurahan Real Delivery Address harus diisi') @api.onchange('partner_id') def onchange_partner_contact(self): @@ -658,6 +670,7 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: + order.check_data_real_delivery_address() order.sale_order_check_approve() order._validate_order() order.order_line.validate_line() -- cgit v1.2.3 From fb3ed255759edcbe8dfbdcedf0fb1f803aae2e4f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 23 Sep 2024 15:31:38 +0700 Subject: cr sale order --- indoteknik_custom/models/sale_order.py | 1 - 1 file changed, 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 86b3d50d..610d5126 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -670,7 +670,6 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: - order.check_data_real_delivery_address() order.sale_order_check_approve() order._validate_order() order.order_line.validate_line() -- cgit v1.2.3 From 649f3037e4357dab42d1a8d799e5f2a2f1fd2e52 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 23 Sep 2024 16:03:38 +0700 Subject: add tracking --- indoteknik_custom/models/sale_order.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 610d5126..3a28bc54 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -38,14 +38,14 @@ class SaleOrder(models.Model): have_outstanding_po = fields.Boolean('Have Outstanding PO', compute='_have_outstanding_po') purchase_ids = fields.Many2many('purchase.order', string='Purchases', compute='_get_purchases') real_shipping_id = fields.Many2one( - 'res.partner', string='Real Delivery Address', readonly=True, required=True, + 'res.partner', string='Real Delivery Address', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)], 'sale': [('readonly', False)]}, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", - help="Dipakai untuk alamat tempel") + help="Dipakai untuk alamat tempel", tracking=True) real_invoice_id = fields.Many2one( 'res.partner', string='Delivery Invoice Address', required=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", - help="Dipakai untuk alamat tempel") + help="Dipakai untuk alamat tempel", tracking=True) fee_third_party = fields.Float('Fee Pihak Ketiga') so_status = fields.Selection([ ('terproses', 'Terproses'), @@ -116,6 +116,21 @@ class SaleOrder(models.Model): percent_margin_after_delivery_purchase = fields.Float(string='% Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') purchase_delivery_amt = fields.Float(string='Purchase Delivery Amount', compute='_compute_purchase_delivery_amount') type_promotion = fields.Char(string='Type Promotion', compute='_compute_type_promotion') + partner_invoice_id = fields.Many2one( + 'res.partner', string='Invoice Address', + readonly=True, required=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)], 'sale': [('readonly', False)]}, + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", + tracking=True, # Menambahkan tracking=True + ) + partner_shipping_id = fields.Many2one( + 'res.partner', string='Delivery Address', readonly=True, required=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)], 'sale': [('readonly', False)]}, + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=True) + + payment_term_id = fields.Many2one( + 'account.payment.term', string='Payment Terms', check_company=True, # Unrequired company + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=True) def _compute_type_promotion(self): for rec in self: @@ -687,6 +702,9 @@ class SaleOrder(models.Model): if not order.commitment_date and order.create_date > datetime(2024, 9, 12): raise UserError("Expected Delivery Date kosong, wajib diisi") + if not order.real_shipping_id: + UserError('Real Delivery Address harus di isi') + if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') -- cgit v1.2.3 From 733b749bb4979e0488b02da48b4116774945d6b5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 24 Sep 2024 15:54:12 +0700 Subject: add validation while create tax --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/account_tax.py | 14 ++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 1 + 3 files changed, 16 insertions(+) create mode 100644 indoteknik_custom/models/account_tax.py diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index ad7b1d09..4619147a 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -126,3 +126,4 @@ from . import sale_order_multi_uangmuka_penjualan from . import shipment_group from . import sales_order_reject from . import approval_date_doc +from . import account_tax diff --git a/indoteknik_custom/models/account_tax.py b/indoteknik_custom/models/account_tax.py new file mode 100644 index 00000000..e698d5ec --- /dev/null +++ b/indoteknik_custom/models/account_tax.py @@ -0,0 +1,14 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError + +class AccountTax(models.Model): + _inherit = 'account.tax' + + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_it').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya IT yang bisa membuat tax') + result = super(AccountTax, self).create(vals) + return result \ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 09dbb45e..61ced26c 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -135,3 +135,4 @@ access_shipment_group,access.shipment.group,model_shipment_group,,1,1,1,1 access_shipment_group_line,access.shipment.group.line,model_shipment_group_line,,1,1,1,1 access_sales_order_reject,access.sales.order.reject,model_sales_order_reject,,1,1,1,1 access_approval_date_doc,access.approval.date.doc,model_approval_date_doc,,1,1,1,1 +access_account_tax,access.account.tax,model_account_tax,,1,1,1,1 -- cgit v1.2.3 From 6cfbf125b6154a2dc0fe3aec6f433b94584c91fe Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 24 Sep 2024 16:47:43 +0700 Subject: cr account tax --- indoteknik_custom/models/account_tax.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/indoteknik_custom/models/account_tax.py b/indoteknik_custom/models/account_tax.py index e698d5ec..e39546f2 100644 --- a/indoteknik_custom/models/account_tax.py +++ b/indoteknik_custom/models/account_tax.py @@ -11,4 +11,12 @@ class AccountTax(models.Model): if self.env.user.id not in users_in_group.mapped('id'): raise UserError('Hanya IT yang bisa membuat tax') result = super(AccountTax, self).create(vals) + return result + + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_it').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya IT yang bisa mengedit tax') + result = super(AccountTax, self).write(values) return result \ No newline at end of file -- cgit v1.2.3 From 8793cf3b8dea2c87024b4c9f49077cc8c6b982d8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 10:08:00 +0700 Subject: cr stock_total_f --- indoteknik_custom/models/solr/apache_solr.py | 6 +++--- indoteknik_custom/models/solr/product_product.py | 2 +- indoteknik_custom/models/solr/product_template.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 6560c9b5..f6b29cd8 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -70,7 +70,7 @@ class ApacheSolr(models.Model): stocks = self.env['stock.vendor'].search(query, limit=limit) documents = [] for stock in stocks: - stock_total = int(stock.product_variant_id.product_tmpl_id.qty_stock_vendor) + stock_total = int(stock.product_variant_id.product_tmpl_id.qty_available_bandengan) # dict_stock = dict({"set": stock_total}) document = { "id": int(stock.product_variant_id.product_tmpl_id.id), @@ -178,7 +178,7 @@ class ApacheSolr(models.Model): 'price_discount_f': price_excl_after_disc, 'tax_f': tax, 'variant_total_i': template.product_variant_count, - 'stock_total_f': template.qty_stock_vendor, + 'stock_total_f': template.qty_available_bandengan, 'weight_f': template.weight, 'manufacture_id_i': template.x_manufacture.id or 0, 'manufacture_name_s': template.x_manufacture.x_name or '', @@ -264,7 +264,7 @@ class ApacheSolr(models.Model): 'discount_f': discount, 'price_discount_f': price_excl_after_disc, 'tax_f': tax, - 'stock_total_f': variant.qty_stock_vendor, + 'stock_total_f': variant.qty_available_bandengan, 'weight_f': variant.product_tmpl_id.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 '', diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 35e3a4b3..6864041e 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -58,7 +58,7 @@ class ProductProduct(models.Model): 'product_id_i': variant.id, 'template_id_i': variant.product_tmpl_id.id, 'image_s': ir_attachment.api_image('product.template', 'image_512', variant.product_tmpl_id.id), - 'stock_total_f': variant.qty_stock_vendor, + 'stock_total_f': variant.qty_available_bandengan, '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 '', diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index d8dec47c..9cb27c5b 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -92,7 +92,7 @@ class ProductTemplate(models.Model): "product_id_i": template.id, "image_s": self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), "variant_total_i": template.product_variant_count, - "stock_total_f": template.qty_stock_vendor, + "stock_total_f": template.qty_available_bandengan, "weight_f": template.weight, "manufacture_id_i": template.x_manufacture.id or 0, "manufacture_name_s": template.x_manufacture.x_name or '', -- cgit v1.2.3 From 41b8281f9e01d675d0078bbe131e41acc9a8c15a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 10:36:21 +0700 Subject: fix error --- indoteknik_custom/models/solr/apache_solr.py | 4 ++-- indoteknik_custom/models/solr/product_template.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index f6b29cd8..f04b5e84 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -70,7 +70,7 @@ class ApacheSolr(models.Model): stocks = self.env['stock.vendor'].search(query, limit=limit) documents = [] for stock in stocks: - stock_total = int(stock.product_variant_id.product_tmpl_id.qty_available_bandengan) + stock_total = int(stock.product_variant_id.product_tmpl_id.qty_stock_vendor) # dict_stock = dict({"set": stock_total}) document = { "id": int(stock.product_variant_id.product_tmpl_id.id), @@ -178,7 +178,7 @@ class ApacheSolr(models.Model): 'price_discount_f': price_excl_after_disc, 'tax_f': tax, 'variant_total_i': template.product_variant_count, - 'stock_total_f': template.qty_available_bandengan, + 'stock_total_f': template.qty_stock_vendor, 'weight_f': template.weight, 'manufacture_id_i': template.x_manufacture.id or 0, 'manufacture_name_s': template.x_manufacture.x_name or '', diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 9cb27c5b..d8dec47c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -92,7 +92,7 @@ class ProductTemplate(models.Model): "product_id_i": template.id, "image_s": self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), "variant_total_i": template.product_variant_count, - "stock_total_f": template.qty_available_bandengan, + "stock_total_f": template.qty_stock_vendor, "weight_f": template.weight, "manufacture_id_i": template.x_manufacture.id or 0, "manufacture_name_s": template.x_manufacture.x_name or '', -- cgit v1.2.3 From 30efa28bf211ffefc181551df026047143939b4f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 11:32:20 +0700 Subject: solr fix --- indoteknik_custom/models/solr/apache_solr.py | 2 +- indoteknik_custom/models/solr/product_product.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index f04b5e84..6560c9b5 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -264,7 +264,7 @@ class ApacheSolr(models.Model): 'discount_f': discount, 'price_discount_f': price_excl_after_disc, 'tax_f': tax, - 'stock_total_f': variant.qty_available_bandengan, + 'stock_total_f': variant.qty_stock_vendor, 'weight_f': variant.product_tmpl_id.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 '', diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 6864041e..35e3a4b3 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -58,7 +58,7 @@ class ProductProduct(models.Model): 'product_id_i': variant.id, 'template_id_i': variant.product_tmpl_id.id, 'image_s': ir_attachment.api_image('product.template', 'image_512', variant.product_tmpl_id.id), - 'stock_total_f': variant.qty_available_bandengan, + 'stock_total_f': variant.qty_stock_vendor, '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 '', -- cgit v1.2.3 From 6c7c80b9cf3f4146af1fcfc4c9b24881a7b29b3c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 14:39:16 +0700 Subject: add price_tier to program line --- .../models/promotion/promotion_program_line.py | 22 ++++++++++++++++++++++ indoteknik_custom/models/purchase_pricelist.py | 8 ++++++++ indoteknik_custom/models/solr/product_template.py | 4 ++-- .../models/solr/promotion_program_line.py | 5 +++++ .../views/promotion/promotion_program_line.xml | 5 +++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index a57f1f2c..903e95cf 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -34,6 +34,28 @@ class PromotionProgramLine(models.Model): active = fields.Boolean(string="Active", default=True) solr_flag = fields.Integer(string="Solr Flag", default=1) description = fields.Char('Description') + price_tier_1 = fields.Float('Price Tier 1') + price_tier_2 = fields.Float('Price Tier 2') + price_tier_3 = fields.Float('Price Tier 3') + price_tier_4 = fields.Float('Price Tier 4') + price_tier_5 = fields.Float('Price Tier 5') + + def get_price_tier(self, product_id, qty): + product = self.env['product.product'].browse(product_id.id) # Get the product record + + tiers = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] + + for index, tier in enumerate(tiers, start=1): # Automatically count from 1 to 5 + # Call the function _get_pricelist_tier from product.product model + price_tier_data = product._get_pricelist_tier(tier) + + # Use the index as the tier number (1, 2, 3, etc.) + price_field = f'price_tier_{index}' # 'price_tier_1', 'price_tier_2', etc. + + # Update the corresponding price_tier_X field + if price_field in self._fields: # Ensure the field exists in the model + price = price_tier_data.get(f'price_tier{tier}', 0) * qty # Multiply by qty + self[price_field] = price def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index 68fb796e..b5f719cb 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -23,6 +23,14 @@ class PurchasePricelist(models.Model): brand_id = fields.Many2one('x_manufactures', string='Brand') count_brand_vendor = fields.Integer(string='Count Brand Vendor') is_winner = fields.Boolean(string='Winner', default=False, help='Pemenang yang direkomendasikan oleh Merchandise') + + @api.constrains('include_price') + def sync_pricelist_tier(self): + for rec in self: + promotion_product = self.env['promotion.product'].search([('product_id', '=', rec.product_id.id)]) + + for promotion in promotion_product: + promotion.program_line_id.get_price_tier(promotion.product_id, promotion.qty) @api.depends('product_id', 'vendor_id') def _compute_name(self): diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index d8dec47c..1eb6f31b 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -112,8 +112,8 @@ class ProductTemplate(models.Model): "description_clean_t": cleaned_desc or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, - 'sni_b': template.unpublished, - 'tkdn_b': template.unpublished, + 'sni_b': template.sni, + 'tkdn_b': template.tkdn, "qty_sold_f": template.qty_sold, "is_in_bu_b": is_in_bu, "voucher_min_purchase_f" : voucher.min_purchase_amount or 0, diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 3e3a2a28..64ad4209 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -53,6 +53,11 @@ class PromotionProgramLine(models.Model): 'package_limit_user_i': rec.package_limit_user, 'package_limit_trx_i': rec.package_limit_trx, 'price_f': rec.price, + 'price_tier_1_f': rec.price_tier_1, + 'price_tier_2_f': rec.price_tier_2, + 'price_tier_3_f': rec.price_tier_3, + 'price_tier_4_f': rec.price_tier_4, + 'price_tier_5_f': rec.price_tier_5, 'sequence_i': sequence_value, 'product_ids': [x.product_id.id for x in rec.product_ids], 'products_s': json.dumps(products), diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index f3c2eea1..b4dd2254 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -32,6 +32,11 @@ + + + + + -- cgit v1.2.3 From ce4715289f52a5a1b39fdecc8bda40fbf88308a9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 25 Sep 2024 16:14:58 +0700 Subject: program line cr --- .../models/promotion/promotion_program_line.py | 17 +++++++++-------- .../views/promotion/promotion_program_line.xml | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 903e95cf..7a15ad11 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -41,22 +41,23 @@ class PromotionProgramLine(models.Model): price_tier_5 = fields.Float('Price Tier 5') def get_price_tier(self, product_id, qty): - product = self.env['product.product'].browse(product_id.id) # Get the product record + product = self.env['product.product'].browse(product_id.id) tiers = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] - for index, tier in enumerate(tiers, start=1): # Automatically count from 1 to 5 - # Call the function _get_pricelist_tier from product.product model + for index, tier in enumerate(tiers, start=1): + price_tier_data = product._get_pricelist_tier(tier) - # Use the index as the tier number (1, 2, 3, etc.) - price_field = f'price_tier_{index}' # 'price_tier_1', 'price_tier_2', etc. + price_field = f'price_tier_{index}' - # Update the corresponding price_tier_X field - if price_field in self._fields: # Ensure the field exists in the model - price = price_tier_data.get(f'price_tier{tier}', 0) * qty # Multiply by qty + if price_field in self._fields: + price = price_tier_data.get(f'price_tier{tier}', 0) * qty self[price_field] = price + if index == 1: + self.price = price + def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') return self.search([ diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index b4dd2254..9cda67a8 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -32,7 +32,7 @@ - + -- cgit v1.2.3 From 2638a9fbfe29520e5be0b88810208f5232aaac7b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 26 Sep 2024 10:10:25 +0700 Subject: cr purchase pricelist --- indoteknik_custom/models/purchase_pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index b5f719cb..e5b35d7f 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -24,7 +24,6 @@ class PurchasePricelist(models.Model): count_brand_vendor = fields.Integer(string='Count Brand Vendor') is_winner = fields.Boolean(string='Winner', default=False, help='Pemenang yang direkomendasikan oleh Merchandise') - @api.constrains('include_price') def sync_pricelist_tier(self): for rec in self: promotion_product = self.env['promotion.product'].search([('product_id', '=', rec.product_id.id)]) @@ -119,5 +118,6 @@ class PurchasePricelist(models.Model): tier_prod_pricelist = self.env['product.pricelist.item'].search(product_domain + [('pricelist_id', '=', tier_pricelist.id)], limit=1) tier_prod_pricelist.price_discount = tier_perc + rec.sync_pricelist_tier() rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') \ No newline at end of file -- cgit v1.2.3 From b920f203ac689497d117f5a5c4def44f87f85bc7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 26 Sep 2024 11:28:11 +0700 Subject: cr api register --- indoteknik_api/controllers/api_v1/user.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 7166bd79..f4fffc0e 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -157,20 +157,26 @@ class User(controller.Controller): user.partner_id.email = email user.partner_id.mobile = phone - if type_acc == 'business': - parameter = [ - ('company_type', '=', 'company'), - ('name', 'ilike', business_name) - ] - match_company = request.env['res.partner'].search(parameter, limit=1) - match_ratio = 0 - if match_company: - match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio() - if match_ratio > 0.8: + if type_acc == 'business' and business_name: + # Eksekusi query SQL menggunakan Levenshtein distance + query = """ + SELECT name, levenshtein(name::text, %s) AS distance + FROM res_partner + WHERE levenshtein(name::text, %s) < 3 + ORDER BY distance ASC + """ + params = (business_name, business_name) + request.env.cr.execute(query, params) + result = request.env.cr.fetchone() + + if result: + match_company_name = result[0] + match_company_id = result[2] + # Create a user company request request.env['user.company.request'].create({ 'user_id': user.partner_id.id, - 'user_company_id': match_company.id, + 'user_company_id': match_company_id, 'user_input': business_name }) else: -- cgit v1.2.3 From 0d1bf664d93ff02a42b1962fcf034690b105b8a9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 26 Sep 2024 15:22:07 +0700 Subject: cr revisi po --- indoteknik_custom/views/purchase_order.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 0ef0aa7f..f6e5a1a4 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -36,7 +36,7 @@ - + -- cgit v1.2.3