19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:07 +01:00
parent ba20ce7443
commit 768b70e05e
2357 changed files with 1057103 additions and 712486 deletions

View file

@ -1,2 +1,4 @@
from . import test_fleet_log_services
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_fleet_vehicle_log_services
from . import test_account_fleet

View file

@ -1,12 +1,17 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from freezegun import freeze_time
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import tagged, Form
@tagged('post_install', '-at_install')
class TestAccountFleet(AccountTestInvoicingCommon):
@freeze_time('2021-09-15')
def test_transfer_wizard_vehicle_info_propagation(self):
self.env.user.group_ids |= self.env.ref("fleet.fleet_group_manager")
brand = self.env["fleet.vehicle.model.brand"].create({
"name": "Audi",
})
@ -16,7 +21,7 @@ class TestAccountFleet(AccountTestInvoicingCommon):
})
car_1 = self.env["fleet.vehicle"].create({
"model_id": model.id,
"plan_to_change_car": False
"plan_to_change_car": False,
})
bill = self.init_invoice('in_invoice', products=self.product_a, invoice_date='2021-09-01', post=False)
@ -25,13 +30,19 @@ class TestAccountFleet(AccountTestInvoicingCommon):
context = {'active_model': 'account.move.line', 'active_ids': bill.invoice_line_ids.ids}
expense_account = self.company_data['default_account_expense']
with Form(self.env['account.automatic.entry.wizard'].with_context(context)) as wizard_form:
wizard_form.action = 'change_period'
wizard_form.date = '2021-09-15'
wizard_form.expense_accrual_account = expense_account
wizard_form.journal_id = bill.journal_id
wizard = wizard_form.save()
wizard = self.env['account.automatic.entry.wizard'].with_context(context).create({
'action': 'change_period',
'date': '2021-09-10',
'percentage': 60,
'journal_id': self.company_data['default_journal_misc'].id,
'expense_accrual_account': expense_account.id,
'revenue_accrual_account': self.env['account.account'].create({
'name': 'Accrual Revenue Account',
'code': '765432',
'account_type': 'expense',
'reconcile': True,
}).id,
})
result_action = wizard.do_action()
transfer_moves = self.env['account.move'].search(result_action['domain'])
self.assertEqual(transfer_moves.line_ids.filtered(lambda l: l.account_id == expense_account).vehicle_id, car_1, "Vehicle info is missing")

View file

@ -1,48 +0,0 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import common, tagged
@tagged('post_install', '-at_install')
class TestFleetLogServices(AccountTestInvoicingCommon, common.TransactionCase):
def test_fleet_log_services_amount(self):
brand = self.env["fleet.vehicle.model.brand"].create({
"name": "Audi",
})
model = self.env["fleet.vehicle.model"].create({
"brand_id": brand.id,
"name": "A3",
})
car = self.env["fleet.vehicle"].create({
"model_id": model.id,
"plan_to_change_car": False
})
partner = self.env['res.partner'].create({
"name": "Test Partner",
})
move = self.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': partner.id,
'invoice_date': '2019-01-01',
'date': '2019-01-01',
'currency_id': self.env.ref('base.EUR').id,
'line_ids': [
(0, 0, {
'currency_id': self.currency_data['currency'].id,
'account_id': self.company_data['default_account_expense'].id,
'vehicle_id': car.id,
'quantity': 1,
'price_unit': 5000
})
],
})
move.action_post()
line = move.line_ids[0]
fleet_service = self.env['fleet.vehicle.log.services'].search([('vendor_id', '=', partner.id),
('description', '=', False)])
self.assertNotEqual(line.debit, line.price_subtotal)
self.assertEqual(fleet_service.amount, line.debit)

View file

