diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2026-03-02 13:36:25 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2026-03-02 13:36:25 +0700 |
| commit | ac740aaf093356e87588d10f536426c0cda1a5db (patch) | |
| tree | 268276c64303599f30485b76bac1bf586ce53c3f /fixco_custom/models/detail_order.py | |
| parent | fad81778927ee717d284efbe64c8deb5723556ff (diff) | |
<Miqdad> rev detail order
Diffstat (limited to 'fixco_custom/models/detail_order.py')
| -rwxr-xr-x | fixco_custom/models/detail_order.py | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py index 2309e30..af6b1ee 100755 --- a/fixco_custom/models/detail_order.py +++ b/fixco_custom/models/detail_order.py @@ -268,6 +268,7 @@ class DetailOrder(models.Model): def prepare_data_so_line(self, json_data): order_lines = [] product_not_found = False + product_bundling_no_pricelist = False # Get all items (already combined if grouped) items = json_data.get('data', [{}])[0].get('items', []) @@ -297,7 +298,7 @@ class DetailOrder(models.Model): sale_pricelist = self.env['product.pricelist.item'].search([ ('product_id', 'in', bundling_variant_ids), ('pricelist_id', '=', 17) - ]) + ]) price_bundling_bottom = sum(item.fixed_price for item in sale_pricelist) for bline in bundling_lines: @@ -305,13 +306,17 @@ class DetailOrder(models.Model): ('product_id', '=', bline.variant_id.id), ('pricelist_id', '=', 17) ], limit=1) - price = bottom_price.fixed_price - price_unit = self.prorate_price_bundling( - bline.variant_id, - price_bundling_bottom, - price, - actual_price=combined_item['actualPrice'] - ) + price = bottom_price.fixed_price if bottom_price else 0 + if not price or price <= 0: + price_unit = 0 + product_bundling_no_pricelist = True + else: + price_unit = self.prorate_price_bundling( + bline.variant_id, + price_bundling_bottom, + price, + actual_price=combined_item['actualPrice'] + ) order_lines.append((0, 0, { 'product_id': bline.variant_id.id if bline.variant_id else product.id, 'product_uom_qty': bline.product_uom_qty * combined_item['quantity'], @@ -340,13 +345,13 @@ class DetailOrder(models.Model): order_lines.append((0, 0, line_data)) - return order_lines, product_not_found + return order_lines, product_not_found, product_bundling_no_pricelist def execute_queue_detail(self): try: json_data = json.loads(self.detail_order) data = self.prepare_data_so(json_data) - order_lines, product_not_found = self.prepare_data_so_line(json_data) + order_lines, product_not_found, product_bundling_no_pricelist = self.prepare_data_so_line(json_data) order_id, order_status, print_info = self.get_order_id_detail() # First check if a sale order with this reference already exists @@ -391,7 +396,7 @@ class DetailOrder(models.Model): else: # If no existing SO, create one, then cancel data = self.prepare_data_so(json_data) - order_lines, product_not_found = self.prepare_data_so_line(json_data) + order_lines, product_not_found, product_bundling_no_pricelist = self.prepare_data_so_line(json_data) data['order_line'] = order_lines sale_order = self.env['sale.order'].create(data) @@ -438,7 +443,7 @@ class DetailOrder(models.Model): sale_order.order_reference = order_id sale_order.address = json_data.get('data', [{}])[0].get('shippingAddressInfo', []).get('fullAddress', []) sale_order.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', []) - if not product_not_found or sale_order.partner_id == 414: + if (not product_not_found and not product_bundling_no_pricelist) or sale_order.partner_id == 414: sale_order.action_confirm() # self.picking_id = sale_order.picking_ids[0].id # self.picking_id.order_reference = order_id @@ -446,9 +451,9 @@ class DetailOrder(models.Model): # self.picking_id.carrier = sale_order.carrier # self.picking_id.address = json_data.get('data', [{}])[0].get('shippingAddressInfo', []).get('fullAddress', []) # self.picking_id.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', []) - self.execute_status = 'so_confirm' else: + sale_order.message_post(body="Auto draft karena bundling price 0 / tidak ditemukan.") self.execute_status = 'so_draft' else: # For other statuses, create new order only if it doesn't exist @@ -459,7 +464,7 @@ class DetailOrder(models.Model): sale_order.order_reference = order_id sale_order.address = json_data.get('data', [{}])[0].get('shippingAddressInfo', []).get('fullAddress', []) sale_order.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', []) - if not product_not_found or sale_order.partner_id == 414: + if (not product_not_found and not product_bundling_no_pricelist) or sale_order.partner_id == 414: sale_order.action_confirm() # self.picking_id = sale_order.picking_ids[0].id # self.picking_id.order_reference = order_id @@ -467,9 +472,9 @@ class DetailOrder(models.Model): # self.picking_id.carrier = sale_order.carrier # self.picking_id.address = json_data.get('data', [{}])[0].get('shippingAddressInfo', []).get('fullAddress', []) # self.picking_id.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', []) - self.execute_status = 'so_confirm' else: + sale_order.message_post(body="Auto draft karena bundling price 0 / tidak ditemukan.") self.execute_status = 'so_draft' else: self.execute_status = 'failed' |
