Skip to content

Commit

Permalink
fix: map missing fields in opportunity (#27904)
Browse files Browse the repository at this point in the history
(cherry picked from commit d81f811)

# Conflicts:
#	erpnext/crm/doctype/opportunity/opportunity.py
  • Loading branch information
pateljannat authored and mergify-bot committed Oct 20, 2021
1 parent ebe68c1 commit 2fff5e5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions erpnext/crm/doctype/opportunity/opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,43 @@ def validate(self):
self.validate_item_details()
self.validate_uom_is_integer("uom", "qty")
self.validate_cust_name()
self.map_fields()

if not self.title:
self.title = self.customer_name

if not self.with_items:
self.items = []

<<<<<<< HEAD
=======
else:
self.calculate_totals()

def map_fields(self):
for field in self.meta.fields:
if not self.get(field.fieldname):
try:
value = frappe.db.get_value(self.opportunity_from, self.party_name, field.fieldname)
frappe.db.set(self, field.fieldname, value)
except Exception:
continue

def calculate_totals(self):
total = base_total = 0
for item in self.get('items'):
item.amount = flt(item.rate) * flt(item.qty)
item.base_rate = flt(self.conversion_rate * item.rate)
item.base_amount = flt(self.conversion_rate * item.amount)
total += item.amount
base_total += item.base_amount

self.total = flt(total)
self.base_total = flt(base_total)
self.grand_total = flt(self.total) + flt(self.opportunity_amount)
self.base_grand_total = flt(self.base_total) + flt(self.base_opportunity_amount)

>>>>>>> d81f811349 (fix: map missing fields in opportunity (#27904))
def make_new_lead_if_required(self):
"""Set lead against new opportunity"""
if (not self.get("party_name")) and self.contact_email:
Expand Down

0 comments on commit 2fff5e5

Please sign in to comment.