summaryrefslogtreecommitdiff
path: root/fixco_custom/models/detail_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-06-04 13:40:22 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-06-04 13:40:22 +0700
commitdca58449623e0fd25f2dc301747982da6a5ea940 (patch)
tree3a090311c4e9892384acee114fad9ad80c1bb3f5 /fixco_custom/models/detail_order.py
parent3307dcbdb37285bcd43a719a0ecbc1453e4af9df (diff)
add new field on so and invoice
Diffstat (limited to 'fixco_custom/models/detail_order.py')
-rwxr-xr-xfixco_custom/models/detail_order.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py
index 9cbc446..bac1ff5 100755
--- a/fixco_custom/models/detail_order.py
+++ b/fixco_custom/models/detail_order.py
@@ -114,7 +114,7 @@ class DetailOrder(models.Model):
print_info = json_data.get('data', {})[0].get('printInfo', {}).get('labelPrintStatus')
if not order_id:
raise UserError(_("Order ID not found in JSON data"))
- return order_id, order_status, print_info
+ return order_id, order_status, print_info, json_data
raise UserError(_("No JSON data available"))
except json.JSONDecodeError:
raise UserError(_("Invalid JSON format in detail_order field"))
@@ -160,6 +160,7 @@ class DetailOrder(models.Model):
def prepare_data_so_line(self, json_data):
order_lines = []
items = json_data.get('data', [{}])[0].get('items', [])
+ product_not_found = False
for item in items:
product = self.env['product.product'].search(
@@ -173,18 +174,19 @@ class DetailOrder(models.Model):
'product_uom_qty': item.get('quantity'),
'price_unit': item.get('actualPrice'),
}
-
+
if not product:
line_data['name'] = f"{item.get('masterSku')} ({item.get('productName')})"
+ product_not_found = True
order_lines.append((0, 0, line_data))
- return order_lines
+ return order_lines, product_not_found
def execute_queue_detail(self):
try:
json_data = json.loads(self.detail_order)
data = self.prepare_data_so(json_data)
- order_lines = self.prepare_data_so_line(json_data)
+ order_lines, product_not_found = 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
@@ -204,11 +206,16 @@ class DetailOrder(models.Model):
self.sale_id = sale_order.id
sale_order.order_reference = order_id
- sale_order.action_confirm()
+ 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:
+ sale_order.action_confirm()
self.picking_id = sale_order.picking_ids[0].id
self.picking_id.order_reference = order_id
self.picking_id.invoice_mp = sale_order.invoice_mp
+ 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:
@@ -218,11 +225,16 @@ class DetailOrder(models.Model):
self.sale_id = sale_order.id
sale_order.order_reference = order_id
- sale_order.action_confirm()
+ 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:
+ sale_order.action_confirm()
self.picking_id = sale_order.picking_ids[0].id
self.picking_id.order_reference = order_id
self.picking_id.invoice_mp = sale_order.invoice_mp
+ 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'