diff --git a/ecommerce_integrations/unicommerce/delivery_note.py b/ecommerce_integrations/unicommerce/delivery_note.py index 73675d77..45a9df5b 100644 --- a/ecommerce_integrations/unicommerce/delivery_note.py +++ b/ecommerce_integrations/unicommerce/delivery_note.py @@ -72,99 +72,38 @@ def create_delivery_note(order, settings, so): if ( not frappe.db.get_value("Delivery Note", {"shipment_id":order["code"]}, "name") ): - - frappe.logger("log1").exception("++++++++++++++++++++++"+str(so.unicommerce_order_code)) - # Get the sales invoice - if frappe.get_value("Sales Invoice", {"unicommerce_order_code":so.unicommerce_order_code}): - sales_invoice = frappe.get_doc("Sales Invoice", {"unicommerce_order_code":so.unicommerce_order_code}) + # create a new delivery note + delivery_note = frappe.get_doc({ + "doctype": "Delivery Note", + "customer": so.customer, + "unicommerce_order_no":order["saleOrderCode"], + "shipment_id":order["code"], + "status": "Completed" + }) - # Create the delivery note - delivery_note = frappe.new_doc("Delivery Note") - delivery_note.update({ - "customer": sales_invoice.customer, - "customer_address": sales_invoice.customer_address, - "shipping_address_name": sales_invoice.shipping_address_name, - "posting_date": sales_invoice.posting_date, - "items": [] + # add items to the delivery note + for item in so.items: + delivery_note.append("items", { + "item_code": item.item_code, + "qty": item.qty, + "rate": item.rate, + "warehouse":item.warehouse, + "against_sales_order":so.name + }) + # add texes to the delivery note + for item in so.taxes: + delivery_note.append("taxes",{ + "charge_type": item.charge_type, + "account_head": item.account_head, + "tax_amount": item.tax_amount, + "description": item.description, + "item_wise_tax_detail": item.item_wise_tax_detail, + "dont_recompute_tax": item.dont_recompute_tax, }) - # Add items to the delivery note - for item in sales_invoice.items: - delivery_note.append("items", { - "item_code": item.item_code, - "item_name": item.item_name, - "description": item.description, - "qty": item.qty, - "uom": item.uom, - "rate": item.rate, - "amount": item.amount, - "stock_qty": item.qty, - "so_detail": item.name, - "so_detail_item": item.idx, - "warehouse":item.warehouse, - "against_sales_order":so.name - }) - for item in sales_invoice.taxes: - delivery_note.append("taxes",{ - "charge_type": item.charge_type, - "account_head": item.account_head, - "tax_amount": item.tax_amount, - "description": item.description, - "item_wise_tax_detail": item.item_wise_tax_detail, - "dont_recompute_tax": item.dont_recompute_tax, - }) - # Save the delivery note - delivery_note.flags.ignore_permissions = True - delivery_note.flags.ignore_mandatory = True - delivery_note.unicommerce_order_no = order["saleOrderCode"] - delivery_note.shipment_id = order["code"] - delivery_note.status = "Completed" - delivery_note.insert() - - # Submit the delivery note - delivery_note.submit() - - # Update the sales invoice with the delivery note information - sales_invoice.delivery_note = delivery_note.name - sales_invoice.flags.ignore_permissions = True - sales_invoice.flags.ignore_mandatory = True - sales_invoice.save() - - - # create a new delivery note - - # delivery_note = frappe.get_doc({ - # "doctype": "Delivery Note", - # "customer": so.customer, - # "unicommerce_order_no":order["saleOrderCode"], - # "shipment_id":order["code"], - # "status": "Completed" - # }) - - # # add items to the delivery note - # for item in so.items: - # delivery_note.append("items", { - # "item_code": item.item_code, - # "qty": item.qty, - # "rate": item.rate, - # "warehouse":item.warehouse, - # "against_sales_order":so.name - # }) - # # add texes to the delivery note - # for item in so.taxes: - # delivery_note.append("taxes",{ - # "charge_type": item.charge_type, - # "account_head": item.account_head, - # "tax_amount": item.tax_amount, - # "description": item.description, - # "item_wise_tax_detail": item.item_wise_tax_detail, - # "dont_recompute_tax": item.dont_recompute_tax, - # }) - - # # save the delivery note - # delivery_note.insert() - # delivery_note.submit() + # save the delivery note + delivery_note.insert() + delivery_note.submit() except Exception as e: - frappe.logger("log1").exception(e) create_unicommerce_log(status="Error", exception=e, rollback=True)