Browse Source

Aug 04 : [FIX] Bug Fixed 'sale_delivery_address'

18.0
Risvana Cybro 6 days ago
parent
commit
fe1b7cf9a3
  1. 2
      sale_delivery_address/__manifest__.py
  2. 6
      sale_delivery_address/doc/RELEASE_NOTES.md
  3. 1
      sale_delivery_address/models/__init__.py
  4. 87
      sale_delivery_address/models/stock_move.py
  5. 53
      sale_delivery_address/models/stock_rule.py

2
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

6
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

1
sale_delivery_address/models/__init__.py

@ -21,4 +21,3 @@
#############################################################################
from . import sale_order_line
from . import stock_move
from . import stock_rule

87
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

53
sale_delivery_address/models/stock_rule.py

@ -1,53 +0,0 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
#############################################################################
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
Loading…
Cancel
Save