[UPD] Correction on plan_price calculation
To make possible the use of sections and sub-section without child lines
This commit is contained in:
@@ -162,15 +162,10 @@ class BudgetForecast(models.Model):
|
|||||||
def _onchange_product_id(self):
|
def _onchange_product_id(self):
|
||||||
if self.product_id:
|
if self.product_id:
|
||||||
self.description = self.product_id.name
|
self.description = self.product_id.name
|
||||||
if self.display_type == "line_article":
|
self._calc_plan_price(True)
|
||||||
self.plan_price = self.product_id.standard_price
|
|
||||||
else:
|
|
||||||
self._calc_plan_price()
|
|
||||||
else:
|
else:
|
||||||
self.description = ""
|
self.description = ""
|
||||||
self.plan_price = 0
|
self.plan_price = 0
|
||||||
if self.display_type != "line_article":
|
|
||||||
self._calc_plan_price()
|
|
||||||
|
|
||||||
def _get_budget_category_label(self):
|
def _get_budget_category_label(self):
|
||||||
categories = dict(self._fields["budget_category"].selection)
|
categories = dict(self._fields["budget_category"].selection)
|
||||||
@@ -304,17 +299,17 @@ class BudgetForecast(models.Model):
|
|||||||
record.plan_qty = sum(record.mapped("child_ids.plan_qty"))
|
record.plan_qty = sum(record.mapped("child_ids.plan_qty"))
|
||||||
|
|
||||||
@api.depends("child_ids")
|
@api.depends("child_ids")
|
||||||
def _calc_plan_price(self):
|
def _calc_plan_price(self, product_change=False):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.display_type in ["line_section", "line_subsection"]:
|
if record.display_type in ["line_section", "line_subsection"]:
|
||||||
if record.child_ids:
|
if record.child_ids:
|
||||||
lst = record.mapped("child_ids.plan_price")
|
lst = record.mapped("child_ids.plan_price")
|
||||||
if lst and (sum(lst) > 0):
|
if lst and (sum(lst) > 0):
|
||||||
record.plan_price = lst and sum(lst)
|
record.plan_price = lst and sum(lst)
|
||||||
else:
|
elif product_change:
|
||||||
record.plan_price = record.product_id.standard_price
|
|
||||||
else:
|
|
||||||
record.plan_price = record.product_id.standard_price
|
record.plan_price = record.product_id.standard_price
|
||||||
|
elif product_change and (record.display_type == "line_article"):
|
||||||
|
record.plan_price = self.product_id.standard_price
|
||||||
elif record.display_type == "line_note":
|
elif record.display_type == "line_note":
|
||||||
record.plan_price = 0.00
|
record.plan_price = 0.00
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user