@ -0,0 +1,178 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class TestFleetVehicleLogServices(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.user.group_ids |= cls.env.ref("fleet.fleet_group_manager")
cls.vendor = cls.env['res.partner'].create({'name': "Vendor"})
cls.purchaser = cls.env['res.partner'].create({'name': "Purchaser"})
brand = cls.env["fleet.vehicle.model.brand"].create({
"name": "Audi",
})
model = cls.env["fleet.vehicle.model"].create({
"brand_id": brand.id,
"name": "A3",
})
cls.car_1, cls.car_2 = cls.env["fleet.vehicle"].create([
{
"model_id": model.id,
"driver_id": cls.purchaser.id,
"plan_to_change_car": False
},
{
"model_id": model.id,
"driver_id": cls.purchaser.id,
"plan_to_change_car": False
}
])
cls.bill = cls.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': cls.vendor.id,
'invoice_date': '2019-01-01',
'date': '2019-01-01',
})
cls.service_line = cls.env['account.move.line'].create({
'name': 'line',
'price_unit': 50.0,
'vehicle_id': cls.car_1.id,
'move_id': cls.bill.id,
})
cls.fleet_service_type = cls.env['fleet.service.type'].create({
'name': 'Test service type',
'category': 'service',
})
def test_service_bill_right_amount(self):
self.bill.action_post()
# check if the log service is created
self.assertEqual(self.car_1.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_1.log_services[0].amount, self.service_line.price_subtotal)
self.bill.button_draft()
self.service_line.price_unit = 110
self.bill.action_post()
# check if the log service's amount is equal to the new price
self.assertEqual(self.car_1.log_services[0].amount, self.service_line.price_unit)
def test_service_bill_deletion(self):
service_line_2 = self.env['account.move.line'].create({
'name': 'line',
'price_unit': 150.0,
'vehicle_id': self.car_2.id,
'move_id': self.bill.id,
})
self.bill.action_post()
# check if the log service is created
self.assertEqual(self.car_1.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_1.log_services[0].amount, self.service_line.price_subtotal)
self.assertEqual(self.car_2.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_2.log_services[0].amount, service_line_2.price_subtotal)
self.bill.button_draft()
self.service_line.unlink()
self.assertFalse(self.car_1.log_services)
self.assertEqual(self.car_2.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_2.log_services[0].amount, service_line_2.price_subtotal)
def test_service_log_deletion(self):
self.bill.action_post()
# check if the log service is created
self.assertEqual(self.car_1.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_1.log_services[0].amount, self.service_line.price_subtotal)
# a log services linked to a bill cannot be deleted
with self.assertRaises(UserError):
self.car_1.log_services[0].unlink()
log_service_without_bill = self.env['fleet.vehicle.log.services'].create({
'vehicle_id': self.car_1.id,
'service_type_id': self.fleet_service_type.id,
'amount': 1440,
})
log_service_without_bill.unlink()
def test_service_bill_change_vehicle(self):
self.bill.action_post()
# check if the log service is created
self.assertEqual(self.car_1.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_1.log_services[0].amount, self.service_line.price_subtotal)
self.bill.button_draft()
self.service_line.vehicle_id = self.car_2
self.bill.action_post()
self.assertFalse(self.car_1.log_services)
self.assertEqual(self.car_2.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_2.log_services[0].amount, self.service_line.price_subtotal)
# remove the vehicle should also delete the service
self.bill.button_draft()
self.service_line.vehicle_id = False
self.bill.action_post()
self.assertFalse(self.car_2.log_services)
self.assertFalse(self.service_line.vehicle_log_service_ids)
# putting car 2 back should create a new service
self.bill.button_draft()
self.service_line.vehicle_id = self.car_2
self.bill.action_post()
self.assertEqual(self.car_2.log_services[0].account_move_line_id.move_id, self.bill)
self.assertEqual(self.car_2.log_services[0].amount, self.service_line.price_subtotal)
def test_fleet_log_services_amount(self):
other_currency = self.setup_other_currency('EUR')
brand = self.env["fleet.vehicle.model.brand"].create({
"name": "Audi",
})
model = self.env["fleet.vehicle.model"].create({
"brand_id": brand.id,
"name": "A3",
})
car = self.env["fleet.vehicle"].create({
"model_id": model.id,
"plan_to_change_car": False
})
partner = self.env['res.partner'].create({
"name": "Test Partner",
})
move = self.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': partner.id,
'invoice_date': '2019-01-01',
'date': '2019-01-01',
'currency_id': other_currency.id,
'line_ids': [
(0, 0, {
'account_id': self.company_data['default_account_expense'].id,
'vehicle_id': car.id,
'quantity': 1,
'price_unit': 5000
})
],
})
move.action_post()
line = move.line_ids[0]
fleet_service = self.env['fleet.vehicle.log.services'].search([('vendor_id', '=', partner.id),
('description', '=', False)])
self.assertNotEqual(line.debit, line.price_subtotal)
self.assertEqual(fleet_service.amount, line.debit)