diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 28 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_tax.py | 22 | ||||
| -rw-r--r-- | indoteknik_custom/models/promotion/promotion_program_line.py | 23 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 8 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 48 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/promotion_program_line.py | 5 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/promotion/promotion_program_line.xml | 5 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 2 |
13 files changed, 137 insertions, 14 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: diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index b225c687..3d700ce0 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -126,4 +126,5 @@ 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 from . import approval_unreserve diff --git a/indoteknik_custom/models/account_tax.py b/indoteknik_custom/models/account_tax.py new file mode 100644 index 00000000..e39546f2 --- /dev/null +++ b/indoteknik_custom/models/account_tax.py @@ -0,0 +1,22 @@ +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 + + 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 diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index a57f1f2c..7a15ad11 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -34,6 +34,29 @@ 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) + + tiers = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] + + for index, tier in enumerate(tiers, start=1): + + price_tier_data = product._get_pricelist_tier(tier) + + price_field = f'price_tier_{index}' + + 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') diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index 68fb796e..e5b35d7f 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -23,6 +23,13 @@ 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') + + 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): @@ -111,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 diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d7b24b34..d0a34007 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -132,6 +132,54 @@ class SaleOrder(models.Model): 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 action_estimate_shipping(self): + total_weight = 0 + missing_weight_products = [] + + # Menghitung total berat dari Sale Order Line + for line in self.order_line: + if line.weight: + total_weight += line.weight * line.product_uom_qty + line.product_id.weight = line.weight + else: + missing_weight_products.append(line.product_id.name) + + # Menampilkan pesan jika ada produk tanpa berat + if missing_weight_products: + self.message_post(body="Warning: Beberapa produk tidak memiliki berat: %s" % ', '.join(missing_weight_products)) + + if total_weight == 0: + raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") + + # Panggil API Raja Ongkir untuk mendapatkan estimasi ongkir + result = self._call_rajaongkir_api(total_weight) + if result: + estimated_cost = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['value'] + # Memasukkan hasil estimasi ke field delivery_amt + self.delivery_amt = estimated_cost + self.message_post(body=f"Estimasi Ongkos Kirim: {estimated_cost}") + else: + raise UserError("Gagal mendapatkan estimasi ongkir.") + + def _call_rajaongkir_api(self, total_weight): + url = 'https://pro.rajaongkir.com/api/cost' + headers = { + 'key': '7ac9883688da043b50cc32f0e3070bb6', + } + courier = self.carrier_id.name.lower() + origin = self.partner_shipping_id.city_id.state_id.code + destination = self.partner_shipping_id.city_id.state_id.code + data = { + 'origin': origin, # Contoh ID kota asal (Yogyakarta) + 'destination': destination, # Contoh ID kota tujuan (Jakarta) + 'weight': int(total_weight * 1000), # Menggunakan berat dalam gram + 'courier': courier, + } + response = requests.post(url, headers=headers, data=data) + if response.status_code == 200: + return response.json() + return None def _compute_type_promotion(self): for rec in self: diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 50438dbe..0ea6a2cc 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -31,6 +31,7 @@ class SaleOrderLine(models.Model): qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') reserved_from = fields.Char(string='Reserved From', copy=False) item_percent_margin_without_deduction = fields.Float('%Margin', compute='_compute_item_margin_without_deduction') + weight = fields.Float(string='Weight') @api.constrains('note_procurement') def note_procurement_to_apo(self): @@ -244,6 +245,7 @@ class SaleOrderLine(models.Model): # query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') price, taxes, vendor_id = self._get_purchase_price(line.product_id) line.vendor_id = vendor_id + line.weight = line.product_id.weight line.tax_id = line.order_id.sales_tax_id # price, taxes = line._get_valid_purchase_price(purchase_price) line.purchase_price = price 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/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d81f4634..19e3bdca 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -135,5 +135,6 @@ 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 access_approval_unreserve,access.approval.unreserve,model_approval_unreserve,,1,1,1,1 access_approval_unreserve_line,access.approval.unreserve.line,model_approval_unreserve_line,,1,1,1,1 diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index f3c2eea1..9cda67a8 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -32,6 +32,11 @@ <field name="package_limit_user" /> <field name="package_limit_trx" /> <field name="price" attrs="{'invisible': [('promotion_type', '=', 'special_price')]}" /> + <field name="price_tier_1"/> + <field name="price_tier_2" invisible="1"/> + <field name="price_tier_3" invisible="1"/> + <field name="price_tier_4" invisible="1"/> + <field name="price_tier_5" invisible="1"/> <field name="sequence"/> <field name="discount_type" attrs="{'invisible': [('promotion_type', '!=', 'special_price')]}" /> <field name="discount_amount" attrs="{'invisible': [('promotion_type', '!=', 'special_price')]}" /> 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 @@ <field name="approval_status"/> </field> <field name="approval_status" position="after"> - <field name="revisi_po" invisible="1"/> + <field name="revisi_po"/> </field> <field name="incoterm_id" position="after"> <field name="amount_total_without_service"/> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 3b8a7d1f..17faaa95 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -85,6 +85,7 @@ string="Override Create Invoice" type="object" /> + <button string="Estimate Shipping" type="object" name="action_estimate_shipping"/> </field> <field name="partner_shipping_id" position="after"> <field name="real_shipping_id"/> @@ -131,6 +132,7 @@ <field name="note" optional="hide"/> <field name="note_procurement" optional="hide"/> <field name="vendor_subtotal" optional="hide"/> + <field name="weight" optional="hide"/> <field name="amount_voucher_disc" string="Voucher" readonly="1" optional="hide"/> <field name="order_promotion_id" string="Promotion" readonly="1" optional="hide"/> </xpath> |
