From 064a726ffb97176f06e8ce2dcfa0891063642b2a Mon Sep 17 00:00:00 2001
From: Agustin Bordon <agustin.bordon@eynes.com.ar>
Date: Wed, 21 Aug 2024 17:28:08 -0300
Subject: [PATCH 1/2] Refactor set origin field in po when create po from po
 lines

---
 models/sale_order.py               | 4 ++++
 views/purchase_view.xml            | 8 ++++----
 wizard/purchase_order_generator.py | 9 ++++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/models/sale_order.py b/models/sale_order.py
index 0784943..2d141c8 100644
--- a/models/sale_order.py
+++ b/models/sale_order.py
@@ -29,3 +29,7 @@ class SaleOrder(models.Model):
             })
         return result
 
+    def _get_purchase_orders(self):
+        res = super(SaleOrder, self)._get_purchase_orders()
+        return res | self.env['purchase.order'].search([('sale_order_ids', 'in', self.id)])
+
diff --git a/views/purchase_view.xml b/views/purchase_view.xml
index 8a0779b..ce146ff 100644
--- a/views/purchase_view.xml
+++ b/views/purchase_view.xml
@@ -7,7 +7,7 @@
             <field name="arch" type="xml">
                 <field name="name" position="after">
                     <!--<field name="origin_sale_order_id" optional="show"/>-->
-                    <field name="sale_order_ids" widget="many2many_tags" optional="show"/>
+                    <field name="sale_order_ids" widget="many2many_tags_link" optional="show"/>
                 </field>
             </field>
         </record>
@@ -18,7 +18,7 @@
             <field name="arch" type="xml">
                 <field name="name" position="after">
                     <!--<field name="origin_sale_order_id" optional="show"/>-->
-                    <field name="sale_order_ids" widget="many2many_tags" optional="show"/>
+                    <field name="sale_order_ids" widget="many2many_tags_link" optional="show"/>
                 </field>
             </field>
         </record>
@@ -133,7 +133,7 @@
                 <field name="origin" position="before">
                     <field name="boarding_mode"/>
                     <!--<field name="origin_sale_order_id" invisible="1"/>-->
-                    <field name="sale_order_ids" widget="many2many_tags"/>
+                    <field name="sale_order_ids" widget="many2many_tags_link"/>
                 </field>
                 <field name="origin" position="attributes">
                 <attribute name="attrs">
@@ -207,7 +207,7 @@
                     <field name="refrigerated_transfer" optional="show"/>
                     <field name="tariff_position_code" optional="show"/>
                     <field name="product_un_code" optional="show"/>
-                    <field name="sale_order" widget="many2many_tags_link" string="SO" optional="show"/>
+                    <field name="sale_order" widget="many2many_tags_link_link" string="SO" optional="show"/>
                     <field name="date_due_so"/>
                     <field name="orderpoint_id" widget="many2one" string="OP" optional="show"/>
                 </xpath>
diff --git a/wizard/purchase_order_generator.py b/wizard/purchase_order_generator.py
index 7f8d837..e4bcb9a 100644
--- a/wizard/purchase_order_generator.py
+++ b/wizard/purchase_order_generator.py
@@ -31,7 +31,14 @@ class PurchaseOrderGeneratorWizard(models.TransientModel):
 
     def _update_new_order(self, order):
         lines = self.line_ids
-        origin = ", ".join(lines.mapped("order_id.name"))
+        sale_order_name = lines.mapped('sale_order.display_name')
+        orderpoints_name = lines.mapped('orderpoint_id.display_name')
+        requisitions_name = lines.mapped('requisition_id.display_name')
+        combined = sale_order_name + orderpoints_name + requisitions_name
+        if combined:
+            origin = ", ".join(combined)
+        else:
+            origin = ", ".join(lines.mapped("order_id.name"))            
         orders = lines.order_id
         order.write({
             "origin": origin,
-- 
GitLab


From b556c22e14c4e88ecc47ea1b71ed45e232756714 Mon Sep 17 00:00:00 2001
From: Agustin Bordon <agustin.bordon@eynes.com.ar>
Date: Thu, 22 Aug 2024 09:09:07 -0300
Subject: [PATCH 2/2] Change get purchase order in sale order, change set
 origin when confirm multiples po.line, link m2m sale.order field in
 purchase.order

---
 views/purchase_view.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/views/purchase_view.xml b/views/purchase_view.xml
index ce146ff..5959104 100644
--- a/views/purchase_view.xml
+++ b/views/purchase_view.xml
@@ -207,7 +207,7 @@
                     <field name="refrigerated_transfer" optional="show"/>
                     <field name="tariff_position_code" optional="show"/>
                     <field name="product_un_code" optional="show"/>
-                    <field name="sale_order" widget="many2many_tags_link_link" string="SO" optional="show"/>
+                    <field name="sale_order" widget="many2many_tags_link" string="SO" optional="show"/>
                     <field name="date_due_so"/>
                     <field name="orderpoint_id" widget="many2one" string="OP" optional="show"/>
                 </xpath>
-- 
GitLab