Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2648 Widoki

def action_stock_move(self):
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'
}
picking = self.env['stock.picking'].create(pick)

if self.type in ['out_refund', 'in_refund']:
picking.type = 'out_invoice' if self.type == 'in_refund' else 'in_invoice'
else:
picking.type = self.type

self.invoice_picking_id = picking.id
self.picking_count = len(picking)

moves = order.invoice_line_ids.filtered(
lambda r: r.product_id.type in ['product', 'consu'])._create_stock_moves(picking)

# Modify the quantity field for refunds
if self.type == 'in_refund' or self.type == 'out_refund':
for move in moves:
for line in move.move_line_ids:
line.qty_done = line.product_qty

move_ids = moves._action_confirm()
move_ids._action_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."))

for move in picking.move_lines.filtered(
lambda m: m.state not in ['done', 'cancel']):
for move_line in move.move_line_ids:
actual_qty_moved = move.product_uom_qty - move_line.qty_done
move_line.write({'qty_done': actual_qty_moved})

picking.action_done()


This is a function created by Cybrosys to make stock moves upon invoicing, I updated the code to automatic transfer when pressing the button. But, I need to do the following: When creating a vendor bill, the stock is increasing based on this function and this is correct. But, when doing a refund I need to create a direct decrease in stock as if I am creating a customer invoice. How to do this based on this function?

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Here you have make an adjustment in the code in which you create the picking, if it is a vendor refund, you have to change the picking_type_id and swap the values of location_id and location_dest_id.


You can make the above changes by adding a if condition to check whether it is a vendor bill or vendor refund.


Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 22
7541
0
gru 15
3368
1
maj 16
4452
4
maj 24
3591
1
sie 23
4692