[ADD] account_fleet: manage accounting with fleet
Task: 2186429 Add a vehicle on account.move.line to help create reports. When a vehicle is set, log a service log on the vehicle. closes odoo/odoo#49675 Related: odoo/upgrade#1357 Related: odoo/enterprise#8480 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': 'Accounting/Fleet bridge',
|
||||
'category': 'Accounting/Accounting',
|
||||
'summary': 'Manage accounting with fleets',
|
||||
'description': "",
|
||||
'version': '1.0',
|
||||
'depends': ['fleet', 'account'],
|
||||
'data': [
|
||||
'data/fleet_service_type_data.xml',
|
||||
'views/account_move_views.xml',
|
||||
'views/fleet_vehicle_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
'application': False,
|
||||
'license': 'OEEL-1',
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="data_fleet_service_type_vendor_bill" model="fleet.service.type">
|
||||
<field name="name">Vendor Bill</field>
|
||||
<field name="category">service</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +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
|
||||
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
def _post(self, soft=True):
|
||||
vendor_bill_service = self.env.ref('account_fleet.data_fleet_service_type_vendor_bill', raise_if_not_found=False)
|
||||
if not vendor_bill_service:
|
||||
return super()._post(soft)
|
||||
|
||||
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):
|
||||
val = {
|
||||
'service_type_id': vendor_bill_service.id,
|
||||
'vehicle_id': line.vehicle_id.id,
|
||||
'amount': line.price_subtotal,
|
||||
'vendor_id': line.partner_id.id,
|
||||
'description': line.name,
|
||||
}
|
||||
log = _('Service Vendor Bill: <a href=# data-oe-model=account.move data-oe-id={move_id}>{move_name}</a>').format(
|
||||
move_id=line.move_id.id,
|
||||
move_name=line.move_id.name,
|
||||
)
|
||||
val_list.append(val)
|
||||
log_list.append(log)
|
||||
log_service_ids = self.env['fleet.vehicle.log.services'].create(val_list)
|
||||
for log_service_id, log in zip(log_service_ids, log_list):
|
||||
log_service_id.message_post(body=log)
|
||||
return posted
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle')
|
||||
need_vehicle = fields.Boolean(compute='_compute_need_vehicle',
|
||||
help="Technical field to decide whether the vehicle_id field is editable")
|
||||
|
||||
def _compute_need_vehicle(self):
|
||||
self.need_vehicle = False
|
||||
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class FleetVehicle(models.Model):
|
||||
_inherit = 'fleet.vehicle'
|
||||
|
||||
bill_count = fields.Integer(compute='_compute_move_ids', string="Bills Count")
|
||||
account_move_ids = fields.One2many('account.move', compute='_compute_move_ids')
|
||||
|
||||
def _compute_move_ids(self):
|
||||
if not self.env.user.has_group('account.group_account_readonly'):
|
||||
self.account_move_ids = False
|
||||
self.bill_count = 0
|
||||
return
|
||||
|
||||
for vehicle in self:
|
||||
vehicle.account_move_ids = self.env['account.move.line'].search([('vehicle_id', '=', self.id), ('move_id.state', '!=', 'cancel')]).move_id
|
||||
vehicle.bill_count = len(vehicle.account_move_ids)
|
||||
|
||||
def action_view_bills(self):
|
||||
self.ensure_one()
|
||||
|
||||
form_view_ref = self.env.ref('account.view_move_form', False)
|
||||
tree_view_ref = self.env.ref('account.view_move_tree', False)
|
||||
|
||||
action = self.env.ref('account.action_move_in_invoice_type')
|
||||
result = action.read()[0]
|
||||
result.update({
|
||||
'domain': [('id', 'in', self.account_move_ids.ids)],
|
||||
'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')],
|
||||
})
|
||||
return result
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<odoo>
|
||||
<record id="view_move_form" model="ir.ui.view">
|
||||
<field name="name">account.move.form</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='line_ids']//field[@name='account_id']" position="after">
|
||||
<field name='need_vehicle' invisible='1'/>
|
||||
<field name='vehicle_id' attrs="{'required': [('need_vehicle', '=', True), ('parent.move_type', '=', 'in_invoice')], 'column_invisible': [('parent.move_type', '!=', 'in_invoice')]}" optional='hidden'/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='invoice_line_ids']//field[@name='account_id']" position="after">
|
||||
<field name='need_vehicle' invisible='1'/>
|
||||
<field name='vehicle_id' attrs="{'required': [('need_vehicle', '=', True), ('parent.move_type', '=', 'in_invoice')], 'column_invisible': [('parent.move_type', '!=', 'in_invoice')]}" optional='hidden'/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<odoo>
|
||||
<record id="fleet_vehicle_view_form" model="ir.ui.view">
|
||||
<field name="name">fleet.vehicle.form</field>
|
||||
<field name="model">fleet.vehicle</field>
|
||||
<field name="inherit_id" ref="fleet.fleet_vehicle_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='open_assignation_logs']" position='before'>
|
||||
<button name="action_view_bills"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
attrs="{'invisible': [('bill_count', '=', 0)]}"
|
||||
help="show the vendor bills for this vehicle">
|
||||
<field name="bill_count" widget="statinfo" string="Bills"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user