Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] stock_picking_invoicing: set reversed_entry in return pick invoicing #1905

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stock_picking_invoicing/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ def action_assign(self):
if any(m.invoice_state == "2binvoiced" for m in self.mapped("move_lines")):
self.write({"invoice_state": "2binvoiced"})
return super().action_assign()

def get_return_origin_invoice_ids(self):
"""
Override this method if you need to set a specific invoice to return
:return: invoices
"""
source_picking_id = self.mapped("move_lines.origin_returned_move_id.picking_id")
return source_picking_id.mapped("invoice_ids")
14 changes: 14 additions & 0 deletions stock_picking_invoicing/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,26 @@ def _action_generate_invoices(self):
invoices = self.env["account.move"].browse()
for pickings in pick_list:
moves = pickings.mapped("move_lines")
# Origin moves are set when invoicing a return picking
origin_moves = moves.mapped("origin_returned_move_id")
origin_account_move_id = False
if origin_moves:
# Core does not suport multi returns:
# pick first and set as invoice.reversed_entry_id
# TODO: check if this is approach changes in next versions
if pickings.get_return_origin_invoice_ids():
origin_account_move_id = pickings.get_return_origin_invoice_ids()[
0
].id

grouped_moves_list = self._group_moves(moves)
parts = self.ungroup_moves(grouped_moves_list)
for moves_list in parts:
invoice, invoice_values = self._build_invoice_values_from_pickings(
pickings
)
if origin_account_move_id:
invoice_values["reversed_entry_id"] = origin_account_move_id
lines = [(5, 0, {})]
line_values = False
for moves in moves_list:
Expand Down