[IMP] account_fleet: assets/fleet/DNA/accounting

The goal is to improve the way Disallowed Expenses (DNA - Dépenses Non Admises)
and Assets (vehicles in particular) work.

This should help integrate the Accounting and Fleet modules.

closes odoo/odoo#76684

Task: 2641494
Related: odoo/upgrade#3067
Related: odoo/enterprise#20950
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
John Laterre (jol)
2022-01-25 09:56:59 +00:00
parent 2514c24b20
commit 16872e63a4
3 changed files with 31 additions and 10 deletions
+11 -7
View File
@@ -17,13 +17,7 @@ class AccountMove(models.Model):
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'):
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,
}
val = line._prepare_fleet_log_service()
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,
@@ -45,3 +39,13 @@ class AccountMoveLine(models.Model):
def _compute_need_vehicle(self):
self.need_vehicle = False
def _prepare_fleet_log_service(self):
vendor_bill_service = self.env.ref('account_fleet.data_fleet_service_type_vendor_bill', raise_if_not_found=False)
return {
'service_type_id': vendor_bill_service.id,
'vehicle_id': self.vehicle_id.id,
'amount': self.price_subtotal,
'vendor_id': self.partner_id.id,
'description': self.name,
}
+5 -1
View File
@@ -17,7 +17,11 @@ class FleetVehicle(models.Model):
return
moves = self.env['account.move.line'].read_group(
domain=[('vehicle_id', 'in', self.ids), ('move_id.state', '!=', 'cancel')],
domain=[
('vehicle_id', 'in', self.ids),
('move_id.state', '!=', 'cancel'),
('move_id.move_type', 'in', self.env['account.move'].get_purchase_types())
],
fields=['vehicle_id', 'move_id:array_agg'],
groupby=['vehicle_id'],
)
@@ -1,15 +1,16 @@
<?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">
<xpath expr="//field[@name='line_ids']//field[@name='name']" position="after">
<field name='need_vehicle' invisible='1'/>
<field name='vehicle_id' attrs="{'required': [('need_vehicle', '=', True), ('parent.move_type', 'in', ('in_invoice', 'in_refund'))], 'column_invisible': [('parent.move_type', 'not in', ('in_invoice', 'in_refund'))]}" optional='hidden'/>
</xpath>
<xpath expr="//field[@name='invoice_line_ids']//field[@name='account_id']" position="after">
<xpath expr="//field[@name='invoice_line_ids']//field[@name='name']" position="after">
<field name='need_vehicle' invisible='1'/>
<field name='vehicle_id' attrs="{'required': [('need_vehicle', '=', True), ('parent.move_type', 'in', ('in_invoice', 'in_refund'))], 'column_invisible': [('parent.move_type', 'not in', ('in_invoice', 'in_refund'))]}" optional='hidden'/>
</xpath>
@@ -30,4 +31,16 @@
</xpath>
</field>
</record>
<record id="view_move_line_tree_fleet" model="ir.ui.view">
<field name="name">view.move.line.tree.fleet</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position='after'>
<field name="vehicle_id" optional='hidden'/>
</xpath>
</field>
</record>
</odoo>