Browse Source

Dec 7 : [FIX] Bug Fixed 'stock_intercompany_transfer'

pull/295/head
AjmalCybro 2 years ago
parent
commit
d1e34c6da9
  1. 2
      stock_intercompany_transfer/__init__.py
  2. 3
      stock_intercompany_transfer/__manifest__.py
  3. 69
      stock_intercompany_transfer/models/stock_picking.py
  4. 2
      stock_intercompany_transfer/wizard/__init__.py
  5. 49
      stock_intercompany_transfer/wizard/stock_backorder_confirmation.py
  6. 37
      stock_intercompany_transfer/wizard/stock_immediate_transfer.py

2
stock_intercompany_transfer/__init__.py

@ -19,5 +19,5 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
from . import models from . import models
from . import wizard

3
stock_intercompany_transfer/__manifest__.py

@ -19,10 +19,9 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
{ {
'name': 'Inter Company Stock Transfer', 'name': 'Inter Company Stock Transfer',
'version': '16.0.1.0.0', 'version': '16.0.1.0.1',
'summary': """Create counterpart Receipt/Delivery Orders between companies.""", 'summary': """Create counterpart Receipt/Delivery Orders between companies.""",
'description': """Automatically Create Receipt/Delivery orders if any company validates a 'description': """Automatically Create Receipt/Delivery orders if any company validates a
Deliver Order/Receipt to the selected company,Inter Company Stock Transfer, Stock Transfer, Deliver Order/Receipt to the selected company,Inter Company Stock Transfer, Stock Transfer,

69
stock_intercompany_transfer/models/stock_picking.py

@ -27,19 +27,40 @@ from odoo.exceptions import UserError
class StockPickingInherit(models.Model): class StockPickingInherit(models.Model):
_inherit = 'stock.picking' _inherit = 'stock.picking'
auto_generated = fields.Boolean(string='Auto Generated Transfer', copy=False, auto_generated = fields.Boolean(string='Auto Generated Transfer',
help="Field helps to check the picking is created from an another picking or not") copy=False,
help="Field helps to check the picking is "
"created from an another picking "
"or not")
is_backorder_button_clicked = fields.Boolean(default=False,
string='Backorder Button Clicked')
def button_validate(self): def button_validate(self):
"""Creating the internal transfer if it is not created from another picking""" """Creating the internal transfer if it is not created
res = super(StockPickingInherit, self).button_validate() from another picking"""
if not self.auto_generated: active_move = []
self.create_intercompany_transfer() greater_quantity = []
return res for move in self.move_ids:
if move.quantity_done != 0.0:
if move.quantity_done < move.product_uom_qty or move.quantity_done > move.product_uom_qty:
active_move.append(move.id)
if move.quantity_done > move.product_uom_qty:
greater_quantity.append(move.id)
if len(greater_quantity) == self.move_ids.search_count([('picking_id', '=', self.id)]):
if not self.auto_generated:
self.create_intercompany_transfer()
if not self.move_ids.search(
[('picking_id', '=', self.id), ('quantity_done', '=', 0.0)]):
if not active_move:
if not self.auto_generated:
self.create_intercompany_transfer()
return super(StockPickingInherit, self).button_validate()
def create_intercompany_transfer(self): def create_intercompany_transfer(self):
"""Creating the transfer if the selected company is enabled the internal transfer option""" """Creating the transfer if the selected company is enabled the
company_id = self.env['res.company'].sudo().search([('partner_id', '=', self.partner_id.id)], limit=1) internal transfer option"""
company_id = self.env['res.company'].sudo().search(
[('partner_id', '=', self.partner_id.id)], limit=1)
operation_type_id = False operation_type_id = False
location_id = False location_id = False
location_dest_id = False location_dest_id = False
@ -47,18 +68,23 @@ class StockPickingInherit(models.Model):
if company_id and company_id.enable_inter_company_transfer: if company_id and company_id.enable_inter_company_transfer:
create_transfer = False create_transfer = False
if self.picking_type_id.code == company_id.apply_transfer_type or company_id.apply_transfer_type == 'all': if self.picking_type_id.code == company_id.apply_transfer_type or company_id.apply_transfer_type == 'all':
create_transfer = True create_transfer = True
if create_transfer: if create_transfer:
warehouse_ids = company_id.destination_warehouse_id.sudo() warehouse_ids = company_id.destination_warehouse_id.sudo()
if self.picking_type_id.code == 'incoming': if self.picking_type_id.code == 'incoming':
operation_type_id = self.env['stock.picking.type'].sudo().search( operation_type_id = self.env[
[('warehouse_id', 'in', warehouse_ids.ids), ('code', '=', 'outgoing')], limit=1) 'stock.picking.type'].sudo().search(
[('warehouse_id', 'in', warehouse_ids.ids),
('code', '=', 'outgoing')], limit=1)
elif self.picking_type_id.code == 'outgoing': elif self.picking_type_id.code == 'outgoing':
operation_type_id = self.env['stock.picking.type'].sudo().search( operation_type_id = self.env[
[('warehouse_id', 'in', warehouse_ids.ids), ('code', '=', 'incoming')], limit=1) 'stock.picking.type'].sudo().search(
[('warehouse_id', 'in', warehouse_ids.ids),
('code', '=', 'incoming')], limit=1)
else: else:
raise UserError(_('Internal transfer between companies are not allowed')) raise UserError(
_('Internal transfer between companies are not allowed'))
if operation_type_id: if operation_type_id:
if operation_type_id.default_location_src_id: if operation_type_id.default_location_src_id:
@ -80,15 +106,18 @@ class StockPickingInherit(models.Model):
'auto_generated': True, 'auto_generated': True,
'origin': self.name 'origin': self.name
} }
picking_id = self.env['stock.picking'].sudo().create(picking_vals) picking_id = self.env['stock.picking'].sudo().create(
picking_vals)
else: else:
raise UserError(_('Please configure appropriate locations on Operation type/Partner')) raise UserError(
_('Please configure appropriate locations on Operation type/Partner'))
for move in self.move_ids: for move in self.move_ids:
lines = self.move_line_ids.filtered(lambda x: x.product_id == move.product_id) lines = self.move_line_ids.filtered(
lambda x: x.product_id == move.product_id)
done_qty = sum(lines.mapped('qty_done')) done_qty = sum(lines.mapped('qty_done'))
if not done_qty: if not done_qty:
done_qty = sum(lines.mapped('product_uom_qty')) done_qty = sum(lines.move_id.mapped('product_uom_qty'))
move_vals = { move_vals = {
'picking_id': picking_id.id, 'picking_id': picking_id.id,
'picking_type_id': operation_type_id.id, 'picking_type_id': operation_type_id.id,
@ -98,7 +127,7 @@ class StockPickingInherit(models.Model):
'product_uom_qty': done_qty, 'product_uom_qty': done_qty,
'location_id': location_id, 'location_id': location_id,
'location_dest_id': location_dest_id, 'location_dest_id': location_dest_id,
'company_id': company_id.id 'company_id': company_id.id,
} }
self.env['stock.move'].sudo().create(move_vals) self.env['stock.move'].sudo().create(move_vals)
if picking_id: if picking_id:

