From 2fff5e5cd1af24ec0bd4c57ce89373bcb4380544 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 20 Oct 2021 10:53:39 +0530 Subject: [PATCH 1/3] fix: map missing fields in opportunity (#27904) (cherry picked from commit d81f81134955783d632b7d4005999da2092e82e7) # Conflicts: # erpnext/crm/doctype/opportunity/opportunity.py --- .../crm/doctype/opportunity/opportunity.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 0b3f50897ab..3e9d76ee9c1 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -34,6 +34,7 @@ class Opportunity(TransactionBase): 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 @@ -41,6 +42,35 @@ class Opportunity(TransactionBase): 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: From ae948e31eae4c2685d7fbd10c2a952cfa34d4b17 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 20 Oct 2021 11:30:33 +0530 Subject: [PATCH 2/3] fix: linters --- erpnext/crm/doctype/opportunity/opportunity.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 3e9d76ee9c1..6ee95b020dc 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -42,8 +42,6 @@ class Opportunity(TransactionBase): if not self.with_items: self.items = [] -<<<<<<< HEAD -======= else: self.calculate_totals() @@ -70,7 +68,6 @@ class Opportunity(TransactionBase): 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: From 8c57394e7893490b637467c5213a50f18e8ed5d5 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 20 Oct 2021 12:14:15 +0530 Subject: [PATCH 3/3] fix: conflicts --- erpnext/crm/doctype/opportunity/opportunity.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 6ee95b020dc..8027cbc69cc 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -42,9 +42,6 @@ class Opportunity(TransactionBase): if not self.with_items: self.items = [] - else: - self.calculate_totals() - def map_fields(self): for field in self.meta.fields: if not self.get(field.fieldname): @@ -54,20 +51,6 @@ class Opportunity(TransactionBase): 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) - def make_new_lead_if_required(self): """Set lead against new opportunity""" if (not self.get("party_name")) and self.contact_email: