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,5 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import account_move
from . import fleet_vehicle
from . import fleet_vehicle_log_services

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api, _
from odoo import fields, models, _
class AccountMove(models.Model):
@ -14,14 +13,14 @@ class AccountMove(models.Model):
val_list = []
log_list = []
not_posted_before = self.filtered(lambda r: not r.posted_before)
posted = super()._post(soft) # We need the move name to be set, but we also need to know which move are posted for the first time.
for line in (not_posted_before & posted).line_ids.filtered(lambda ml: ml.vehicle_id and ml.move_id.move_type == 'in_invoice'):
for line in posted.line_ids:
if not line.vehicle_id or line.vehicle_log_service_ids\
or line.move_id.move_type != 'in_invoice'\
or line.display_type != 'product':
continue
val = line._prepare_fleet_log_service()
log = _(
'Service Vendor Bill: %s',
line.move_id._get_html_link(),
)
log = _('Service Vendor Bill: %s', line.move_id._get_html_link())
val_list.append(val)
log_list.append(log)
log_service_ids = self.env['fleet.vehicle.log.services'].create(val_list)
@ -36,6 +35,8 @@ class AccountMoveLine(models.Model):
vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle', index='btree_not_null')
# used to decide whether the vehicle_id field is editable
need_vehicle = fields.Boolean(compute='_compute_need_vehicle')
vehicle_log_service_ids = fields.One2many(export_string_translation=False,
comodel_name='fleet.vehicle.log.services', inverse_name='account_move_line_id') # One2one
def _compute_need_vehicle(self):
self.need_vehicle = False
@ -45,7 +46,16 @@ class AccountMoveLine(models.Model):
return {
'service_type_id': vendor_bill_service.id,
'vehicle_id': self.vehicle_id.id,
'amount': self.debit,
'vendor_id': self.partner_id.id,
'description': self.name,
'account_move_line_id': self.id,
}
def write(self, vals):
if 'vehicle_id' in vals and not vals['vehicle_id']:
self.sudo().vehicle_log_service_ids.with_context(ignore_linked_bill_constraint=True).unlink()
return super().write(vals)
def unlink(self):
self.sudo().vehicle_log_service_ids.with_context(ignore_linked_bill_constraint=True).unlink()
return super().unlink()

View file

@ -22,10 +22,10 @@ class FleetVehicle(models.Model):
('parent_state', '!=', 'cancel'),
('move_id.move_type', 'in', self.env['account.move'].get_purchase_types())
],
fields=['vehicle_id', 'move_id:array_agg'],
groupby=['vehicle_id'],
aggregates=['move_id:array_agg'],
)
vehicle_move_mapping = {move['vehicle_id'][0]: set(move['move_id']) for move in moves}
vehicle_move_mapping = {vehicle.id: set(move_ids) for vehicle, move_ids in moves}
for vehicle in self:
vehicle.account_move_ids = [Command.set(vehicle_move_mapping.get(vehicle.id, []))]
vehicle.bill_count = len(vehicle.account_move_ids)
@ -34,11 +34,11 @@ class FleetVehicle(models.Model):
self.ensure_one()
form_view_ref = self.env.ref('account.view_move_form', False)
tree_view_ref = self.env.ref('account_fleet.account_move_view_tree', False)
list_view_ref = self.env.ref('account_fleet.account_move_view_tree', False)
result = self.env['ir.actions.act_window']._for_xml_id('account.action_move_in_invoice_type')
result.update({
'domain': [('id', 'in', self.account_move_ids.ids)],
'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')],
'views': [(list_view_ref.id, 'list'), (form_view_ref.id, 'form')],
})
return result

View file

@ -0,0 +1,50 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class FleetVehicleLogServices(models.Model):
_inherit = 'fleet.vehicle.log.services'
account_move_line_id = fields.Many2one(comodel_name='account.move.line', index='btree_not_null') # One2one
account_move_state = fields.Selection(related='account_move_line_id.parent_state')
amount = fields.Monetary(string='Cost', compute="_compute_amount", inverse="_inverse_amount",
readonly=False, store=True, tracking=True)
vehicle_id = fields.Many2one(comodel_name='fleet.vehicle', string='Vehicle',
compute="_compute_vehicle_id", store=True, readonly=False, required=True)
@api.depends('account_move_line_id.vehicle_id')
def _compute_vehicle_id(self):
for service in self:
# We avoid emptying the vehicle_id as it is a required field
if not service.account_move_line_id.vehicle_id:
continue
service.vehicle_id = service.account_move_line_id.vehicle_id
def _inverse_amount(self):
if any(service.account_move_line_id for service in self):
raise UserError(_("You cannot modify amount of services linked to an account move line. Do it on the related accounting entry instead."))
@api.depends('account_move_line_id.price_subtotal')
def _compute_amount(self):
for log_service in self:
log_service.amount = log_service.account_move_line_id.debit
def action_open_account_move(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'account.move',
'target': 'current',
'name': _('Bill'),
'res_id': self.account_move_line_id.move_id.id,
}
@api.ondelete(at_uninstall=False)
def _unlink_if_no_linked_bill(self):
if self.env.context.get('ignore_linked_bill_constraint'):
return
if any(log_service.account_move_line_id for log_service in self):
raise UserError(_("You cannot delete log services records because one or more of them were bill created."))