Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] improve the contract status warning,Vehicle Contracts :added a … #17139

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/fleet/data/fleet_data.xml
Expand Up @@ -380,7 +380,7 @@

<record id="type_contract_repairing" model="fleet.service.type">
<field name="name">Repairing</field>
<field name="category">both</field>
<field name="category">service</field>
</record>

<record id="type_service_refueling" model="fleet.service.type">
Expand Down
15 changes: 12 additions & 3 deletions addons/fleet/models/fleet_vehicle.py
Expand Up @@ -17,7 +17,7 @@ def _get_default_state(self):
return state and state.id or False

name = fields.Char(compute="_compute_vehicle_name", store=True)
active = fields.Boolean(default=True)
active = fields.Boolean(default=True, track_visibility='onchange')
company_id = fields.Many2one('res.company', 'Company')
license_plate = fields.Char(required=True, help='License plate number of the vehicle (i = plate number for a car)')
vin_sn = fields.Char('Chassis Number', help='Unique number written on the vehicle motor (VIN/SN number)', copy=False)
Expand Down Expand Up @@ -67,6 +67,7 @@ def _get_default_state(self):
multi='contract_info')
car_value = fields.Float(string="Catalog Value (VAT Incl.)", help='Value of the bought vehicle')
residual_value = fields.Float()
kanban_color = fields.Integer(compute='_compute_set_kanban_color', default = 0)

_sql_constraints = [
('driver_id_unique', 'UNIQUE(driver_id)', 'Only one car can be assigned to the same employee!')
Expand Down Expand Up @@ -252,6 +253,15 @@ def act_show_log_cost(self):
)
return res

@api.depends('log_contracts')
def _compute_set_kanban_color(self):
log_contracts = self.env['fleet.vehicle.log.contract'].read_group([('vehicle_id', 'in', self.ids), ('state', '=', 'open')
, ('expiration_date', '<', fields.Date.context_today(self))], ['vehicle_id'], ['vehicle_id'])
contract_data = dict([(contract['vehicle_id'][0], contract['vehicle_id_count']) for contract in log_contracts])
for vehicle in self:
vehicle.kanban_color = 7 if contract_data.get(vehicle.id) else 0



class FleetVehicleOdometer(models.Model):
_name = 'fleet.vehicle.odometer'
Expand Down Expand Up @@ -307,6 +317,5 @@ class FleetServiceType(models.Model):
name = fields.Char(required=True, translate=True)
category = fields.Selection([
('contract', 'Contract'),
('service', 'Service'),
('both', 'Both')
('service', 'Service')
], 'Category', required=True, help='Choose wheter the service refer to contracts, vehicle services or both')
1 change: 1 addition & 0 deletions addons/fleet/models/fleet_vehicle_cost.py
Expand Up @@ -74,6 +74,7 @@ def create(self, data):
class FleetVehicleLogContract(models.Model):

_inherits = {'fleet.vehicle.cost': 'cost_id'}
_inherit = 'mail.thread'
_name = 'fleet.vehicle.log.contract'
_description = 'Contract information on a vehicle'
_order = 'state desc,expiration_date'
Expand Down
4 changes: 4 additions & 0 deletions addons/fleet/views/fleet_vehicle_cost_views.xml
Expand Up @@ -225,6 +225,10 @@
<field name="notes" nolabel="1" placeholder="Write here all other information relative to this contract" />
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread" options='{"thread_level": 1}'/>
</div>
</form>
</field>
</record>
Expand Down
60 changes: 46 additions & 14 deletions addons/fleet/views/fleet_vehicle_views.xml
Expand Up @@ -170,6 +170,7 @@
<field name="state_id" />
<field name="id" />
<field name="image" />
<field name="kanban_color"/>
<field name="tag_ids" />
<field name="contract_renewal_due_soon" />
<field name="contract_renewal_overdue" />
Expand All @@ -178,7 +179,7 @@

