mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 09:02:06 +02:00
Initial commit: Accounting packages
This commit is contained in:
commit
4ef34c2317
2661 changed files with 1709616 additions and 0 deletions
|
|
@ -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,51 @@
|
|||
# -*- 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 and ml.move_id.move_type == 'in_invoice'):
|
||||
val = line._prepare_fleet_log_service()
|
||||
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)
|
||||
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', index='btree_not_null')
|
||||
# used to decide whether the vehicle_id field is editable
|
||||
need_vehicle = fields.Boolean(compute='_compute_need_vehicle')
|
||||
|
||||
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.debit,
|
||||
'vendor_id': self.partner_id.id,
|
||||
'description': self.name,
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command, 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
|
||||
|
||||
moves = self.env['account.move.line']._read_group(
|
||||
domain=[
|
||||
('vehicle_id', 'in', self.ids),
|
||||
('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'],
|
||||
)
|
||||
vehicle_move_mapping = {move['vehicle_id'][0]: set(move['move_id']) for move 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)
|
||||
|
||||
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_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')],
|
||||
})
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue