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

Conversation

DiegoParadeda
Copy link

@DiegoParadeda DiegoParadeda commented Feb 7, 2025

This PR automatically references a picking's invoice in it's return invoice using the field reversed_entry_id

Stock Move  --->  Invoice 1
     |
     v
Return Stock Move  --->  Invoice 2 (references Invoice 1)


e.g. invoice_2.reversed_entry_id = invoice_1

@mbcosta
Copy link
Contributor

mbcosta commented Feb 11, 2025

Thank you @DiegoParadeda for your PR, some points about:

@mbcosta
Copy link
Contributor

mbcosta commented Feb 11, 2025

@DiegoParadeda just a example about the suggested changes, this seems work as expect but let me know if there something about the problem that I didn't see or understand

--- a/stock_picking_invoicing/wizards/stock_invoice_onshipping.py
+++ b/stock_picking_invoicing/wizards/stock_invoice_onshipping.py
@@ -316,6 +316,13 @@ class StockInvoiceOnshipping(models.TransientModel):
                 picking.picking_type_id,
                 picking.partner_id,
             )
+            # Refund Case should not be Group
+            refund_picking = picking.mapped(
+                "move_lines.origin_returned_move_id.picking_id"
+            )
+            if refund_picking:
+                key = key + (refund_picking,)
+        print('=========== KEY =====', key)
         return key


     def _group_pickings(self, pickings):
@@ -383,6 +390,17 @@ class StockInvoiceOnshipping(models.TransientModel):
                 "picking_ids": [(4, p.id, False) for p in pickings],
             }
         )
+        refund_picking = picking.mapped(
+                "move_lines.origin_returned_move_id.picking_id"
+        )
+        if refund_picking:
+            values["reversed_entry_id"] = refund_picking.mapped(
+                "invoice_ids"
+            )[0].id
+        print('======== Build Values Refund Picking ===',
+              values.get('reversed_entry_id')
+        )
+
 
         invoice, values = self._simulate_invoice_onchange(values)


--- a/stock_picking_invoicing/tests/test_picking_invoicing.py
+++ b/stock_picking_invoicing/tests/test_picking_invoicing.py
@@ -856,6 +856,13 @@ class TestPickingInvoicing(SavepointCase):
         wizard.action_generate()
         domain = [("picking_ids", "=", picking_devolution.id)]
         invoice_devolution = self.invoice_model.search(domain)
+        print('========= Invoice Devolution ===',
+              invoice,
+              invoice_devolution.reversed_entry_id
+        )
+        self.assertEqual(
+            invoice_devolution.reversed_entry_id, invoice
+        )
         # Confirm Return Invoice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants