-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Add the possibility to have more than 1 vehicle by PO
Initially, there was only one vehicle for one PO. Now, if the vehicle is set on the PO, all the PO lines are related to this vehicle But if the vehicle is not set on the PO, the user can decide to have different vehicles on every line. Use case is a grouped purchase of several items for several vehicles.
- Loading branch information
1 parent
e9bae48
commit bb02ffd
Showing
5 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import purchase_order | ||
from . import purchase_order_line | ||
from . import fleet_vehicle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
fleet_vehicle_id = fields.Many2one( | ||
comodel_name="fleet.vehicle", | ||
compute="_compute_fleet_vehicle_id", | ||
store=True, | ||
readonly=False, | ||
) | ||
fleet_vehicle_from_po = fields.Boolean( | ||
compute="_compute_fleet_vehicle_from_po", store=True | ||
) | ||
|
||
@api.depends("fleet_vehicle_from_po") | ||
def _compute_fleet_vehicle_id(self): | ||
for rec in self: | ||
if rec.fleet_vehicle_from_po: | ||
rec.fleet_vehicle_id = rec.order_id.fleet_vehicle_id | ||
|
||
@api.depends("order_id", "order_id.fleet_vehicle_id") | ||
def _compute_fleet_vehicle_from_po(self): | ||
for rec in self: | ||
rec.fleet_vehicle_from_po = bool(rec.order_id.fleet_vehicle_id) | ||
|
||
def _prepare_account_move_line(self, move=False): | ||
self.ensure_one() | ||
result = super()._prepare_account_move_line(move) | ||
if self.fleet_vehicle_id: | ||
result["vehicle_id"] = self.fleet_vehicle_id.id | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters