|
|
@ -37,66 +37,53 @@ class AccountMove(models.Model): |
|
|
|
picking_type_id = fields.Many2one(comodel_name='stock.picking.type', |
|
|
|
string='Picking Type', |
|
|
|
compute='compute_stock_type', |
|
|
|
store=True, readonly=False, |
|
|
|
help="This will determine the picking type " |
|
|
|
"of incoming/outgoing shipment") |
|
|
|
|
|
|
|
@api.depends('move_type') |
|
|
|
def compute_stock_type(self): |
|
|
|
"""Computes the picking type based on the move type.""" |
|
|
|
for rec in self: |
|
|
|
type = '' |
|
|
|
data = self.env['stock.picking.type'].search([]) |
|
|
|
print('self._context.get', self._context.get('default_move_type')) |
|
|
|
if self._context.get('default_move_type') == 'out_invoice': |
|
|
|
for line in data: |
|
|
|
if line.code == 'outgoing': |
|
|
|
type = line |
|
|
|
if self._context.get('default_move_type') == 'in_invoice': |
|
|
|
for line in data: |
|
|
|
if line.code == 'incoming': |
|
|
|
type = line |
|
|
|
rec.picking_type_id = type |
|
|
|
rec.picking_type_id = False |
|
|
|
picking_types = self.env['stock.picking.type'].search([]) |
|
|
|
if rec.move_type == 'out_invoice': |
|
|
|
rec.picking_type_id = picking_types.filtered(lambda p: p.code == 'outgoing')[:1] |
|
|
|
elif rec.move_type == 'in_invoice': |
|
|
|
rec.picking_type_id = picking_types.filtered(lambda p: p.code == 'incoming')[:1] |
|
|
|
|
|
|
|
def action_stock_move(self): |
|
|
|
"""Function to create transfer from invoice""" |
|
|
|
if not self.picking_type_id: |
|
|
|
raise UserError(_( |
|
|
|
" Please select a picking type")) |
|
|
|
for order in self: |
|
|
|
if not self.invoice_picking_id: |
|
|
|
pick = {} |
|
|
|
if self.picking_type_id.code == 'outgoing': |
|
|
|
pick = { |
|
|
|
'picking_type_id': self.picking_type_id.id, |
|
|
|
'partner_id': self.partner_id.id, |
|
|
|
'origin': self.name, |
|
|
|
'location_dest_id': self.partner_id. |
|
|
|
property_stock_customer.id, |
|
|
|
'location_id': self.picking_type_id. |
|
|
|
default_location_src_id.id, |
|
|
|
'move_type': 'direct' |
|
|
|
} |
|
|
|
if self.picking_type_id.code == 'incoming': |
|
|
|
pick = { |
|
|
|
'picking_type_id': self.picking_type_id.id, |
|
|
|
'partner_id': self.partner_id.id, |
|
|
|
'origin': self.name, |
|
|
|
'location_dest_id': self.picking_type_id. |
|
|
|
default_location_dest_id.id, |
|
|
|
'location_id': self.partner_id. |
|
|
|
property_stock_supplier.id, |
|
|
|
'move_type': 'direct' |
|
|
|
if not order.picking_type_id: |
|
|
|
raise UserError(_("Please select a picking type")) |
|
|
|
if not order.invoice_picking_id: |
|
|
|
pick_vals = { |
|
|
|
'picking_type_id': order.picking_type_id.id, |
|
|
|
'partner_id': order.partner_id.id, |
|
|
|
'origin': order.name, |
|
|
|
'move_type': 'direct', |
|
|
|
} |
|
|
|
picking = self.env['stock.picking'].create(pick) |
|
|
|
self.invoice_picking_id = picking.id |
|
|
|
self.picking_count = len(picking) |
|
|
|
order = order.invoice_line_ids.filtered(lambda item: |
|
|
|
item.product_id.type in |
|
|
|
['product', 'consu']) |
|
|
|
(order._create_stock_moves(picking)._action_confirm(). |
|
|
|
_action_assign()) |
|
|
|
if order.picking_type_id.code == 'outgoing': |
|
|
|
pick_vals.update({ |
|
|
|
'location_dest_id': order.partner_id.property_stock_customer.id, |
|
|
|
'location_id': order.picking_type_id.default_location_src_id.id, |
|
|
|
}) |
|
|
|
elif order.picking_type_id.code == 'incoming': |
|
|
|
pick_vals.update({ |
|
|
|
'location_dest_id': order.picking_type_id.default_location_dest_id.id, |
|
|
|
'location_id': order.partner_id.property_stock_supplier.id, |
|
|
|
}) |
|
|
|
picking = self.env['stock.picking'].create(pick_vals) |
|
|
|
order.invoice_picking_id = picking.id |
|
|
|
order.picking_count = 1 |
|
|
|
stock_moves = order.invoice_line_ids.filtered(lambda line: line.product_id.type in ['product', 'consu']) |
|
|
|
if stock_moves: |
|
|
|
stock_moves._create_stock_moves(picking)._action_confirm()._action_assign() |
|
|
|
|
|
|
|
def action_view_picking(self): |
|
|
|
"""Function to view moves while clicking shipment smart button""" |
|
|
|
action = self.env.ref('stock.action_picking_tree_ready') |
|
|
|
action = self.env.ref('stock.action_picking_tree_ready').sudo() |
|
|
|
result = action.read()[0] |
|
|
|
result.pop('id', None) |
|
|
|
result['context'] = {} |
|
|
|