[cgscop #218] ajout A/R sur ndf IK

parent 1090607d
# © 2019 Le Filament (<http://www.le-filament.com>)
# © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re
......@@ -56,12 +56,14 @@ class CGScopExpense(models.Model):
string="Adresse d'arrivée",
compute='_compute_to_address',
store=True)
is_return = fields.Boolean("Aller/Retour")
# ------------------------------------------------------
# Default Fields
# ------------------------------------------------------
def _default_from_address(self):
return self.env.uid
# ------------------------------------------------------
# Computed Fields
# ------------------------------------------------------
......@@ -90,6 +92,9 @@ class CGScopExpense(models.Model):
# ------------------------------------------------------
@api.onchange('total_amount')
def onchange_total_amount(self):
"""
Lève une alerte si le montant dépasse le plafond
"""
for exp in self:
if exp.product_id.expense_gap > 0:
if exp.total_amount > exp.product_id.expense_gap:
......@@ -101,6 +106,9 @@ class CGScopExpense(models.Model):
@api.onchange('product_id')
def onchange_product_id(self):
"""
Change l'intégration de la NDF en fonction du type de produite
"""
if self.product_id.expense_formula == 'fixed_price':
self.unit_amount = self.product_id.standard_price
self.update({
......@@ -110,6 +118,16 @@ class CGScopExpense(models.Model):
self.quantity = 1.0
self.product_id.unit_amount = self.product_id.standard_price
@api.onchange('is_return')
def onchange_is_return(self):
"""
Définit le comportement lorsqu'on coche Aller/Retour
"""
if self.is_return:
self.quantity = self.quantity * 2
elif not self.is_return:
self.quantity = self.quantity / 2
# ------------------------------------------------------
# Button function
# ------------------------------------------------------
......@@ -122,7 +140,11 @@ class CGScopExpense(models.Model):
distance = self._get_distance(
self._get_coord(self.from_address),
self._get_coord(self.to_address))
self.quantity = ceil(distance/5)*5
quantity = ceil(distance/5)*5
if self.is_return:
self.quantity = quantity * 2
else:
self.quantity = quantity
# ------------------------------------------------------
# Global function
......
......@@ -72,6 +72,7 @@
<field name="to_address" readonly="False"/>
</group>
<group attrs="{'invisible':[('is_ik','!=', True)], 'required':[('is_ik','=', True)]}">
<field name="is_return"/>
<button type="object" name="get_ik" string="Calcul distance" class="btn-primary"></button>
</group>
<group attrs="{'invisible':[('is_ik','!=', True)], 'required':[('is_ik','=', True)]}"></group>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment