diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-03-13 09:56:13 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-03-13 09:56:13 +0700 |
| commit | 457cbc0114e0d340c2f210ddc853479284697987 (patch) | |
| tree | dd1c8a9426d212e80373eeef9345389b30571657 | |
| parent | 84a7a5fde0f5be9c24a5b324087b8726b1b8f01a (diff) | |
| parent | 1ff9a57e2f7a7ecb3ba9321f7133f43e7009aa47 (diff) | |
Merge branch 'odoo-backup' into CR/repeat-order
| -rw-r--r-- | indoteknik_api/controllers/api_v1/partner.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/commision.py | 15 | ||||
| -rw-r--r-- | indoteknik_custom/models/res_partner.py | 10 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 60 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_inventory.py | 26 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/customer_commision.xml | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 1 |
9 files changed, 96 insertions, 24 deletions
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py index ebd91210..126fded4 100644 --- a/indoteknik_api/controllers/api_v1/partner.py +++ b/indoteknik_api/controllers/api_v1/partner.py @@ -78,7 +78,7 @@ class Partner(controller.Controller): 'district_id': ['number', 'alias:kecamatan_id'], 'sub_district_id': ['number', 'alias:kelurahan_id', 'exclude_if_null'], 'zip': ['required'], - 'longitude': '', # Perbaikan dari longtitude ke longitude + 'longtitude': '', 'latitude': '', 'address_map': [], 'alamat_lengkap_text': [] diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index 6920154a..0d31e954 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -157,7 +157,22 @@ class CustomerCommision(models.Model): ('pending', 'Pending'), ('payment', 'Payment'), ], string='Payment Status', copy=False, readonly=True, tracking=3, default='pending') + grouped_so_number = fields.Char(string='Group SO Number', compute='_compute_grouped_numbers') + grouped_invoice_number = fields.Char(string='Group Invoice Number', compute='_compute_grouped_numbers') + def _compute_grouped_numbers(self): + for rec in self: + so_numbers = set() + invoice_numbers = set() + + for line in rec.commision_lines: + if line.invoice_id: + if line.invoice_id.sale_id: + so_numbers.add(line.invoice_id.sale_id.name) + invoice_numbers.add(line.invoice_id.name) + + rec.grouped_so_number = ', '.join(sorted(so_numbers)) + rec.grouped_invoice_number = ', '.join(sorted(invoice_numbers)) # add status for type of commision, fee, rebate / cashback # include child or not? diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index fe04535c..fd3a0514 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -127,8 +127,8 @@ class ResPartner(models.Model): ('PNR', 'Pareto Non Repeating'), ('NP', 'Non Pareto') ]) - email_finance = fields.Char(string='Email Finance') - email_sales = fields.Char(string='Email Sales') + email_finance = fields.Char(string='Email Finance Vendor') + email_sales = fields.Char(string='Email Sales Vendor') user_payment_terms_sales = fields.Many2one('res.users', string='Users Update Payment Terms') date_payment_terms_sales = fields.Datetime(string='Date Update Payment Terms') @@ -191,10 +191,10 @@ class ResPartner(models.Model): def _check_duplicate_name(self): for record in self: if record.name: - # Mencari partner lain yang memiliki nama sama (case-insensitive) existing_partner = self.env['res.partner'].search([ - ('id', '!=', record.id), # Hindari mencocokkan diri sendiri - ('name', '=', record.name) # Case-insensitive search + ('id', '!=', record.id), + ('name', '=', record.name), + ('email', '=', record.email) ], limit=1) if existing_partner: diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index aee19ec7..14a8e688 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -51,6 +51,16 @@ class CancelReasonOrder(models.TransientModel): order.confirm_cancel_order() return {'type': 'ir.actions.act_window_close'} + +class ShippingOption(models.Model): + _name = "shipping.option" + _description = "Shipping Option" + + name = fields.Char(string="Option Name", required=True) + price = fields.Float(string="Price", required=True) + provider = fields.Char(string="Provider") + etd = fields.Char(string="Estimated Delivery Time") + sale_order_id = fields.Many2one('sale.order', string="Sale Order", ondelete="cascade") class SaleOrder(models.Model): _inherit = "sale.order" @@ -221,6 +231,12 @@ class SaleOrder(models.Model): string="Attachment Bukti Cancel", readonly=False, ) nomor_so_pengganti = fields.Char(string='Nomor SO Pengganti', copy=False, tracking=3) + shipping_option_id = fields.Many2one("shipping.option", string="Selected Shipping Option", domain="['|', ('sale_order_id', '=', False), ('sale_order_id', '=', id)]") + + @api.constrains('shipping_option_id') + def _check_shipping_option(self): + for rec in self: + rec.delivery_amt = rec.shipping_option_id.price def _compute_shipping_method_picking(self): for order in self: @@ -268,15 +284,26 @@ class SaleOrder(models.Model): if total_weight == 0: raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") - + if total_weight < 10: total_weight = 10 + self.delivery_amt = total_weight * 3000 + + shipping_option = self.env["shipping.option"].create({ + "name": "Indoteknik Delivery", + "price": self.delivery_amt, + "provider": "Indoteknik", + "etd": "1-2 Hari", + "sale_order_id": self.id, + }) + self.shipping_option_id = shipping_option.id def action_estimate_shipping(self): if self.carrier_id.id in [1, 151]: self.action_indoteknik_estimate_shipping() return + total_weight = 0 missing_weight_products = [] @@ -294,33 +321,35 @@ class SaleOrder(models.Model): if total_weight == 0: raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.") - # Mendapatkan city_id berdasarkan nama kota - origin_city_name = self.warehouse_id.partner_id.kota_id.name destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id - if not destination_subsdistrict_id: - raise UserError("Gagal mendapatkan ID kota asal atau tujuan.") + raise UserError("Gagal mendapatkan ID kota tujuan.") result = self._call_rajaongkir_api(total_weight, destination_subsdistrict_id) if result: - estimated_cost = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['value'] - self.delivery_amt = estimated_cost - - shipping_info = [] + shipping_options = [] for courier in result['rajaongkir']['results']: for cost_detail in courier['costs']: service = cost_detail['service'] description = cost_detail['description'] etd = cost_detail['cost'][0]['etd'] value = cost_detail['cost'][0]['value'] - shipping_info.append(f"Service: {service}, Description: {description}, ETD: {etd} hari, Cost: Rp {value}") + shipping_options.append((service, description, etd, value, courier['code'])) + + self.env["shipping.option"].search([('sale_order_id', '=', self.id)]).unlink() + + for service, description, etd, value, provider in shipping_options: + self.env["shipping.option"].create({ + "name": service, + "price": value, + "provider": provider, + "etd": etd, + "sale_order_id": self.id, + }) - log_message = "<br/>".join(shipping_info) + self.shipping_option_id = self.env["shipping.option"].search([('sale_order_id', '=', self.id)], limit=1).id - description_ongkir = result['rajaongkir']['results'][0]['costs'][0]['description'] - etd_ongkir = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['etd'] - service_ongkir = result['rajaongkir']['results'][0]['costs'][0]['service'] - self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}<br/>Service: {service_ongkir}<br/>Description: {description_ongkir}<br/>ETD: {etd_ongkir}<br/>Detail Lain:<br/>{log_message}") + self.message_post(body=f"Estimasi Ongkos Kirim: Rp{self.delivery_amt}<br/>Detail Lain:<br/>{'<br/>'.join([f'Service: {s[0]}, Description: {s[1]}, ETD: {s[2]} hari, Cost: Rp {s[3]}' for s in shipping_options])}") else: raise UserError("Gagal mendapatkan estimasi ongkir.") @@ -513,6 +542,7 @@ class SaleOrder(models.Model): if vendor_sla: if vendor_sla.unit == 'hari': vendor_duration = vendor_sla.duration * 24 * 60 + include_instant = False else : vendor_duration = vendor_sla.duration * 60 include_instant = True diff --git a/indoteknik_custom/models/stock_inventory.py b/indoteknik_custom/models/stock_inventory.py index 12a891de..69cca5bc 100644 --- a/indoteknik_custom/models/stock_inventory.py +++ b/indoteknik_custom/models/stock_inventory.py @@ -29,10 +29,10 @@ class StockInventory(models.Model): """Menentukan nomor berdasarkan kategori Adjust-In atau Adjust-Out.""" name_upper = record.name.upper() if record.name else "" - if self.adjusment_type == 'out' or "ADJUST OUT" in name_upper or "ADJUST-OUT" in name_upper or "OUT" in name_upper: + if self.adjusment_type == 'out': last_number = self._get_last_sequence("ADJUST/OUT/") record.number = f"ADJUST/OUT/{last_number}" - elif self.adjusment_type == 'in' or "ADJUST IN" in name_upper or "ADJUST-IN" in name_upper or "IN" in name_upper: + elif self.adjusment_type == 'in': last_number = self._get_last_sequence("ADJUST/IN/") record.number = f"ADJUST/IN/{last_number}" else: @@ -54,6 +54,26 @@ class StockInventory(models.Model): @api.model def create(self, vals): + """Pastikan nomor hanya dibuat saat penyimpanan.""" + if 'adjusment_type' in vals and not vals.get('number'): + vals['number'] = False # Jangan buat number otomatis dulu + order = super(StockInventory, self).create(vals) - self._assign_number(order) + + if order.adjusment_type: + self._assign_number(order) # Generate number setelah save + return order + + def write(self, vals): + """Jika adjusment_type diubah, generate ulang nomor.""" + res = super(StockInventory, self).write(vals) + if 'adjusment_type' in vals: + for record in self: + self._assign_number(record) + return res + + def copy(self, default=None): + """Saat duplikasi, adjusment_type dikosongkan dan number tidak ikut terduplikasi.""" + default = dict(default or {}, adjusment_type=False, number=False) + return super(StockInventory, self).copy(default=default) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index b8bdcd94..ab8109c7 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -934,6 +934,7 @@ class StockPicking(models.Model): self.calculate_line_no() self.date_done = datetime.datetime.utcnow() self.state_reserve = 'done' + self.final_seq = 0 self.send_mail_bills() return res diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 4d9d8cf7..4d0e51eb 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -167,3 +167,4 @@ access_barcoding_product_line,access.barcoding.product.line,model_barcoding_prod access_account_payment_register,access.account.payment.register,model_account_payment_register,,1,1,1,1 access_stock_inventory,access.stock.inventory,model_stock_inventory,,1,1,1,1 access_cancel_reason_order,cancel.reason.order,model_cancel_reason_order,,1,1,1,0 +access_shipping_option,shipping.option,model_shipping_option,,1,1,1,1 diff --git a/indoteknik_custom/views/customer_commision.xml b/indoteknik_custom/views/customer_commision.xml index 51172b1c..bb1628bc 100644 --- a/indoteknik_custom/views/customer_commision.xml +++ b/indoteknik_custom/views/customer_commision.xml @@ -17,6 +17,8 @@ decoration-danger="payment_status == 'pending'" widget="badge"/> <field name="brand_ids" widget="many2many_tags"/> + <field name="grouped_so_number" readonly="1"/> + <field name="grouped_invoice_number" readonly="1"/> </tree> </field> </record> @@ -62,6 +64,8 @@ <field name="description"/> <field name="commision_percent"/> <field name="commision_amt"/> + <field name="grouped_so_number" readonly="1"/> + <field name="grouped_invoice_number" readonly="1"/> </group> <group> <div> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index ebee64b1..0d190f37 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -100,6 +100,7 @@ <field name="sales_tax_id" domain="[('type_tax_use','=','sale'), ('active', '=', True)]" required="1"/> <field name="carrier_id" required="1"/> <field name="delivery_service_type" readonly="1"/> + <field name="shipping_option_id"/> </field> <field name="medium_id" position="after"> <field name="date_doc_kirim" readonly="1"/> |
