Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
276 Zobrazení

Hi All,

Currently in our Odoo when we do a sales order delivery, it will also default the source location to the location found with the Delivery operation.


However this obviously is not practical, because we have stock stored in multiple locations and if there is no SOH in the default location it will not allow the delivery to validated, until you go to the source location and select the location for which the product exists.  I am sure there is a way to do this, but after searching it does not appear to be the case.


Also we would need to be able to update the route to look in all locations as opposed to having to specify a specific destination location.  The documentation says that I would need to create separate rules for each different product location for the route/rule to work.  Once again this will be a maintenance nightmare and sure there is a smarter way of doing this.


Any suggestions before I start looking down the customisation road? 


Thanks,
Damien

Avatar
Zrušit
Nejlepší odpověď

Hi,

Please refer to the code below:



from odoo import models, _

from odoo.exceptions import UserError


class StockPicking(models.Model):

    _inherit = 'stock.picking'


    def button_validate(self):

        for picking in self:

            for move in picking.move_ids_without_package:

                product = move.product_id

                qty_needed = move.product_uom_qty

                source_location = move.location_id

                source_stock = self.env['stock.quant'].search([

                    ('product_id', '=', product.id),

                    ('location_id', '=', source_location.id),

                ], limit=1)

                if not source_stock or source_stock.quantity < qty_needed:

                    other_quants = self.env['stock.quant'].search([

                        ('product_id', '=', product.id),

                        ('quantity', '>', 0),

                        ('location_id.usage', '=', 'internal'),

                        ('location_id', '!=', source_location.id),

                    ])

                    location_names = ', '.join(other_quants.mapped('location_id.display_name')) or 'No stock available'

                    raise UserError(_(

                        "Not enough stock for product '%s' in location '%s'.\n"

                        "Available in: %s" % (

                            product.display_name,

                            source_location.display_name,

                            location_names

                        )

                    ))

        return super().button_validate()


Hope it helps.

Avatar
Zrušit