[MERGE] forward port branch 11.0 up to 8f47b028ed

This commit is contained in:
Christophe Simonis
2019-01-24 17:01:40 +01:00
7 changed files with 43 additions and 18 deletions
+1
View File
@@ -51,6 +51,7 @@ class FleetVehicle(models.Model):
fuel_type = fields.Selection([
('gasoline', 'Gasoline'),
('diesel', 'Diesel'),
('lpg', 'LPG'),
('electric', 'Electric'),
('hybrid', 'Hybrid')
], 'Fuel Type', help='Fuel Used by the vehicle')
+20 -11
View File
@@ -45,15 +45,21 @@ class FleetVehicle(models.Model):
elif contract.cost_frequency == "yearly":
car.total_cost += contract.cost_generated / 12.0
def _get_co2_fee(self, co2):
return max((((co2 * 9.0) - 600.0) * 1.2488) / 12.0, 0.0)
def _get_co2_fee(self, co2, fuel_type):
fuel_coefficient = {'diesel': 600, 'gasoline': 768, 'lpg': 990, 'electric': 0, 'hybrid': 600}
co2_fee = 0
if fuel_type and fuel_type != 'electric':
if not co2:
co2 = 165 if fuel_type in ['diesel', 'hybrid'] else 182
co2_fee = (((co2 * 9.0) - fuel_coefficient.get(fuel_type, 0)) * 144.97 / 114.08) / 12.0
return max(co2_fee, 26.47)
@api.depends('co2')
@api.depends('co2', 'fuel_type')
def _compute_co2_fee(self):
for car in self:
car.co2_fee = self._get_co2_fee(car.co2)
car.co2_fee = self._get_co2_fee(car.co2, car.fuel_type)
@api.depends('fuel_type', 'car_value', 'acquisition_date')
@api.depends('fuel_type', 'car_value', 'acquisition_date', 'co2')
def _compute_car_atn(self):
for car in self:
car.atn = car._get_car_atn(car.acquisition_date, car.car_value, car.fuel_type, car.co2)
@@ -99,15 +105,18 @@ class FleetVehicle(models.Model):
atn = 0.0
else:
if fuel_type in ['diesel', 'hybrid']:
reference = 87.0
reference = 88.0
else:
reference = 105.0
reference = 107.0
if not co2:
co2 = 195 if fuel_type in ['diesel', 'hybrid'] else 205
if co2 <= reference:
atn = car_value * max(0.04, (0.055 - 0.001 * (reference - co2))) * magic_coeff
else:
atn = car_value * min(0.18, (0.055 + 0.001 * (co2 - reference))) * magic_coeff
return max(1280, atn) / 12.0
return max(1310, atn) / 12.0
class FleetVehicleLogContract(models.Model):
@@ -121,7 +130,7 @@ class FleetVehicleModel(models.Model):
default_recurring_cost_amount_depreciated = fields.Float(string="Cost (Depreciated)",
help="Default recurring cost amount that should be applied to a new car from this model")
default_co2 = fields.Float(string="CO2 emissions")
default_fuel_type = fields.Selection([('gasoline', 'Gasoline'), ('diesel', 'Diesel'), ('electric', 'Electric'), ('hybrid', 'Hybrid')], 'Fuel Type', help='Fuel Used by the vehicle')
default_fuel_type = fields.Selection([('gasoline', 'Gasoline'), ('diesel', 'Diesel'), ('lpg', 'LPG'), ('electric', 'Electric'), ('hybrid', 'Hybrid')], 'Fuel Type', help='Fuel Used by the vehicle')
default_car_value = fields.Float(string="Catalog Value (VAT Incl.)")
can_be_requested = fields.Boolean(string="Can be requested", help="Can be requested on a contract as a new car")
default_atn = fields.Float(compute='_compute_atn', string="ATN")
@@ -139,7 +148,7 @@ class FleetVehicleModel(models.Model):
for model in self:
model.default_total_depreciated_cost = model.co2_fee + model.default_recurring_cost_amount_depreciated
@api.depends('default_co2')
@api.depends('default_co2', 'default_fuel_type')
def _compute_co2_fee(self):
for model in self:
model.co2_fee = self.env['fleet.vehicle']._get_co2_fee(model.default_co2)
model.co2_fee = self.env['fleet.vehicle']._get_co2_fee(model.default_co2, model.default_fuel_type)
+3 -2
View File
@@ -19,7 +19,7 @@ class AccountAnalyticLine(models.Model):
@api.model
def create(self, values):
result = super(AccountAnalyticLine, self).create(values)
if 'so_line' not in values and not result.so_line and result.product_id and result.product_id.expense_policy != 'no' and result.amount <= 0: # allow to force a False value for so_line
if 'so_line' not in values and not result.so_line and result.product_id and result.product_id.expense_policy not in [False, 'no'] and result.amount <= 0: # allow to force a False value for so_line
result.sudo()._sale_determine_order_line()
return result
@@ -28,7 +28,8 @@ class AccountAnalyticLine(models.Model):
result = super(AccountAnalyticLine, self).write(values)
if 'so_line' not in values: # allow to force a False value for so_line
# only take the AAL from expense or vendor bill, meaning having a negative amount
self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy != 'no' and aal.amount <= 0)._sale_determine_order_line()
self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy not in [False, 'no'] and aal.amount <= 0)._sale_determine_order_line()
return result
# ----------------------------------------------------------
# Vendor Bill / Expense : determine the Sale Order to reinvoice
+4 -4
View File
@@ -34,8 +34,8 @@ class SaleOrder(models.Model):
amount_untaxed += line.price_subtotal
amount_tax += line.price_tax
order.update({
'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed),
'amount_tax': order.pricelist_id.currency_id.round(amount_tax),
'amount_untaxed': amount_untaxed,
'amount_tax': amount_tax,
'amount_total': amount_untaxed + amount_tax,
})
@@ -583,7 +583,7 @@ class SaleOrder(models.Model):
# create an analytic account if at least an expense product
for order in self:
if any([expense_policy != 'no' for expense_policy in order.order_line.mapped('product_id.expense_policy')]):
if any([expense_policy not in [False, 'no'] for expense_policy in order.order_line.mapped('product_id.expense_policy')]):
if not order.analytic_account_id:
order._create_analytic_account()
@@ -857,7 +857,7 @@ class SaleOrderLine(models.Model):
msg = _("Extra line with %s ") % (line.product_id.display_name,)
line.order_id.message_post(body=msg)
# create an analytic account if at least an expense product
if line.product_id.expense_policy != 'no' and not self.order_id.analytic_account_id:
if line.product_id.expense_policy not in [False, 'no'] and not self.order_id.analytic_account_id:
self.order_id._create_analytic_account()
return line
+3
View File
@@ -255,6 +255,7 @@
<field name="qty_delivered_manual" invisible="1"/>
<field name="qty_delivered_method" invisible="1"/>
<field name="price_total" invisible="1"/>
<field name="price_tax" invisible="1"/>
<field name="price_subtotal" invisible="1"/>
<label for="product_uom_qty" string="Ordered Quantity"/>
<div>
@@ -339,12 +340,14 @@
<field name="invoice_status" invisible="1"/>
<field name="customer_lead" invisible="1"/>
<field name="currency_id" invisible="1"/>
<field name="price_tax" invisible="1"/>
</tree>
<kanban class="o_kanban_mobile">
<field name="product_id"/>
<field name="product_uom_qty"/>
<field name="product_uom" groups="uom.group_uom"/>
<field name="price_subtotal"/>
<field name="price_tax" invisible="1"/>
<field name="price_total" invisible="1"/>
<field name="price_unit"/>
<templates>
+1 -1
View File
@@ -10,7 +10,7 @@ class AccountAnalyticLine(models.Model):
@api.multi
def _sale_determine_order(self):
mapping = super(AccountAnalyticLine, self)._sale_determine_order()
for analytic_line in self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy != 'no'):
for analytic_line in self.sudo().filtered(lambda aal: not aal.so_line and aal.product_id and aal.product_id.expense_policy not in [False, 'no']):
if analytic_line.move_id.expense_id.sale_order_id:
mapping[analytic_line.id] = analytic_line.move_id.expense_id.sale_order_id
return mapping
+11
View File
@@ -0,0 +1,11 @@
Yemen, 2019-01-22
I hereby agree to the terms of the Odoo Individual Contributor License
Agreement v1.0.
I declare that I am authorized and able to make this agreement and sign this
declaration.
Signed,
Waleed Mohsen Mohsen.Waleed@gmail.com https://github.com/MohsenWaleed