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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
1
Responder
2344
Vistas
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
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
dic 22
|
7231 | ||
|
0
dic 15
|
3151 | ||
|
1
may 16
|
4209 | ||
|
4
may 24
|
3066 | ||
|
1
ago 23
|
4455 |