2
stock_intercompany_transfer/wizard/__init__.py

@ -0,0 +1,2 @@
from . import stock_immediate_transfer
from . import stock_backorder_confirmation

49
stock_intercompany_transfer/wizard/stock_backorder_confirmation.py

@ -0,0 +1,49 @@
from odoo import fields, models
class StockBackorderConfirmation(models.TransientModel):
_inherit = 'stock.backorder.confirmation'
stock_id = fields.Many2one('stock.picking', setring="Stock", help="Stock")
def process(self):
pickings_to_do = self.env['stock.picking']
pickings_not_to_do = self.env['stock.picking']
for line in self.backorder_confirmation_line_ids:
if line.to_backorder is True:
pickings_to_do |= line.picking_id
else:
pickings_not_to_do |= line.picking_id
pickings_to_validate = self.env.context.get(
'button_validate_picking_ids')
if pickings_to_validate:
pickings_to_validate = self.env['stock.picking'].browse(
pickings_to_validate).with_context(skip_backorder=True)
if pickings_not_to_do:
self._check_less_quantities_than_expected(pickings_not_to_do)
pickings_to_validate = pickings_to_validate.with_context(
picking_ids_not_to_backorder=pickings_not_to_do.ids)
result_validate = pickings_to_validate.button_validate()
result_transfer = ''
if not pickings_to_validate.auto_generated:
result_transfer = pickings_to_validate.create_intercompany_transfer()
pickings_to_validate.write(
{'is_backorder_button_clicked': True})
return result_validate, result_transfer
return True
def process_cancel_backorder(self):
pickings_to_validate_ids = self.env.context.get(
'button_validate_picking_ids')
if pickings_to_validate_ids:
pickings_to_validate = self.env['stock.picking'].browse(
pickings_to_validate_ids)
self._check_less_quantities_than_expected(pickings_to_validate)
result_validate = pickings_to_validate.with_context(
skip_backorder=True,
picking_ids_not_to_backorder=self.pick_ids.ids).button_validate()
result_transfer = ''
if not pickings_to_validate.auto_generated:
result_transfer = pickings_to_validate.create_intercompany_transfer()
return result_validate, result_transfer
return True

37
stock_intercompany_transfer/wizard/stock_immediate_transfer.py

@ -0,0 +1,37 @@
from odoo import models, _
from odoo.exceptions import UserError
class StockImmediateTransfer(models.TransientModel):
_inherit = 'stock.immediate.transfer'
def process(self):
pickings_to_do = self.env['stock.picking']
pickings_not_to_do = self.env['stock.picking']
for line in self.immediate_transfer_line_ids:
if line.to_immediate is True:
pickings_to_do |= line.picking_id
else:
pickings_not_to_do |= line.picking_id
for picking in pickings_to_do:
# If still in draft => confirm and assign
if picking.state == 'draft':
picking.action_confirm()
if picking.state != 'assigned':
picking.action_assign()
if picking.state != 'assigned':
raise UserError(
_("Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually."))
picking.move_ids._set_quantities_to_reservation()
pickings_to_validate = self.env.context.get(
'button_validate_picking_ids')
if pickings_to_validate:
pickings_to_validate = self.env['stock.picking'].browse(
pickings_to_validate)
pickings_to_validate = pickings_to_validate - pickings_not_to_do
pickings_to_validate.write({'state': 'done'})
if not pickings_to_validate.auto_generated:
return pickings_to_validate.with_context(
skip_immediate=True).create_intercompany_transfer()
return True
Loading…
Cancel
Save