sale_order_route: fix crash upon module installation and add route_id in sale.report
sale_stock_usability: direct access to warehouse_id in the sale.report pivot view
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from . import sale_order
|
||||
from . import sale_report
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
@@ -24,3 +24,18 @@ class SaleOrder(models.Model):
|
||||
lambda l:
|
||||
l.product_id and l.product_id.type in ('product', 'consu')).write(vals)
|
||||
return super()._action_confirm()
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
|
||||
# It's important when you add a line AFTER order confirmation
|
||||
route_id = fields.Many2one(compute='_compute_route_id', readonly=False, store=True, precompute=True)
|
||||
|
||||
@api.depends('display_type', 'product_id')
|
||||
def _compute_route_id(self):
|
||||
for line in self:
|
||||
if not line.display_type and line.product_id and line.product_id.type in ('product', 'consu'):
|
||||
line.route_id = line.order_id.route_id or False
|
||||
else:
|
||||
line.route_id = False
|
||||
|
||||
21
sale_order_route/models/sale_report.py
Normal file
21
sale_order_route/models/sale_report.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright 2024 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleReport(models.Model):
|
||||
_inherit = "sale.report"
|
||||
|
||||
route_id = fields.Many2one('stock.route', string='Route', readonly=True)
|
||||
|
||||
def _select_additional_fields(self):
|
||||
res = super()._select_additional_fields()
|
||||
res['route_id'] = "s.route_id"
|
||||
return res
|
||||
|
||||
def _group_by_sale(self):
|
||||
res = super()._group_by_sale()
|
||||
res += ', s.route_id'
|
||||
return res
|
||||
Reference in New Issue
Block a user