diff --git a/addons/fleet/models/fleet_vehicle.py b/addons/fleet/models/fleet_vehicle.py index d7bac0d2925..79a67f544c9 100644 --- a/addons/fleet/models/fleet_vehicle.py +++ b/addons/fleet/models/fleet_vehicle.py @@ -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') diff --git a/addons/l10n_be_hr_payroll_fleet/models/fleet.py b/addons/l10n_be_hr_payroll_fleet/models/fleet.py index da0bf8600fc..69b123f79dd 100644 --- a/addons/l10n_be_hr_payroll_fleet/models/fleet.py +++ b/addons/l10n_be_hr_payroll_fleet/models/fleet.py @@ -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) diff --git a/addons/sale/models/analytic.py b/addons/sale/models/analytic.py index 8cb0384df6b..6171d29f376 100644 --- a/addons/sale/models/analytic.py +++ b/addons/sale/models/analytic.py @@ -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 diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index b0d1080296b..fd49ac36aed 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -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 diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml index d6d1426d626..0655842b7a0 100644 --- a/addons/sale/views/sale_views.xml +++ b/addons/sale/views/sale_views.xml @@ -255,6 +255,7 @@ +