Merge pull request #17113 from deepeshgarg007/item-register

fix: Divide by zero exception handling
diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
index 3234e7a..124910e 100644
--- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
+++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
@@ -162,6 +162,8 @@
 		igroup.parent_item_group =  mws_settings.item_group
 		igroup.insert()
 
+	item.append("item_defaults", {'company':mws_settings.company})
+
 	item.insert(ignore_permissions=True)
 	create_item_price(amazon_item_json, item.item_code)
 
@@ -213,7 +215,7 @@
 			fulfillment_channels=["MFN", "AFN"],
 			lastupdatedafter=after_date,
 			orderstatus=statuses,
-			max_results='20')
+			max_results='50')
 
 		while True:
 			orders_list = []
@@ -432,8 +434,8 @@
 	return final_order_items
 
 def get_item_code(order_item):
-	asin = order_item.ASIN
-	item_code = frappe.db.get_value("Item", {"amazon_item_code": asin}, "item_code")
+	sku = order_item.SellerSKU
+	item_code = frappe.db.get_value("Item", {"item_code": sku}, "item_code")
 	if item_code:
 		return item_code
 
@@ -451,11 +453,16 @@
 			shipment_item_list = return_as_list(shipment_event.ShipmentEvent.ShipmentItemList.ShipmentItem)
 
 			for shipment_item in shipment_item_list:
-				charges = return_as_list(shipment_item.ItemChargeList.ChargeComponent)
-				fees = return_as_list(shipment_item.ItemFeeList.FeeComponent)
+				charges, fees = []
+
+				if 'ItemChargeList' in shipment_item.keys():
+					charges = return_as_list(shipment_item.ItemChargeList.ChargeComponent)
+
+				if 'ItemFeeList' in shipment_item.keys():
+					fees = return_as_list(shipment_item.ItemFeeList.FeeComponent)
 
 				for charge in charges:
-					if(charge.ChargeType != "Principal"):
+					if(charge.ChargeType != "Principal") and float(charge.ChargeAmount.CurrencyAmount) != 0:
 						charge_account = get_account(charge.ChargeType)
 						charges_fees.get("charges").append({
 							"charge_type":"Actual",
@@ -465,13 +472,14 @@
 							})
 
 				for fee in fees:
-					fee_account = get_account(fee.FeeType)
-					charges_fees.get("fees").append({
-						"charge_type":"Actual",
-						"account_head": fee_account,
-						"tax_amount": fee.FeeAmount.CurrencyAmount,
-						"description": fee.FeeType + " for " + shipment_item.SellerSKU
-						})
+					if float(fee.FeeAmount.CurrencyAmount) != 0:
+						fee_account = get_account(fee.FeeType)
+						charges_fees.get("fees").append({
+							"charge_type":"Actual",
+							"account_head": fee_account,
+							"tax_amount": fee.FeeAmount.CurrencyAmount,
+							"description": fee.FeeType + " for " + shipment_item.SellerSKU
+							})
 
 	return charges_fees
 
diff --git a/erpnext/regional/italy/e-invoice.xml b/erpnext/regional/italy/e-invoice.xml
index 935077b..b725b96 100644
--- a/erpnext/regional/italy/e-invoice.xml
+++ b/erpnext/regional/italy/e-invoice.xml
@@ -184,11 +184,7 @@
         <UnitaMisura>{{ item.stock_uom }}</UnitaMisura>
         <PrezzoUnitario>{{ format_float(item.price_list_rate or item.rate) }}</PrezzoUnitario>
         {{ render_discount_or_margin(item) }}
-        {%- if (item.discount_amount or item.rate_with_margin) %}
-          <PrezzoTotale>{{ format_float(item.net_amount) }}</PrezzoTotale>
-        {%- else %}
-          <PrezzoTotale>{{ format_float(item.amount) }}</PrezzoTotale>
-        {%- endif %}
+        <PrezzoTotale>{{ format_float(item.amount) }}</PrezzoTotale>
         <AliquotaIVA>{{ format_float(item.tax_rate) }}</AliquotaIVA>
         {%- if item.tax_exemption_reason %}
         <Natura>{{ item.tax_exemption_reason.split("-")[0] }}</Natura>