diff --git a/sale_delivery_address/__manifest__.py b/sale_delivery_address/__manifest__.py index c0061dd1f..5241d96a0 100644 --- a/sale_delivery_address/__manifest__.py +++ b/sale_delivery_address/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Multiple Delivery Addresses for Sale Order', - 'version': '18.0.1.0.0', + 'version': '18.0.1.1.0', 'category': 'Sales', 'summary': """Multiple Delivery Addresses for Sale Order """, 'description': """ If the customer have multiple addresses, the user can diff --git a/sale_delivery_address/doc/RELEASE_NOTES.md b/sale_delivery_address/doc/RELEASE_NOTES.md index 9bb2240d8..3665fd783 100644 --- a/sale_delivery_address/doc/RELEASE_NOTES.md +++ b/sale_delivery_address/doc/RELEASE_NOTES.md @@ -4,3 +4,9 @@ #### Version 18.0.1.0.0 #### ADD - Initial Commit for Multiple Delivery Addresses for Sale Order + + +#### 11.12.2024 +#### Version 18.0.1.1.0 +#### ADD +- Bug Fix for Multiple Delivery Addresses for Sale Order diff --git a/sale_delivery_address/models/__init__.py b/sale_delivery_address/models/__init__.py index e9d109774..0a075d087 100644 --- a/sale_delivery_address/models/__init__.py +++ b/sale_delivery_address/models/__init__.py @@ -21,4 +21,3 @@ ############################################################################# from . import sale_order_line from . import stock_move -from . import stock_rule diff --git a/sale_delivery_address/models/stock_move.py b/sale_delivery_address/models/stock_move.py index f73dfecfb..15b908e21 100644 --- a/sale_delivery_address/models/stock_move.py +++ b/sale_delivery_address/models/stock_move.py @@ -21,7 +21,6 @@ ############################################################################# from odoo import models from odoo.tools.float_utils import float_compare -from odoo.tools.misc import groupby class StockMove(models.Model): @@ -50,8 +49,6 @@ class StockMove(models.Model): address.append(line.delivery_addr_id.id) elif rec.partner_id.id not in address: address.append(rec.partner_id.id) - # if no delivery address is selected for order lines, - # only one transfer will be created if len(address) <= 1: res = super(StockMove, self)._get_new_picking_values() return res @@ -68,62 +65,30 @@ class StockMove(models.Model): } def _assign_picking(self): - """ Extending _assign_picking function to create new pickings for - order lines having different delivery addresses. """ + """Create separate deliveries per address, ensuring all products are included.""" picking_obj = self.env['stock.picking'] - grouped_moves = groupby(self, key=lambda m: m._key_assign_picking()) - for group, moves in grouped_moves: - moves = self.env['stock.move'].concat(*moves) - picking = moves[0]._search_picking_for_assignation() - if picking: - vals = {} - if any(picking.partner_id.id != move.partner_id.id for move in - moves): - vals['partner_id'] = False - if any(picking.origin != move.origin for move in moves): - vals['origin'] = False - if vals: - picking.write(vals) - else: - moves = moves.filtered( - lambda m: float_compare( - m.product_uom_qty, 0.0, - precision_rounding=m.product_uom.rounding) >= 0) - if not moves: - continue - new_picking = True - origins = moves[0].origin - orders = self.env['sale.order'].search( - [('name', '=', origins)]) - for rec in orders: - addr = [rec.partner_id.id] - for line in rec.order_line: - if line.delivery_addr_id and line.delivery_addr_id.id \ - not in addr: - addr.append(line.delivery_addr_id.id) - elif line.delivery_addr_id and rec.partner_id.id not \ - in addr: - addr.append(rec.partner_id.id) - if len(addr) <= 1: - return super(StockMove, self)._assign_picking() - else: - for mov in moves: - mov.write({ - 'partner_id': - mov.sale_line_id.delivery_addr_id.id - or mov.sale_line_id.order_id.partner_id.id - }) - move_ids = [] - for index, value in enumerate(addr): - for mov in moves: - if mov.partner_id.id == value: - move_ids.append(mov.id) - mvs = self.env['stock.move'].search( - [('id', 'in', move_ids)]) - move_ids = [] - if mvs: - picking = picking_obj.create( - mvs._get_new_picking_values()) - mvs.write({'picking_id': picking.id}) - mvs._assign_picking_post_process(new=new_picking) - return True + moves_by_address = {} + for move in self: + if not move.sale_line_id: + continue + partner_id = move.sale_line_id.delivery_addr_id.id or move.sale_line_id.order_id.partner_id.id + + if partner_id not in moves_by_address: + moves_by_address[partner_id] = self.env['stock.move'] + moves_by_address[partner_id] += move + + for partner_id, moves in moves_by_address.items(): + moves = moves.filtered( + lambda m: float_compare( + m.product_uom_qty, 0.0, + precision_rounding=m.product_uom.rounding) >= 0 + ) + if not moves: + continue + + picking_vals = moves._get_new_picking_values() + picking = picking_obj.create(picking_vals) + moves.write({'picking_id': picking.id}) + moves._assign_picking_post_process(new=True) + + return True \ No newline at end of file diff --git a/sale_delivery_address/models/stock_rule.py b/sale_delivery_address/models/stock_rule.py deleted file mode 100644 index 41769bf4c..000000000 --- a/sale_delivery_address/models/stock_rule.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################# -# -# Cybrosys Technologies Pvt. Ltd. -# Copyright (C) 2024-TODAY Cybrosys Technologies() -# Author: Anzil K A (odoo@cybrosys.com) - -# You can modify it under the terms of the GNU AFFERO -# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. -# -# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE -# (AGPL v3) along with this program. -# If not, see . -# -############################################################################# -from odoo import models - - -class StockRule(models.Model): - """Inherits the stock.rule to update each move with the partner from - corresponding sale order line""" - - _inherit = 'stock.rule' - - def _get_stock_move_values(self, product_id, product_qty, product_uom, - location_id, name, origin, company_id, values): - """ Extending the _get_stock_move_values function for updating the - partner as the partner from the selected delivery address if it exists - or the partner from the order. Returns a dictionary of values that will - be used to create a stock move from a procurement. - :param procurement: browse record - :rtype: dictionary """ - res = super()._get_stock_move_values( - product_id, product_qty, product_uom, location_id, name, origin, - company_id, values) - if res.get('warehouse_id'): - warehouse = self.env['stock.warehouse'].browse(res.get( - 'warehouse_id')) - if res.get('order_id') and warehouse.delivery_steps in [ - 'pick_ship', 'ship_only']: - for data in res.get('order_id'): - for move in self.env['stock.move'].browse(data[-1]): - partner_id = move.sale_line_id.delivery_addr.id or \ - move.sale_line_id.order_id.partner_id.id - res.update({ - 'partner_id': partner_id - }) - return res