<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div t-attf-class="#{kanban_color(record.kanban_color.raw_value)} oe_kanban_global_click">
<div class="o_kanban_tags_section">
<field name="tag_ids"/>
</div>
Expand All @@ -196,15 +197,17 @@
<li>
<t t-if="record.location.raw_value"><field name="location"/></t>
</li>
<li>
<a type="object" name="return_action_to_open" context="{'xml_id': 'fleet_vehicle_log_contract_action'}">
<t t-if="record.contract_count.raw_value &gt; 1">
<field name="contract_count"/> Contracts
</t>
<t t-elif="record.contract_count.raw_value == 1">
<field name="contract_count"/> Contract
</t>
</a>
</li>
</ul>
<div class="o_kanban_button">
<a t-if="record.contract_renewal_due_soon.raw_value and !record.contract_renewal_overdue.raw_value" data-type="object" data-name="return_action_to_open" href="#" class="oe_kanban_action btn btn-sm btn-warning" data-context='{"xml_id":"fleet_vehicle_log_contract_action"}'>
<field name="contract_renewal_name"/> <t t-if="record.contract_renewal_total.raw_value > 0"> and <field name="contract_renewal_total" /> other(s)</t>
</a>
<a t-if="record.contract_renewal_overdue.raw_value" data-type="object" data-name="return_action_to_open" href="#" class="oe_kanban_action btn btn-sm btn-danger" data-context='{"xml_id":"fleet_vehicle_log_contract_action"}'>
<field name="contract_renewal_name"/> <t t-if="record.contract_renewal_total.raw_value > 0"> and <field name="contract_renewal_total" /> other(s)</t>
</a>
</div>
</div>
</div>
</t>
Expand Down Expand Up @@ -316,22 +319,23 @@

<menuitem action="fleet_vehicle_odometer_action" parent="fleet_vehicles" id="fleet_vehicle_odometer_menu" groups="fleet_group_user"/>

<record id='fleet_vehicle_service_types_view_tree' model='ir.ui.view'>
<record id='fleet_service_type_view_tree_service' model='ir.ui.view'>
<field name="name">fleet.service.type.tree</field>
<field name="model">fleet.service.type</field>
<field name="arch" type="xml">
<tree string="Service types" editable="top">
<field name="name" />
<field name="category"/>
</tree>
</field>
</record>

<record id='fleet_vehicle_service_types_action' model='ir.actions.act_window'>
<record id='fleet_service_type_action_service' model='ir.actions.act_window'>
<field name="name">Service Types</field>
<field name="res_model">fleet.service.type</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('category', '=', 'service')]</field>
<field name="context">{'default_category': 'service'}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new type of service.
Expand All @@ -341,14 +345,42 @@
</field>
</record>

<menuitem action="fleet_vehicle_service_types_action" parent="fleet_configuration" id="fleet_vehicle_service_types_menu"/>
<menuitem action="fleet_service_type_action_service" parent="fleet_configuration" id="fleet_vehicle_service_types_menu"/>

<record id='fleet_service_type_view_tree_contract' model='ir.ui.view'>
<field name="name">fleet.service.type.tree</field>
<field name="model">fleet.service.type</field>
<field name="arch" type="xml">
<tree string="Contract types" editable="top">
<field name="name" />
</tree>
</field>
</record>

<record id='fleet_service_type_action_contract' model='ir.actions.act_window'>
<field name="name">Contract Types</field>
<field name="res_model">fleet.service.type</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('category', '=', 'contract')]</field>
<field name="context">{'default_category': 'contract'}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new type of Contract.
</p><p>
Each service can used in contracts, as a standalone service or both.
</p>
</field>
</record>

<menuitem action="fleet_service_type_action_contract" parent="fleet_configuration" id="fleet_vehicle_contract_types_menu"/>

<record id='fleet_vehicle_state_view_tree' model='ir.ui.view'>
<field name="name">fleet.vehicle.state.tree</field>
<field name="model">fleet.vehicle.state</field>
<field name="arch" type="xml">
<tree string="State" editable="bottom">
<field name="sequence" widget="handler"/>
<field name="sequence" widget="handle"/>
<field name="name" />

</tree>
Expand Down